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

[TextField] Use aria-hidden on required asterisk #20742

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: 1 addition & 0 deletions packages/material-ui/src/FormLabel/FormLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const FormLabel = React.forwardRef(function FormLabel(props, ref) {
{children}
{fcs.required && (
<span
aria-hidden
className={clsx(classes.asterisk, {
[classes.error]: fcs.error,
})}
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui/src/FormLabel/FormLabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ describe('<FormLabel />', () => {
}));

describe('prop: required', () => {
it('should show an asterisk if required is set', () => {
it('should visually show an asterisk but not include it in the a11y tree', () => {
const { container } = render(<FormLabel required>name</FormLabel>);

expect(container.querySelector('label')).to.have.text('name\u2009*');
expect(container.querySelectorAll(`.${classes.asterisk}`)).to.have.lengthOf(1);
expect(container.querySelectorAll(`.${classes.asterisk}`)[0]).toBeAriaHidden();
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
});

it('should not show an asterisk by default', () => {
Expand All @@ -48,6 +49,7 @@ describe('<FormLabel />', () => {

expect(container.querySelectorAll(`.${classes.asterisk}`)).to.have.lengthOf(1);
expect(container.querySelector(`.${classes.asterisk}`)).to.have.class(classes.error);
expect(container.querySelectorAll(`.${classes.asterisk}`)[0]).toBeAriaHidden();
expect(container.firstChild).to.have.class(classes.error);
});
});
Expand Down