Skip to content

Commit 901236f

Browse files
committed
fix(ui): harden overflow measurement defaults
1 parent 592ee66 commit 901236f

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

packages/emcn/src/components/overflow-text/overflow-text.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe('OverflowText', () => {
8585
setWidths(label, 80, 180)
8686

8787
expect(label.classList.contains('overflow-hidden')).toBe(true)
88+
expect(label.classList.contains('block')).toBe(true)
8889
expect(label.classList.contains('text-clip')).toBe(true)
8990
expect(label.classList.contains('whitespace-nowrap')).toBe(true)
9091
expect(label.classList.contains('truncate')).toBe(false)
@@ -211,6 +212,30 @@ describe('OverflowText', () => {
211212
expect(label.className).not.toContain('mask-image:linear-gradient')
212213
})
213214

215+
it('remeasures when decorated content changes without changing the label', () => {
216+
act(() =>
217+
root.render(
218+
<OverflowText label='Workflow production'>
219+
Workflow <mark>production</mark>
220+
</OverflowText>
221+
)
222+
)
223+
const label = host.querySelector<HTMLElement>('span')
224+
if (!label) throw new Error('Overflow label did not render')
225+
226+
setWidths(label, 100, 60)
227+
Object.defineProperty(label, 'scrollWidth', { configurable: true, value: 180 })
228+
act(() =>
229+
root.render(
230+
<OverflowText label='Workflow production'>
231+
Workflow <strong>production</strong>
232+
</OverflowText>
233+
)
234+
)
235+
236+
expect(label.className).toContain('mask-image:linear-gradient')
237+
})
238+
214239
it('remeasures when loaded fonts change text width', () => {
215240
act(() => root.render(<OverflowText label='Workflow name' />))
216241
const label = host.querySelector<HTMLElement>('span')

packages/emcn/src/components/overflow-text/overflow-text.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const OverflowText = memo(function OverflowText({
4545
tooltipEnabled = true,
4646
focusTarget,
4747
}: OverflowTextProps) {
48-
const { ref: textRef, node, isOverflowing } = useIsOverflowing<HTMLSpanElement>(label)
48+
const { ref: textRef, node, isOverflowing } = useIsOverflowing<HTMLSpanElement>(children ?? label)
4949
const tooltipEligible = tooltipEnabled && label.length > 0 && (Boolean(showWhen) || isOverflowing)
5050
const getFocusTarget = useCallback(() => {
5151
if (focusTarget !== 'nearest-interactive') return null
@@ -74,7 +74,7 @@ export const OverflowText = memo(function OverflowText({
7474
data-overflow-text=''
7575
className={cn(
7676
className,
77-
'min-w-0 overflow-hidden text-clip whitespace-nowrap',
77+
'block min-w-0 overflow-hidden text-clip whitespace-nowrap',
7878
isOverflowing && overflowTextFadeClass
7979
)}
8080
{...handlers}

0 commit comments

Comments
 (0)