Skip to content

Commit

Permalink
Set attributes to undefined (aka hide them) when false. Ultimately sh…
Browse files Browse the repository at this point in the history
…ould be the same behavior, but cleaner html
  • Loading branch information
ben-pomelo committed Dec 12, 2024
1 parent 90c3777 commit 17e2574
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/mui-material/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ describe('<Select />', () => {
expect(getByRole('combobox')).to.have.attribute('aria-required', 'true');
});

it('aria-required is not present if component is not required', () => {
const { getByRole } = render(<Select required={false} value="" />);

expect(getByRole('combobox')).not.to.have.attribute('aria-required');
});

it('sets required attribute in input when component is required', () => {
const { container } = render(<Select required value="" />);

Expand All @@ -486,6 +492,13 @@ describe('<Select />', () => {
expect(getByRole('combobox')).to.have.attribute('aria-invalid', 'true');
});

it('aria-invalid is not present if component is not in an error state', () => {
const { getByRole } = render(<Select value="" />);

expect(getByRole('combobox')).not.to.have.attribute('aria-invalid');
});


it('indicates that activating the button displays a listbox', () => {
const { getByRole } = render(<Select value="" />);

Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
aria-label={ariaLabel}
aria-labelledby={[labelId, buttonId].filter(Boolean).join(' ') || undefined}
aria-describedby={ariaDescribedby}
aria-required={required}
aria-invalid={error}
aria-required={required ? 'true' : undefined}
aria-invalid={error ? 'true' : undefined}
onKeyDown={handleKeyDown}
onMouseDown={disabled || readOnly ? null : handleMouseDown}
onBlur={handleBlur}
Expand Down

0 comments on commit 17e2574

Please sign in to comment.