Skip to content

Commit

Permalink
[Fab] Add disabled class to FAB button (mui#34245)
Browse files Browse the repository at this point in the history
  • Loading branch information
meenarama authored and alexfauquette committed Oct 14, 2022
1 parent 3b79aaa commit 31f9d28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/mui-material/src/Fab/Fab.js
Expand Up @@ -6,7 +6,7 @@ import ButtonBase from '../ButtonBase';
import capitalize from '../utils/capitalize';
import useThemeProps from '../styles/useThemeProps';
import fabClasses, { getFabUtilityClass } from './fabClasses';
import styled from '../styles/styled';
import styled, { rootShouldForwardProp } from '../styles/styled';

const useUtilityClasses = (ownerState) => {
const { color, variant, classes, size } = ownerState;
Expand All @@ -20,12 +20,18 @@ const useUtilityClasses = (ownerState) => {
],
};

return composeClasses(slots, getFabUtilityClass, classes);
const composedClasses = composeClasses(slots, getFabUtilityClass, classes);

return {
...classes, // forward the focused, disabled, etc. classes to the ButtonBase
...composedClasses,
};
};

const FabRoot = styled(ButtonBase, {
name: 'MuiFab',
slot: 'Root',
shouldForwardProp: (prop) => rootShouldForwardProp(prop) || prop === 'classes',
overridesResolver: (props, styles) => {
const { ownerState } = props;

Expand Down Expand Up @@ -165,6 +171,7 @@ const Fab = React.forwardRef(function Fab(inProps, ref) {
ownerState={ownerState}
ref={ref}
{...other}
classes={classes}
>
{children}
</FabRoot>
Expand Down
7 changes: 7 additions & 0 deletions packages/mui-material/src/Fab/Fab.test.js
Expand Up @@ -142,6 +142,13 @@ describe('<Fab />', () => {
expect(button.querySelector('.pulsate-focus-visible')).to.equal(null);
});

it('should pass disabled class to ButtonBase', () => {
const disabledClassName = 'testDisabledClassName';
const { container } = render(<Fab disabled classes={{ disabled: disabledClassName }} />);

expect(container.querySelector('button')).to.have.class(disabledClassName);
});

it('should render Icon children with right classes', () => {
const childClassName = 'child-woof';
const iconChild = <Icon data-testid="icon" className={childClassName} />;
Expand Down

0 comments on commit 31f9d28

Please sign in to comment.