question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If using disabled variant it will not prevent onClick from firing

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
emdowucommented, Mar 12, 2022

just use

pointerEvents: none

on disabled props

4reactions
paul-sachscommented, Mar 30, 2022

Another possibility is to use something like:

const ButtonDisabledVariant = styled("button", {
  "&[disabled]": {
    opacity: 0.5
  }
});
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found