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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fab] Hover CSS styles mix up with disabled styles on tap on mobile #35039

Closed
2 tasks done
Uzwername opened this issue Nov 7, 2022 · 5 comments 路 Fixed by #35304
Closed
2 tasks done

[Fab] Hover CSS styles mix up with disabled styles on tap on mobile #35039

Uzwername opened this issue Nov 7, 2022 · 5 comments 路 Fixed by #35304
Assignees
Labels
bug 馃悰 Something doesn't work component: Fab The React component. package: material-ui Specific to @mui/material

Comments

@Uzwername
Copy link
Contributor

Uzwername commented Nov 7, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 馃暪

Link to live example: https://yrh2tw.csb.app/

Steps:

  1. Render a @mui/material/Fab
  2. Disable it once it gets clicked
  3. Simulate a mobile device using Chrome's developer tools (the same happens on real mobiles)
  4. Tap on the Fab
  5. See hover styles applied to the disabled Fab

Current behavior 馃槸

React.App.webm

Expected behavior 馃

Disabled styles must take precedence, the Fab must look disabled (have the corresponding background, etc.).

Context 馃敠

Initially, I found this bug while using Fab as a navigation button inside a multistep form (which isn't its main use case, obviously).

Your environment 馃寧

npx @mui/envinfo

Reproducible with codesandbox

@Uzwername Uzwername added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 7, 2022
@Uzwername
Copy link
Contributor Author

Uzwername commented Nov 7, 2022

IRL I've fixed this by passing the following as sx prop to the Fab:

import { fabClasses } from '@mui/material/Fab';
import type { Theme } from '@mui/material';

// ...

export const NAV_FAB = (theme: Theme) => ({
  [`&.${fabClasses.disabled}, &.${fabClasses.disabled}:hover, &.${fabClasses.disabled}:focus`]: {
    backgroundColor: theme.palette.action.disabledBackground,
  },
});

I'd be glad to open a PR to fix it

@zannager zannager added the package: system Specific to @mui/system label Nov 8, 2022
@michaldudak michaldudak self-assigned this Nov 8, 2022
@Uzwername
Copy link
Contributor Author

Just following up: is this going to be addressed?

@michaldudak michaldudak added component: Fab The React component. package: material-ui Specific to @mui/material and removed package: system Specific to @mui/system labels Nov 28, 2022
@michaldudak
Copy link
Member

Moving the disabled styles to the very bottom should do the trick without increasing specificity:

@@ -76,11 +76,6 @@ const FabRoot = styled(ButtonBase, {
     [`&.${fabClasses.focusVisible}`]: {
       boxShadow: (theme.vars || theme).shadows[6],
     },
-    [`&.${fabClasses.disabled}`]: {
-      color: (theme.vars || theme).palette.action.disabled,
-      boxShadow: (theme.vars || theme).shadows[0],
-      backgroundColor: (theme.vars || theme).palette.action.disabledBackground,
-    },
     ...(ownerState.size === 'small' && {
       width: 40,
       height: 40,
@@ -132,6 +127,13 @@ const FabRoot = styled(ButtonBase, {
         },
       }),
   }),
+  ({ theme }) => ({
+    [`&.${fabClasses.disabled}`]: {
+      color: (theme.vars || theme).palette.action.disabled,
+      boxShadow: (theme.vars || theme).shadows[0],
+      backgroundColor: (theme.vars || theme).palette.action.disabledBackground,
+    },
+  }),
 );

 const Fab = React.forwardRef(function Fab(inProps, ref) {

Would you like to create a PR?

@michaldudak michaldudak added bug 馃悰 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 28, 2022
@Uzwername
Copy link
Contributor Author

@michaldudak Sure thing, I'll submit it soon

@Uzwername
Copy link
Contributor Author

Uzwername commented Nov 29, 2022

I'm going to submit a PR no later than tomorrow night (UTC)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work component: Fab The React component. package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants