If using disabled variant it will not prevent onClick from firing
See original GitHub issueBug report
Describe the bug
When you use the disabled
variant on a button, the onClick
will fire. If you don’t add this variant, it will prevent the onClick
from firing as expected.
const ButtonDisabledVariant = styled("button", {
variants: {
disabled: {
true: {
opacity: 0.5
}
}
}
});
To Reproduce
This example has two buttons, one with the disabled
variant and one without to illustrate:
https://codesandbox.io/s/gallant-sky-up4h1s
Expected behavior
I expect the onClick
handler to not fire when when it’s disabled even when I’m adding disabled
as a variant.
System information
- OS: macOS
- Browser: Firefox, Safari, Chrome
- Version of Stitches: 1.2.7
- Version of Node.js: 16.8.0
Additional context
I suspect this might happen because the disabled
part of the button will be completely replaced with stitches own implementation?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Disabled button still fires using ".click()" - Stack Overflow
The attribute only disables user interaction, the button is still usable programmatically. So yeah, you gotta check
Read more >disabled - CSS: Cascading Style Sheets - MDN Web Docs
An element is disabled if it can't be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has an...
Read more >Introduction to browser events - The Modern JavaScript Tutorial
An event is a signal that something has happened. All DOM nodes generate such signals (but events are not limited to DOM). Here's...
Read more >pointer-events | CSS-Tricks
The pointer-events property allows for control over how HTML elements respond to mouse/touch events – including CSS hover/active states, ...
Read more >Overlays | React-Bootstrap
Elements with the disabled attribute aren't interactive, meaning users cannot hover or click them to trigger a popover (or tooltip). As a workaround,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
just use
on disabled props
Another possibility is to use something like: