-
Notifications
You must be signed in to change notification settings - Fork 198
Description
Key handling is broken in our Storybook stories. It works in examples outside Storybook, so the problem seems tied to the Storybook integration.
Describe the bug
I noticed the issue while migrating the Validation story to TypeScript. Arrow keys are not handled. I also tried with the legacy keyCode value 40 for ArrowDown and it still did not work.
- Repros on Ubuntu with Chrome and Firefox. Both fail.
- Works in
ts-exampleoutside Storybook. So this looks Storybook-specific. - Our current implementation uses
event.keyCodewhich is deprecated. - On mxGraph, the same validation demo works in Firefox (checked on 2025-08-22).
Note
This might be related to not passing an explicit target node to theKeyHandlerconstructor in the stories.
Links
-
Validation story migration PR: refactor: migrate the
Guidesstory to TypeScript #908- My tests and attempts after CodeRabbit suggestions: refactor: migrate the
Guidesstory to TypeScript #908 (review). This is a good start but this is not always working.
- My tests and attempts after CodeRabbit suggestions: refactor: migrate the
-
mxGraph reference that works in FF: https://jgraph.github.io/mxgraph/javascript/examples/validation.html
-
MDN note about
keyCodedeprecation: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode#browser_compatibility
Steps to Reproduce
- Run Storybook.
- Open the Validation story - also reproduced on the Guides story using other keys (JS or migrated to TS).
- Click in the canvas/story area.
- Press arrow keys (e.g., ArrowDown).
Expected behavior
- Arrow keys are captured and handled by
KeyHandlerin the story. - Behavior is consistent with
ts-exampleand with mxGraph’s demo.
Actual behavior
- Arrow keys are not captured in Storybook stories.
- Same code works in
ts-example(outside Storybook), so it’s not a core logic regression.
Environment
-
OS: Ubuntu
-
Browsers: Chrome and Firefox (both reproduce)
-
Context:
- Repro in Storybook stories (Validation, Guides)
- Works in
packages/examples/ts-example
Hypothesis
- Storybook isolates focus. The target element for key events might not be focused or not focusable.
KeyHandleris created without an explicit target DOM node in stories, so it may attach todocumentwhile Storybook’s iframe steals focus.- Use of deprecated
event.keyCodemay cause inconsistent behavior across browsers in modern setups. Probably not the issue here.
Important
This looks like a Storybook integration detail: focus management and explicit target forKeyHandlerare likely the root causes.
If we don't succeed in making it work in Storybook, we could use an external example instead. We could implement the use case described in #716
Additional context
- The Guides story migrated to TS also reproduces the same problem in PR refactor: migrate the
Guidesstory to TypeScript #908. - I tried a few tweaks based on CodeRabbit recommendations but results were not conclusive yet. Further isolating focus and passing the target node explicitly seems the most promising path.