mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
fix(tabs): activate clicks when pointer release has no button (#6386)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user