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

[RFR] Automatically add id attribute on input if not specified and accessibility fixes #2351

Merged
merged 1 commit into from
Sep 26, 2018

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Sep 24, 2018

  • Infer id from source prop and set the id and htmlFor props automatically
  • Adds aria-label to buttons

This allows material-ui to bind labels to their inputs using the for attribute, simplifying e2e tests with libraries such as react-test-utils and providing better accessibility.

For example, using cypress-testing-library in cypress, with an input written as:

<TextInput source="first_name" />

We can now write tests like:

cy.getByLabelText('First Name').type('Gildas');

Before, for the same result, we would have written the input as:

<TextInput id="first_name" source="first_name" />

NOTE: it is still possible to override the default id inferred from the source prop

@djhi djhi changed the title [RFR] Automatically add id attribute on input if not specified [WIP] Automatically add id attribute on input if not specified Sep 24, 2018
@djhi djhi changed the title [WIP] Automatically add id attribute on input if not specified [RFR] Automatically add id attribute on input if not specified Sep 24, 2018
@djhi djhi changed the title [RFR] Automatically add id attribute on input if not specified [RFR] Automatically add id attribute on input if not specified and accessibility fixes Sep 24, 2018
@fzaninotto
Copy link
Member

Awesome! Although, strictly speaking, this is an evolution, so it should land in next rather than master. Can you rebase to the next branch?

@djhi djhi changed the base branch from master to next September 25, 2018 21:09
@fzaninotto fzaninotto merged commit 9598545 into next Sep 26, 2018
@fzaninotto fzaninotto deleted the accessibility branch September 26, 2018 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants