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

Typing storybook shortcuts in inputs triggers them #491

Closed
stropitek opened this issue Jun 1, 2023 · 7 comments
Closed

Typing storybook shortcuts in inputs triggers them #491

stropitek opened this issue Jun 1, 2023 · 7 comments

Comments

@stropitek
Copy link
Contributor

For example, try typing s in an input: it opens / closes the storybook sidebar

Might be related to shadow dom? Because I don't remember having the same issues in other projects using storybook

@stropitek
Copy link
Contributor Author

stropitek commented Aug 10, 2023

I made some research and I think I understand why storybook triggers shortcut actions when typing in inputs.

I read this interesting article which reveals that:

Most of the standard UI events bubble and are composed with a few exceptions. There are a few exceptions like mouseenter and mouseleave that aren't bubbling and composed.

The key here is that composed events leak to the shadow dom when they bubble up the dom tree.

If add an event listener on the storybook root like this:

storybookRoot.addEventListener('keydown', (event) => { console.log(event.composedPath(), event.target)})

it gives this:
CleanShot 2023-08-10 at 12 27 04

Therefore I suspect storybook to use the target property to know where the event originated from. If the event comes from within the shadow tree, the target element is the shadow host and storybook might think it originated from a div, not some input.

Will try to confirm that by searching in storybook's source code. Seems that could be fixable by using the result from composedPath()

@targos
Copy link
Member

targos commented Aug 10, 2023

Is it possible to block event bubbling so it doesn't exit the shadow dom (not sure we want that though) ?

@stropitek
Copy link
Contributor Author

stropitek commented Aug 10, 2023

Is it possible to block event bubbling so it doesn't exit the shadow dom (not sure we want that though) ?

Could work but only if the listener of the event which we want to prevent is not directly on the shadow host. But I don't know if it's possible to change the bubbling behaviour of a standard event.

@targos
Copy link
Member

targos commented Aug 10, 2023

I wonder if the problem also affects storybook users who create custom elements (web components).

@stropitek
Copy link
Contributor Author

@stropitek
Copy link
Contributor Author

@stropitek
Copy link
Contributor Author

Fixed in storybook but also since we moved away from shadow dom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants