You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use storybook@8, react and vite. I noticed that a disabled checkbox wrapped in label triggers onChange handler in storybook interaction tests, however I expect it not to. The minimal setup with a reproducible failed test is
If I manually click on the checkbox, it doesn't trigger onChange handler as expected.
If I recreate the same setup in vitest, then it behaves as expected as well.
** Disclaimer** This information might be inaccurate, due to it being generated automatically
This appears to be an issue with how userEvent handles disabled elements in Storybook's test environment. The fix would be to modify the click behavior in @storybook/test's userEvent implementation to respect the disabled attribute. Specific steps: 1. Check @storybook/test-runner/src/user-event for the click event handling 2. Add a check before triggering click events: js const isDisabled = element.hasAttribute('disabled') || element.closest('label')?.querySelector('[disabled]'); if (isDisabled) { return; } 3. This should be added before the click event is dispatched to prevent interaction with disabled elements
About Greptile
This response provides a starting point for your research, not a precise solution.
Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
lebedev
changed the title
[Bug]: Disabled input is clickable in interaction tests
[Bug]: Disabled checkbox is clickable in interaction tests
Mar 11, 2025
Describe the bug
I use
storybook@8
,react
andvite
. I noticed that a disabled checkbox wrapped in label triggersonChange
handler in storybook interaction tests, however I expect it not to. The minimal setup with a reproducible failed test isIf I manually click on the checkbox, it doesn't trigger
onChange
handler as expected.If I recreate the same setup in vitest, then it behaves as expected as well.
Reproduction link
https://stackblitz.com/edit/github-6tqsvjkd-c8xb1vxt?file=src%2Fstories%2FCheckbox.stories.tsx
Reproduction steps
Checkbox
->Primary
story, thenInteraction
tab with a failed test.System
Additional context
I think that it's
userEvent
behaves not like a user doing events in storybook environment.The text was updated successfully, but these errors were encountered: