Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: keyboard shortcuts cause focus los on custom elements #23670

Open
rhelling opened this issue Aug 1, 2023 · 6 comments
Open

[Bug]: keyboard shortcuts cause focus los on custom elements #23670

rhelling opened this issue Aug 1, 2023 · 6 comments

Comments

@rhelling
Copy link

rhelling commented Aug 1, 2023

Describe the bug

When I have a story which contains a custom element, I want to be able to type certain characters into the element such as "1".

Probable cause of the issue

Storybook has a check when you type inside an input element to verify if the keyboard event is emitted from an input, textarea or contenteditable element. This check, however, does not work from within custom elements because of event retargeting.

image

To Reproduce

https://stackblitz.com/edit/github-gdt3q9?file=src%2Fstories%2FInput.stories.ts

type 1 inside the given input

System

Environment Info:

  System:
    OS: macOS 13.4.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 18.17.0 - ~/.volta/tools/image/node/18.17.0/bin/node
    npm: 9.6.7 - ~/.volta/tools/image/node/18.17.0/bin/npm
  Browsers:
    Chrome: 115.0.5790.114
    Safari: 16.5.2
  npmPackages:
    @storybook/addon-a11y: ^7.0.4 => 7.1.1
    @storybook/addon-essentials: ^7.0.4 => 7.1.1
    @storybook/addon-links: ^7.0.4 => 7.1.1
    @storybook/addon-mdx-gfm: ^7.0.4 => 7.1.1
    @storybook/addon-storysource: ^7.0.4 => 7.1.1
    @storybook/addons: ^7.0.4 => 7.1.1
    @storybook/blocks: ^7.0.4 => 7.1.1
    @storybook/theming: ^7.0.4 => 7.1.1
    @storybook/web-components: ^7.0.4 => 7.1.1
    @storybook/web-components-vite: ^7.0.4 => 7.1.1

Additional context

Suggested solution

  • Extend the check to the first element in the target.composedPath()
  • Extend the check to elements that have an aria role like input, searchbox, textbox or combobox
@quintondang
Copy link

I have been running into this too! 🙏

@rhelling
Copy link
Author

@quintondang as a workaround you can set the enableShortcuts to false in the manager.ts. This disables the keyboard shortcuts for all stories.

import {addons} from '@storybook/manager-api';

addons.setConfig({
  enableShortcuts: false
});

@quintondang
Copy link

@rhelling do you know if you can disable it for a single story?

@shilman
Copy link
Member

shilman commented Sep 20, 2023

Extend the check to the first element in the target.composedPath()
Extend the check to elements that have an aria role like input, searchbox, textbox or combobox

If somebody wants to create a PR with one of the suggested solutions, that would be a great contribution

@rasvii
Copy link

rasvii commented Nov 17, 2023

@shilman I am interested to try out the solutions.

@noelparisi
Copy link

👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

5 participants