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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Checkbox, Menu, Switch] Audit focus states on disabled components #734

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/data/api/menu-trigger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"props": {
"className": { "type": { "name": "union", "description": "func<br>&#124;&nbsp;string" } },
"disabled": { "type": { "name": "bool" }, "default": "false" },
"focusableWhenDisabled": { "type": { "name": "bool" }, "default": "false" },
"label": { "type": { "name": "string" } },
"render": { "type": { "name": "union", "description": "element<br>&#124;&nbsp;func" } }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"description": "Class names applied to the element or a function that returns them based on the component&#39;s state."
},
"disabled": { "description": "If <code>true</code>, the component is disabled." },
"focusableWhenDisabled": {
"description": "If <code>true</code>, allows a disabled button to receive focus."
},
"label": { "description": "Label of the button" },
"render": { "description": "A function to customize rendering of the component." }
},
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-base/src/Checkbox/Root/CheckboxRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ describe('<Checkbox.Root />', () => {
});

describe('prop: disabled', () => {
it('should have the `aria-disabled` attribute', async () => {
it('should have the `disabled` attribute', async () => {
const { getAllByRole } = await render(<Checkbox.Root disabled />);
expect(getAllByRole('checkbox')[0]).to.have.attribute('aria-disabled', 'true');
expect(getAllByRole('checkbox')[0]).to.have.attribute('disabled');
});

it('should not have the aria attribute when `disabled` is not set', async () => {
it('should not have the `disabled` attribute when `disabled` is not set', async () => {
const { getAllByRole } = await render(<Checkbox.Root />);
expect(getAllByRole('checkbox')[0]).not.to.have.attribute('aria-disabled');
expect(getAllByRole('checkbox')[0]).not.to.have.attribute('disabled');
});

it('should not change its state when clicked', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Checkbox/Root/useCheckboxRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export function useCheckboxRoot(params: UseCheckboxRoot.Parameters): UseCheckbox
value: 'off',
type: 'button',
role: 'checkbox',
disabled,
'aria-checked': indeterminate ? 'mixed' : checked,
'aria-disabled': disabled || undefined,
'aria-readonly': readOnly || undefined,
'aria-labelledby': labelId,
onBlur() {
Expand Down
10 changes: 0 additions & 10 deletions packages/mui-base/src/Menu/Trigger/MenuTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ namespace MenuTrigger {
* @default false
*/
disabled?: boolean;
/**
* If `true`, allows a disabled button to receive focus.
* @default false
*/
focusableWhenDisabled?: boolean;
/**
* Label of the button
*/
Expand Down Expand Up @@ -103,11 +98,6 @@ MenuTrigger.propTypes /* remove-proptypes */ = {
* @default false
*/
disabled: PropTypes.bool,
/**
* If `true`, allows a disabled button to receive focus.
* @default false
*/
focusableWhenDisabled: PropTypes.bool,
/**
* Label of the button
*/
Expand Down
1 change: 0 additions & 1 deletion packages/mui-base/src/Menu/Trigger/useMenuTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export function useMenuTrigger(parameters: useMenuTrigger.Parameters): useMenuTr

const { getButtonProps, buttonRef } = useButton({
disabled,
focusableWhenDisabled: false,
buttonRef: mergedRef,
});

Expand Down
8 changes: 4 additions & 4 deletions packages/mui-base/src/Switch/Root/SwitchRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ describe('<Switch.Root />', () => {
});

describe('prop: disabled', () => {
it('should have the `aria-disabled` attribute', async () => {
it('should have the `disabled` attribute', async () => {
const { getByRole } = await render(<Switch.Root disabled />);
expect(getByRole('switch')).to.have.attribute('aria-disabled', 'true');
expect(getByRole('switch')).to.have.attribute('disabled');
});

it('should not have the aria attribute when `disabled` is not set', async () => {
it('should not have the `disabled` attribute when `disabled` is not set', async () => {
const { getByRole } = await render(<Switch.Root />);
expect(getByRole('switch')).not.to.have.attribute('aria-disabled');
expect(getByRole('switch')).not.to.have.attribute('disabled');
});

it('should not change its state when clicked', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Switch/Root/useSwitchRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export function useSwitchRoot(params: useSwitchRoot.Parameters): useSwitchRoot.R
ref: buttonRef,
type: 'button',
role: 'switch',
disabled,
'aria-checked': checked,
'aria-disabled': disabled || undefined,
'aria-readonly': readOnly,
'aria-labelledby': labelId,
onBlur() {
Expand Down
Loading