6

My HTML is as below (an extracted portion):

<h1><span>Main Menu</span></h1>
<div>
    <button tabindex="0">New Customer</button><br>
    <button tabindex="0">Existing Customer</button>
</div>

I am using NVDA. When the user enters the screen, the focus is on the first button. NVDA reads the text on the first button(New Customer). It skips the heading (h1). I assumed it should read the h1 tags without any of the aria tags like aria-label. Am I wrong in my assumption? What do I need to do to make this work?

3
  • 2
    What's the span for inside the h1?
    – msanford
    Commented Feb 8, 2018 at 21:29
  • The heading reads fine in JAWS17/18 and NVDA2015.3 and 2017.4. Also why do you have tabindex=0 assigned to the buttons? Buttons are already interactive and included in the tab order.
    – J. Afarian
    Commented Feb 8, 2018 at 22:29
  • If the focus is set to the first button when the user enters the screen (I'm assuming by calling .focus() on the element) then the user as essentially already bypassed the h1 in source order. They would need to shift+tab back to that heading to hear it read. You could consider moving the h1 markup below the buttons. that wouldn't solve the issue completely, but that seems like on barrier to this problem
    – kdub1312
    Commented Mar 10, 2022 at 15:54

2 Answers 2

2

If you want a group label around your buttons that will be read when focus moves into the group, then use role='group' and aria-label on the container. The group label will be read when you TAB forward into the group ("New Customer") and when you TAB backwards into the group ("Existing Customer").

<div role="group" aria-label="Main Menu">
  <div>
    <button>New Customer</button><br>
    <button tabindex="0">Existing Customer</button>
  </div>
</div>

The above example does not visually show the text "Main Menu". You can still have that displayed if you want using:

<div role="group" aria-label="Main Menu">Main Menu
  <div>
    <button>New Customer</button><br>
    <button>Existing Customer</button>
  </div>
</div>

You could also use a <nav> element, but with your brief snippet, it doesn't sound like the buttons are for navigation so I wouldn't recommend this but wanted to show it for completeness:

<nav aria-label="Main Menu">
  <div>
    <button>New Customer</button><br>
    <button>Existing Customer</button>
  </div>
</nav>
0

If you are using a script to send focus to the first button, screenreader software will skip over anything in the markup before that and go straight to the button. You should be able to use the arrow keys to go back up to hear it.

Generally it’s best practise to let the user control focus with clicks/taps instead of automating it for them on page load.

Not the answer you're looking for? Browse other questions tagged or ask your own question.