Skip to content

Commit e6b4682

Browse files
committed
wip: reset adjustLabelFit upon resizing window
1 parent cd47828 commit e6b4682

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/webui/src/client/ui/util/AdjustLabelFit.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,29 @@ export const AdjustLabelFit: React.FC<AdjustLabelFitProps> = ({
218218
}
219219

220220
useEffect(() => {
221-
adjustTextToFit()
221+
// Add debouncing for resize events
222+
let resizeTimer: number
223+
const handleResize = () => {
224+
cancelAnimationFrame(resizeTimer)
225+
resizeTimer = requestAnimationFrame(() => {
226+
// Reset all styles first before recalculating
227+
if (labelRef.current) {
228+
labelRef.current.style.letterSpacing = '0px'
229+
labelRef.current.style.fontVariationSettings = ''
230+
labelRef.current.textContent = label
231+
// Reset the word break and white space properties
232+
labelRef.current.style.wordBreak = 'normal'
233+
labelRef.current.style.whiteSpace = 'nowrap'
234+
}
235+
adjustTextToFit()
236+
})
237+
}
222238

223239
// Adjust on window resize
224-
window.addEventListener('resize', adjustTextToFit)
240+
window.addEventListener('resize', handleResize)
225241
return () => {
226-
window.removeEventListener('resize', adjustTextToFit)
242+
window.removeEventListener('resize', handleResize)
243+
cancelAnimationFrame(resizeTimer)
227244
}
228245
}, [label, width, fontFamily, fontSize, minFontSize, maxFontSize, minLetterSpacing])
229246

0 commit comments

Comments
 (0)