fix(tabs): activate clicks when pointer release has no button (#6386)

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinwoo Hong
2026-06-25 15:04:53 -07:00
committed by GitHub
co-authored by Orca
parent 73255f3c59
commit cbfb36b566
2 changed files with 15 additions and 6 deletions
@@ -65,8 +65,8 @@ function renderProbe(onActivate = vi.fn()): {
}
}
function dispatchPointer(target: EventTarget, type: string): void {
target.dispatchEvent(new MouseEvent(type, { bubbles: true, button: 0 }))
function dispatchPointer(target: EventTarget, type: string, button = 0): void {
target.dispatchEvent(new MouseEvent(type, { bubbles: true, button }))
}
afterEach(() => {
@@ -89,6 +89,16 @@ describe('useTabStripPointerActivation', () => {
expect(onActivate).toHaveBeenCalledTimes(1)
})
it('activates when the release event reports no changed button', () => {
const { onActivate, tabButton } = renderProbe()
act(() => dispatchPointer(tabButton, 'pointerdown'))
act(() => dispatchPointer(window, 'pointerup', -1))
expect(tabButton.dataset.pressed).toBe('false')
expect(onActivate).toHaveBeenCalledTimes(1)
})
it('cancels pending activation on pointercancel', () => {
const { onActivate, tabButton } = renderProbe()
@@ -33,10 +33,9 @@ export function useTabStripPointerActivation({
if (!isPressed) {
return
}
const finishPointerPress = (event: PointerEvent): void => {
if (event.button !== 0) {
return
}
const finishPointerPress = (): void => {
// Why: pointerup often reports button -1/no changed button; the left-button
// gate is on pointerdown, so release must always clear the pending click.
const shouldActivate = pendingActivationRef.current && !isTabDragActiveRef.current
pendingActivationRef.current = false
setIsPressed(false)