Skip to content

Commit

Permalink
fix Button disabled prop priority
Browse files Browse the repository at this point in the history
  • Loading branch information
Smileek committed Feb 9, 2024
1 parent 5ae79e6 commit bd1a2a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mui-joy/src/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const Button = React.forwardRef(function Button(inProps, ref) {
const size = inProps.size || buttonGroup.size || sizeProp;
const color = inProps.color || buttonGroup.color || colorProp;
const disabled =
(inProps.disabled || inProps.loading) ?? (buttonGroup.disabled || disabledProp || loading);
(inProps.loading || inProps.disabled) ?? (buttonGroup.disabled || disabledProp || loading);

const buttonRef = React.useRef<HTMLElement>(null);
const handleRef = useForkRef(buttonRef, ref);
Expand Down
11 changes: 11 additions & 0 deletions packages/mui-joy/src/ButtonGroup/ButtonGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ describe('<ButtonGroup />', () => {
expect(getAllByRole('button')[0]).to.have.property('disabled', true);
expect(getAllByRole('button')[1]).to.have.property('disabled', true);
});

it('pass disabled to buttons inless it is overriden', () => {
const { getAllByRole } = render(
<ButtonGroup disabled>
<Button disabled={false} />
<IconButton disabled={false} />
</ButtonGroup>,
);
expect(getAllByRole('button')[0]).not.to.have.property('disabled', true);
expect(getAllByRole('button')[1]).not.to.have.property('disabled', true);
});
});

0 comments on commit bd1a2a1

Please sign in to comment.