Skip to content

Commit

Permalink
[material-ui][Select] Do not set aria-controls when closed (#44919)
Browse files Browse the repository at this point in the history
Signed-off-by: siddhantantil39 <[email protected]>
Co-authored-by: Albert Yu <[email protected]>
  • Loading branch information
siddhantantil39 and mj12albert authored Jan 7, 2025
1 parent 4d1bb85 commit 0221d17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/mui-material/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ describe('<Select />', () => {
expect(getByRole('combobox', { hidden: true })).to.have.attribute('aria-controls', listboxId);
});

it('does not set aria-controls when closed', () => {
const { getByRole } = render(<Select open={false} value="" />);
expect(getByRole('combobox', { hidden: true })).to.not.have.attribute('aria-controls');
});

specify('the listbox is focusable', async () => {
const { getByRole } = render(<Select open value="" />);

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
ref={handleDisplayRef}
tabIndex={tabIndex}
role="combobox"
aria-controls={listboxId}
aria-controls={open ? listboxId : undefined}
aria-disabled={disabled ? 'true' : undefined}
aria-expanded={open ? 'true' : 'false'}
aria-haspopup="listbox"
Expand Down

0 comments on commit 0221d17

Please sign in to comment.