Skip to content

Commit

Permalink
fix(ellipsis): can't show tooltip if content width is very close to c…
Browse files Browse the repository at this point in the history
…ontainer width, closes #1393, closes #2899
  • Loading branch information
07akioni committed May 8, 2022
1 parent bfc0b2a commit 3d2074d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix `n-data-table`'s `work-break` isn't `break-word`.
- Fix `n-list`'s css variable `n-merged-color` is not correct.
- Fix `MessageReactive`'s `destroy` method throws error if message has disappeared.
- Fix `n-ellpisis` can't show tooltip if content width is very close to container width, closes [#1393](https://github.com/TuSimple/naive-ui/issues/1393), [#2899](https://github.com/TuSimple/naive-ui/issues/2899).

### Feats

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- 修复 `n-data-table``work-break` 样式为 `break-word`
- 修复 `n-list``n-merged-color` 样式不正常
- 修复 `MessageReactive``destroy` 方法在 message 消失后调用会抛错
- 修复 `n-ellpisis` 在恰好触发省略的时候无法弹出 tooltip,关闭 [#1393](https://github.com/TuSimple/naive-ui/issues/1393)[#2899](https://github.com/TuSimple/naive-ui/issues/2899)

### Feats

Expand Down
1 change: 1 addition & 0 deletions src/ellipsis/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ line-clamp.vue
expand-trigger.vue
custom-tooltip.vue
dynamic-debug.vue
width-debug.vue
```

## API
Expand Down
9 changes: 9 additions & 0 deletions src/ellipsis/demos/zhCN/width-debug.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<markdown>
# Width debug
</markdown>

<template>
<n-ellipsis style="width: 70px; font-family: 'Helvetica Neue'">
624748504
</n-ellipsis>
</template>
11 changes: 9 additions & 2 deletions src/ellipsis/src/Ellipsis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default defineComponent({
mergedClsPrefixRef
)
const triggerRef = ref<HTMLElement | null>(null)
const triggerInnerRef = ref<HTMLElement | null>(null)
const tooltipRef = ref<TooltipInst | null>(null)
const expandedRef = ref(false)
const ellipsisStyleRef = computed(() => {
Expand Down Expand Up @@ -74,7 +75,12 @@ export default defineComponent({
if (lineClamp !== undefined) {
tooltipDisabled = trigger.scrollHeight <= trigger.offsetHeight
} else {
tooltipDisabled = trigger.scrollWidth <= trigger.offsetWidth
const { value: triggerInner } = triggerInnerRef
if (triggerInner) {
tooltipDisabled =
triggerInner.getBoundingClientRect().width <=
trigger.getBoundingClientRect().width
}
}
syncCursorStyle(trigger, tooltipDisabled)
}
Expand Down Expand Up @@ -112,7 +118,7 @@ export default defineComponent({
props.expandTrigger === 'click' ? getTooltipDisabled : undefined
}
>
{slots}
{props.lineClamp ? slots : <span ref="triggerInnerRef">{slots}</span>}
</span>
)
function syncEllipsisStyle (trigger: HTMLElement): void {
Expand Down Expand Up @@ -160,6 +166,7 @@ export default defineComponent({
return {
mergedTheme,
triggerRef,
triggerInnerRef,
tooltipRef,
handleClick: handleClickRef,
renderTrigger,
Expand Down

0 comments on commit 3d2074d

Please sign in to comment.