Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
How to make screen reader read a heading in a component on mount if initial focus is set to another element?

Is it possible to make a screen reader read a text (heading, span or div) on mount if focus is set to another element in the page?

I have a react app with a login page. The login page has input boxes for user name and password with initial focus set to username using autoFocus. The page has a heading too. How can I make a screen reader read the heading when it is mounted without losing focus from username? Please see the sample codepen: Sample app.

The above sample has a login button in the initial landing page, clicking on it will load login component. I want screen reader to read the heading first without losing focus from username input. Tried aria-live attribute, but it is not working. Can someone please help?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe a <fieldset> is exactly what you are looking for.

ARIA defines the abstract structure role, which groups the content in different contexts, so to say. landmark falls under these, group as well.

I’m not sure on which role this logic is based exactly, but screen readers announce these context changes, so when focus leaves one group and/or enters another, their roles and names are announced.

So if your heading serves as the accessible name for a structure that the auto-focussed input is part of, it should be announced.

One very appropriate structure role for forms is that of group, implemented by <fieldset>.

<button onclick="document.querySelector('input').focus();">Login</button>

<form>
  <fieldset>
    <legend><h3>Enter Credentials</h3></legend>

    <label>Username
      <input name="username" autofocus>
    </label>
  </fieldset>
</form>

After pressing the Login button, NVDA (with Firefox or Chrome) will announce:

Enter Credentials, grouping
Username, edit, has autocomplete, blank

Orca with Firefox is similar, but Chromevox unfortunately does not announce the group, neither the name of a <section>.

Notice also name="username". This is a common standard to allow browsers to autocomplete fields, important for accessibility. You could also add autocomplete="username" if you have a different name.

The outermost context inside the site would be that of the document. Its accessible name is the meta <title> of your page, which will be announced in the beginning, that’s unavoidable.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!