Skip to content

Commit

Permalink
fix: text wrap and overflow hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinpan committed Oct 31, 2023
1 parent d13138e commit 6eab8db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
26 changes: 23 additions & 3 deletions src/directives/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineDirective<string, HTMLElement>({
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;
Expand All @@ -37,15 +38,34 @@ export default defineDirective<string, HTMLElement>({
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();
}
},
},
],
},
});
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import VTitle from '@/directives/title';
import './styles/title.scss';

export default VTitle;
3 changes: 0 additions & 3 deletions src/styles/title.scss

This file was deleted.

0 comments on commit 6eab8db

Please sign in to comment.