4

I have a simple textbox:

<input type="text" aria-label="First Name" title="First Name" />

I am showing the tooltip First Name on hover of textbox.

I used the aria-label as well as aria-labelledby but neither are working with Chrome or Firefox.

It's working on selection of the textbox, but not working on mouse hover.

But it's working fine with IE on mouse hover as well as on textbox select.

I am using the screen reader NVDA.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hemant Malpote
  • 891
  • 13
  • 28
  • remove the 'title', you do not need a tooltip you need an actual label. – GrahamTheDev Jan 30 '20 at 08:57
  • @GrahamRitchie doesn't works – Hemant Malpote Jan 30 '20 at 09:28
  • I know that doesn't fix your issue, the `title` isn't a good idea that's all. How do people know what the field is about, do you not have an actual label for the input? DO you have a more complete example as I may not be able to fix your issue but I can help you make the input / form accessible and WCAG compliant, at the moment I have a feeling it won't work correctly with most screen readers but I am guessing from that one line of code. – GrahamTheDev Jan 30 '20 at 15:05
  • You need to apply the corresponding ` – Huangism Jan 30 '20 at 15:33

3 Answers3

1

Just to avoid confusion the correct method for labelling an input is to simply use a <label>.

So you should have

<label for="firstName">First Name</label>
<input id="firstName" name="firstName" type="text"/>

The way to link labels and inputs is using the for attribute and point that at the input's ID.

The added benefit of this is that if you click on the label it will focus the corresponding input, which other solutions will not.

Should you for some reason require an input without a label then the following example illustrates how to do this correctly. (please do not do this if you can avoid it, labels are important for people with anxiety disorders to be able to check that they have filled in the correct field - however I know that sometimes 'designers' just won't budge and you have to workaround them....)

In this example we 'visually hide' the label using CSS and add placeholder text to the element. Just to reiterate this is a last resort for those designers who will not listen about accessibility and you should use visible labels.

At least doing it this way the input will function correctly for screen reader users.

.visually-hidden { 
    position: absolute !important;
    height: 1px; 
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap; /* added line */
}
<label for="firstName" class="visually-hidden">First Name</label>
<input id="firstName" name="firstName" placeholder="First Name" type="text"/>

Edit

Finally got chance to test this, works in Firefox, Internet Explorer and not in Chrome for announce on hover.

However if the label is visible it does work fine (if you hover the label, it does not announce if you hover the input itself even with a visible label), it also works fine for if you focus the input.

Final thoughts - show the labels (third time I said this in one answer. hehe), problem solved, no need to make it complicated.

Also, I am not sure why you think this is important, if someone uses a screen reader to assist while using a mouse they will click on an input, I have never come across anyone who would find not having a form field read on hover an accessibility issue if it works correctly once you click into the field.

Also the only people possibly affected by this are:-

  • screen reader users,
  • who use the mouse,
  • who have a sight impediment,
  • who use Google Chrome,
  • who also use NVDA,
  • and do not use a screen magnifier.

pretty specific, so not likely an issue.

Community
  • 1
  • 1
GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • The example you given is not working. DO we need to do any setting changes in NVDA just like we have in JAWS. – Hemant Malpote Jan 31 '20 at 05:09
  • If you use the first example (without hiding the label) it should work. However I think you are too concerned about this particular feature as this is not how screen reader users would use the software, if you click into the input it will announce correctly, if you have a visible label it will announce correctly. Input without a label, I wouldn't expect it to announce at all, if it is doing that is not expected behaviour and will be a quirk of that particular browser / screen reader pairing. The fiddle I gave is the correct and accepted way of handling an input without a visible label. – GrahamTheDev Jan 31 '20 at 09:13
1

Its working on selection of textbox, but not working on mouse hover.

It's not intended to work on mouse hover.

NVDA reads the label for input elements on mouse hover, not the accessible name.

If you want something to be read, you have to add a label.

Adam
  • 17,838
  • 32
  • 54
  • Per [WAI-ARIA 1.1](https://www.w3.org/TR/wai-aria-1.1/#aria-label), aria-label `Defines a string value that labels the current element`. NVDA *should* treat this value as a label, not just an accessible name. If it doesn't, it's a bug. – ilikesleeping Dec 15 '20 at 12:54
-1

I tested with NVDA on Firefox and Chrome and I can confirm the screen reader doesn't announce the value of aria-label on the input

I looked at 2.10 Practical Support: aria-label, aria-labelledby and aria-describedby and found out that aria-label isn't supported for input elements, but aria-labelledby and aria-describedby are. Taken from the link above:

aria-labelledby and aria-describedby are robustly supported for interactive content elements such as links and form controls including the many input types.

So I changed the code this snippet works with NVDA on Chrome and Firefox.

<input type="text"  aria-labelledby="label" />
<span id="label">First Name</span>

Make sure to enclose the input and the "label" inside form for it to work optimally.

Stefany Newman
  • 524
  • 4
  • 9
  • Why would you use a `` instead of a ` – GrahamTheDev Jan 30 '20 at 15:47
  • @GrahamRitchie I know that, but the OP was asking how to make it work with `aria-label` so I assume he can't use ` – Stefany Newman Jan 30 '20 at 16:37
  • There is no reason he can't use a label if he can use a span though. I understand not wanting a **visible** label even though I disagree with designs that do that, but there is no reason to use a span instead of a label but lots of reasons to use a label instead of a span (semantics, linked together, maintainability, W3C HTML5 compliant etc.). As they can both be styled in the same way I can't see a valid use case for using a span over a label. – GrahamTheDev Jan 30 '20 at 16:53
  • @StefanyNewman:The example you given is not working. DO we need to do any setting changes in NVDA just like we have in JAWS. – Hemant Malpote Jan 31 '20 at 05:10