question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:

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.

image

Suggested solution:

It would really help if you could support the placeholder during accessible name calculation.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Apr 2, 2021

I’d imagine that support has only grown since then.

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.

@eps1lon Looks like the only thing you have that relates to placeholder is a commit removing the TODO since you didn’t find any reference for it 😅

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.

1reaction
eps1loncommented, Apr 1, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found