From 32f41cdd9f09599b6734f8f4dd3044399b5ac271 Mon Sep 17 00:00:00 2001 From: yoyo837 <6134547+yoyo837@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:20:53 +0800 Subject: [PATCH 1/2] fix: leave Enter/Space untouched for nested focusable content The `onKeyDown` handler of a clickable step handled Enter/Space without checking the event target, so it also reacted to keydown events bubbling up from focusable descendants: a space typed in an `` nested in the step content was swallowed by `preventDefault()`, and pressing Enter/Space there activated the step as well. Only handle the keys when the event targets the step element itself. --- src/Step.tsx | 6 ++++++ tests/index.test.tsx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Step.tsx b/src/Step.tsx index eb9eb25..c359231 100644 --- a/src/Step.tsx +++ b/src/Step.tsx @@ -109,6 +109,12 @@ export default function Step(props: StepProps) { }; accessibilityProps.onKeyDown = (e) => { + // Only handle keys pressed on the step itself. Events bubbling up from + // nested focusable content (e.g. an `` in the step content) must be + // left untouched, otherwise Space / Enter would be swallowed there. + if (e.target !== e.currentTarget) { + return; + } if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.currentTarget.click(); diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 261fea1..cc1140c 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -336,6 +336,36 @@ describe('Steps', () => { expect(spaceEvent.defaultPrevented).toBe(true); }); + it('should leave Enter/Space untouched when they bubble up from a nested input', () => { + const onChange = jest.fn(); + const onItemClick = jest.fn(); + const { container } = render( + , + onClick: onItemClick, + }, + ]} + />, + ); + + const input = container.querySelector('input'); + const enterEvent = createEvent.keyDown(input, { key: 'Enter' }); + const spaceEvent = createEvent.keyDown(input, { key: ' ' }); + + fireEvent(input, enterEvent); + fireEvent(input, spaceEvent); + + expect(enterEvent.defaultPrevented).toBe(false); + expect(spaceEvent.defaultPrevented).toBe(false); + expect(onChange).not.toHaveBeenCalled(); + expect(onItemClick).not.toHaveBeenCalled(); + }); + it('itemRender', () => { const { container } = render( Date: Wed, 25 Nov 2026 00:27:34 +0800 Subject: [PATCH 2/2] test: put the nested input on a non-current step With the input on the step that is already `current`, `onChange` is never called regardless of whether the key incorrectly activates the step, so that assertion could not detect the regression. --- tests/index.test.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/index.test.tsx b/tests/index.test.tsx index cc1140c..75e4d90 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -344,6 +344,9 @@ describe('Steps', () => { current={0} onChange={onChange} items={[ + { + title: 'Finished', + }, { title: 'Waiting', content: ,