diff --git a/src/directives/title.ts b/src/directives/title.ts index 3cd5e00..3141651 100644 --- a/src/directives/title.ts +++ b/src/directives/title.ts @@ -19,6 +19,7 @@ export default defineDirective({ const trigger = el.getAttribute('title-trigger') || undefined; const maxWidth = el.getAttribute('title-max-width') || undefined; const delayTime = toNum(el.getAttribute('title-delay-time')) || 200; + const nowrap = el.hasAttribute('title-nowrap'); const overflow = binding.modifiers.overflow; const multiple = binding.modifiers.multiple; const delay = binding.modifiers.delay; @@ -37,15 +38,34 @@ export default defineDirective({ body: document.body, 'offset-parent': (el: HTMLElement) => el.offsetParent, }[appendTo] as Props['appendTo']) - : 'parent', + : document.body, onShow(instance) { if (!instance.props.content || (overflow && !isOverflow(el, multiple))) return false; }, + onCreate(instance) { + const content = instance.popper.querySelector( + '.tippy-content', + ) as HTMLElement; + if (nowrap) { + content.style.whiteSpace = 'nowrap'; + } else { + content.style.wordBreak = 'break-all'; + } + }, popperOptions: { modifiers: [ - { name: 'preventOverflow', enabled: false }, - { name: 'hide', enabled: false }, + { + name: 'destroy-auto', + enabled: true, + phase: 'main', + fn: ({ state }) => { + if (state.modifiersData.hide?.isReferenceHidden) { + instance.setProps({ duration: 0 }); + instance.hide(); + } + }, + }, ], }, }); diff --git a/src/index.ts b/src/index.ts index ac8afce..17e4382 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ import VTitle from '@/directives/title'; -import './styles/title.scss'; export default VTitle; diff --git a/src/styles/title.scss b/src/styles/title.scss deleted file mode 100644 index a86e85e..0000000 --- a/src/styles/title.scss +++ /dev/null @@ -1,3 +0,0 @@ -.tippy-content { - word-break: break-all; -}