-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Add tooltip as directive #9610
Comments
Duplicate of #2961 We have some changes coming that might make this possible |
I cant find "v-tooltip" directive in v2.3.6. is this feature available in v2.3.0 or v3.0? |
This comment was marked as outdated.
This comment was marked as outdated.
no this is not available in 2.x, but might happen in the 3.x rework |
@johnleider does the last change mean that it won't happen in Vuetify 3? |
@unicrus They just moved it to a different v3 board. They enabled GitHub Organizations for better cross repo project management, I'd assume, and the board had to be migrated. |
For anyone else still wishing this was easily available in v2, I've published the plugin I've been using to wrap VTooltip with a directive: vue-tooltip-directive |
Your library is awesome, and is exactly what I expect on a future revision for Vuetify. |
I cannot agree more, among hundreds of usages in our app there's less than a handful where this wouldn't work. |
Hello, This thread may be old but for anyone stumbling upon it, I've written such a directive in TS for my use case.
I use it as a module, so to make it work you should set the following in your main file :
Hope this helps ! |
@resu511 Thanks for sharing! Made it vue3/vuetify3 compatible. import { createVNode, render } from 'vue';
import { VTooltip } from 'vuetify/lib/components/index.mjs';
export default defineNuxtPlugin(({ vueApp }) => {
let tooltips: { el: any }[] = [];
vueApp.directive('tooltip', {
beforeUnmount: (el, binding) => {
const tooltipIndex = tooltips.findIndex((tooltip) => tooltip.el === el);
const tooltip = tooltips.splice(tooltipIndex, 1);
if (tooltip.length > 0) {
render(null, el);
}
},
mounted: (el, binding) => {
const { value, modifiers } = binding;
const { start = false, bottom = false, end = false } = modifiers;
let location = 'top';
if (start) location = 'left';
else if (end) location = 'right';
else if (bottom) location = 'bottom';
/**
* applies `cursor: help` on the hovered element if no cursor logic is applied
*/
if (!el.className.match(/cursor-/) && !el.style.cursor) el.style.cursor = 'help';
let vNode = createVNode(
VTooltip,
{
activator: el,
location,
},
() => [value],
);
vNode.appContext = vueApp._context;
render(vNode, el);
tooltips.push({ el });
},
});
}); |
Keep an eye on this P.R. #17395 |
This doesn't work for me, what am i doing wrong? Vue: 2.7.10
However, no tooltip is shown (it also doesn't work with |
closed by 2e1e743 |
Problem to solve
Tooltips are needed very often, and every time they are needed, we need to write quite a lot of code for one (according to documentation):
Most of this stuff is needed only for advanced cases
Proposed solution
It would be awesome if they were available as a directive as well, for example:
The text was updated successfully, but these errors were encountered: