Skip to content

Commit 5b31936

Browse files
fix(tab-strip): stop an in-flight reveal on every retarget and on pointer scrolling
1 parent 6761d95 commit 5b31936

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/emcn/src/components/tab-strip/tab-strip.tsx‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ export function TabStrip({
574574
const revealActiveTab = useCallback(() => {
575575
const node = scrollNodeRef.current
576576
if (!node || !activeRegularId) return
577+
// Stopped before any early return, so a reveal still in flight toward a
578+
// previous tab cannot scroll an already-visible active tab away.
579+
stopRevealScroll()
577580
const element = Array.from(node.querySelectorAll<HTMLElement>('[data-tab-strip-item]')).find(
578581
(candidate) => candidate.dataset.tabStripItem === activeRegularId
579582
)
@@ -597,7 +600,6 @@ export function TabStrip({
597600
// gradient at a scroll extreme, so no margin is needed to clear one.
598601
const nextLeft = Math.max(0, Math.min(maxScrollLeft, target))
599602
if (Math.abs(nextLeft - node.scrollLeft) < 1) return
600-
stopRevealScroll()
601603
if (reduceMotion) {
602604
node.scrollLeft = nextLeft
603605
return
@@ -656,7 +658,12 @@ export function TabStrip({
656658
event.preventDefault()
657659
}
658660
strip.addEventListener('wheel', handleWheel, { passive: false })
659-
return () => strip.removeEventListener('wheel', handleWheel)
661+
// Touch, pen, and scrollbar drags scroll natively without a wheel event.
662+
strip.addEventListener('pointerdown', stopRevealScroll)
663+
return () => {
664+
strip.removeEventListener('wheel', handleWheel)
665+
strip.removeEventListener('pointerdown', stopRevealScroll)
666+
}
660667
}, [stopRevealScroll, updateOverflow])
661668

662669
const handleDragStart = useCallback(

0 commit comments

Comments
 (0)