material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Button] Disabled buttons should have `cursor: not-allowed` by default

Open Maia313 opened this issue 3 years ago • 10 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Summary 💡

Disabled buttons should have cursor not allowed by default

Examples 🌈

No response

Motivation 🔦

Helps user better notice the state of the buttons

Maia313 avatar Apr 19 '22 11:04 Maia313

Can you elaborate on your point?

Disabled buttons already have the default cursor, not the pointer.

Example: https://codesandbox.io/s/basicbuttons-material-demo-forked-oeg9mk

hbjORbj avatar Apr 19 '22 13:04 hbjORbj

To make it more intuitive for the user, on hover they should probably have cursor: not-allowed;

Maia313 avatar Apr 20 '22 04:04 Maia313

Does that align with material design, @danilo-leal ?

Codesandbox for cursor: not-allowed with Button: https://codesandbox.io/s/basicbuttons-material-demo-forked-2pe2qn?file=/demo.js

hbjORbj avatar Apr 20 '22 07:04 hbjORbj

This is a tough one and I don't think Material Design is the place to refer to in order to find out the optimal way. This exact same discussion happened in this thread https://github.com/mui/material-ui/pull/27719#discussion_r690716745 and I don't believe there was a final conclusion.

I'd appreciate it if you @Maia313 read through it and added your perspective. Also, if you happen to have any documentation about it, that would be great.

danilo-leal avatar Apr 20 '22 19:04 danilo-leal

You can customize it creating your theme also.

henriqueholtz avatar Jul 02 '22 12:07 henriqueholtz

customize it, Share a tip:

// css
.pointer-events-none {
    pointer-events: none;
}

.wrapper {
    cursor: not-allowed;
}


// Dom
<div class="wrapper">
    <button class="pointer-events-none">Some Text</button>// OR <MuiButton>....</MuiButton>
</div>

hongdeyuan avatar Feb 23 '23 08:02 hongdeyuan

Actually up... It's a shame that there's no way to change the cursor of an MUI button when it is in the "disabled" state. Tried everything, changing the style in sx in style and finally in my global SCSS file. Nothing worked. The button seems to be completely out of flow (even though tab-index="-1"). It's even impossible to select the button using the browser console. I feel like it's not optimal.

Focus-me34 avatar Oct 04 '23 10:10 Focus-me34

In button.tsx generated by ShadCn, you can change the cursor in there. Here is short snippet where cursor will be not-allowed for disabled buttons

const buttonVariants = cva( 'inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', { variants: { variant: { default: 'bg-primary text-primary-foreground hover:bg-primary/90', destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90', outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground', secondary: 'bg-secondary border border-solid border-slate-500 text-secondary-foreground hover:bg-secondary/80', ghost: 'hover:bg-accent hover:text-accent-foreground', link: 'text-primary underline-offset-4 hover:underline', }, size: { default: 'h-10 px-4 py-2', sm: 'h-9 rounded-md px-3', lg: 'h-11 rounded-md px-8', icon: 'h-10 w-10', }, }, defaultVariants: { variant: 'default', size: 'default', }, }, );

Just. change the below line which is by default to your preferred stylings

disabled:pointer-events-none

R-Mohammed-Hasan avatar Oct 24 '23 06:10 R-Mohammed-Hasan

It is not that difficult to change the cursor when button is disabled.

sx={{
      "&:disabled": {
           cursor: "not-allowed",
           pointerEvents: "all !important",
      },
}}

ArslanKhann avatar Nov 16 '23 08:11 ArslanKhann

The premise of this issue seems incorrect according to the MDN documentation. It appears that the not-allowed cursor is used for indicating a drag & drop action will not be carried out. There should be other ways to indicate that a button is disabled outside of violating the specification. Just my 2 cents.

gsavchenko avatar Oct 08 '25 14:10 gsavchenko