Accessible name not based on placeholder
See original GitHub issue@testing-library/dom
version: 7.28.1- Testing Framework and version: Jest 26.6.0
- DOM Environment: jsdom 16.4.0 (also tested with cypress 6.1.0)
- Other: create-react-app with react-scripts 4.0.3
Relevant code or config:
App.js
function App() {
return (
<div className="App">
<input type="text" placeholder="placeholder-value" />
</div>
);
}
export default App;
App.test.js
test('finds textbox by role and placeholder', () => {
render(<App />);
expect(screen.getByRole('textbox', { name: 'placeholder-value' })).toBeVisible()
});
What you did:
Run test (via yarn test
)
What happened:
The test fails with the message:
TestingLibraryElementError: Unable to find an accessible element with the role "textbox" and name "placeholder-value"
Here are the accessible roles:
textbox:
Name ""
Note that the value for Name is empty
Reproduction:
- clone https://github.com/nphmuller/dom-testing-placeholder-repro
- run
yarn test
Relevant commit: https://github.com/nphmuller/dom-testing-placeholder-repro/commit/1786a0a4c048f244a469ac8a0fa1bdaf92fc54a3
Problem description:
When looking at the Chrome dev tools, the accessible name is also calculated based on the placeholder. See the screenshot below. dom-testing-library seems to ignore the placeholder value for calculating this name.
Suggested solution:
It would really help if you could support the placeholder during accessible name calculation.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
input where "placeholder" should be accessible name
In example 4, the title value of "Rabbit" should be announced as the accessible name as no other accessible name is provided. As...
Read more >Is placeholder text a sufficient accessible label for form fields
In a mobile first world many websites use placeholder text to save space. Let's test to see if its a good idea. In...
Read more >Placeholder Research - Low Vision Accessibility Task Force
The placeholder is a short hint intended to aid the user with data entry so it should not be identical to the label...
Read more >Decoding Label and Name for Accessibility - WebAIM
The HTML specification for placeholder states as much: "The placeholder attribute should not be used as an alternative to a label" (meaning WCAG ......
Read more >aria-placeholder - Accessibility - MDN Web Docs - Mozilla
If you are creating a textbox using any other element, placeholder is not supported. That is where aria-placeholder comes into play. The aria- ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Or not. In any case, we need to verify that claim. It might also be that AT just do this to fix author errors. AT and the ARIA spec make a big effort to fix author errors. That doesn’t mean that we as a dev tool should accept these errors which effectively encourages them.
Thanks for digging this up. That comment basically confirms my current suspicion: There are no references to
placeholder
being used in the accessible name. But that doesn’t mean there aren’t actually any.I seem to remember putting some notes into https://github.com/eps1lon/dom-accessibility-api concerning placeholder. So I would suggest doing some digging there. Then we need to double check what
accname
would say and then what assistive technology (e.g. NVDA, VoiceOver, JAWS) actually do in these cases. Chrome devtools is not our primary source of truth here.Regardless, don’t use placeholders.