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..75e4d90 100644
--- a/tests/index.test.tsx
+++ b/tests/index.test.tsx
@@ -336,6 +336,39 @@ 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(