Spacebar usage according to WCAG 2.0 - html

I want to know, according to WCAG 2.0, in which cases the spacebar is used to interact within the page.
Is it use in the same cases as the enter key?
Should I provide the same function to the enter key and the spacebar?

Do not change the native behavior of controls. That can mess with users.
A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. If there isn’t more to scroll then the user just experiences nothing.
I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).
I have a CodePen from another example that shows this: http://s.codepen.io/aardrian/debug/PZQJyd
If you are making something like a <div> clickable and trying to add keyboard interaction, then do not use a <div>. Use the right element for the purpose, which I briefly outline as:
Does the control take me to another page? Use an anchor (<a href>).
Does the control change something on the current page? Use <button>.
Does the control submit form fields? Use <input type=submit> or <button type=submit>.

As far as WCAG 2.0 it says specifically to use space bar only in 3 cases:
https://www.w3.org/TR/2009/WD-wai-aria-practices-20090224/
Checks the radio button with keyboard focus (this is a special case when using tab and no radio buttons have been marked as checked (https://www.w3.org/TR/2009/WD-wai-aria-practices-20090224#kbd_general_ex).
It is recommended that the space bar be used for selection for Drag drop support (https://www.w3.org/TR/2009/WD-wai-aria-practices-20090224#dragdrop)
Checkbox - Space bar toggles checkboxes, if the list items are checkable (https://www.w3.org/TR/2009/WD-wai-aria-practices-20090224#listbox)
The WCAG only mentions a guideline:
"The TAB key moves keyboard focus to the widget, and other keys operate the features of the widget, typically cursor keys, Enter key and Spacebar. The actual keys are up to the developer, but best practices recommend using the same key bindings that are used to control similar widgets in common GUI operating systems like Microsoft Windows®, Apple OSX® and UNIX Desktops like GNOME and GTK."
Frankly its left to the user's interpretation, and based on what you are trying to implement, you would probably have to see the existing behaviour of similar components on popular tools/web sites/ browser behaviour and make a logical decision.

Related

Not able to find the correct accessibility role for list elements

<ul class="draggable-list" role="listbox">
-- list runs in for loop around 5 li elements (all draggable elements)
<li tabindex="0" role="option">
</li>
</ul>
All the drag drop li elements are working fine on mouse click drag and drop. But when I try to use keyboard enter for accessibility.. there is a on key press function which works fine in chrome but fails in IE and Safari.
I have tried role="listitem" but then on enter key press nothing happens on any of the browsers. is there any specific role i can use across browsers for list items which needs to be moved (basically need on key press event to fire, where I am deciding the location to move). I have tried role="application" this works across browser but there some other accessibility issue that come up. Everyone in the team suggested not to use application as a role for list elements (That doesn't seem correct to me as well but thts the only role which has worked on IE and safari safari for key press event)
list item
Note: list item doesn't have any keyboard interactions
Note that specifying a role does not give you any behavior. See "What adding a role does not do"
Adding an ARIA role will not make an element look or act differently for people not using assistive technology. It does not change the behaviours, states and properties of the host element but only the native role semantics.
In other words, changing the role only changes how the screen reader announces the element (the "semantics"). It doesn't cause the element to behave any differently.
Also note that the following in a previous answer is not quite accurate:
"A lot of screen-readers (depending on their user-settings) do not pass key-presses to the browser"
This is not true. Depending on the role of the element, the screen reader (with default settings) can switch between virtual/explorer/browse mode to application/forms mode, thus passing key presses to the browser (and thus to your element). For a list of roles that do this, see "5.1 Fundamental Keyboard Navigation Conventions". Even though that section talks about keyboard navigation and which roles require you to implement arrow key navigation, it essentially tells you which roles will allow key presses to pass through to your element.
So if you want key presses, use one of the roles listed in that section. As a last resort, use role="application".
From my experience, you can never be certain that role="application" will work consistently from time to time.
Roles: role="listitem" is supposed to be used when one or more options are to be selected. What you are describing sounds to me more like a regular list that the user can re-order, and not something like a <select>. If I'm correct, you could consider using a role="list" with role="listitem" for children - and as it happens, that comes for free when using a <ul>, so you can completely skip the role attributes here. You can also keep using the role="listitem", because some screen-readers will let users go item-by-item a little easier. Depends on your needs and preferences.
But addressing the real problem: A lot of screen-readers (depending on their user-settings) do not pass key-presses to the browser, so your onkeypress will not fire. At least not reliably. That's because the screen-reader relies heavily on keyboard shortcuts, and those might differ from user to user. You would not want to overwrite those.
However, when something can be tabbed to, the screen-reader will happily fire an onclick event when the user presses the Enter key.
When grabbing an item, you could consider adding aria-grabbed="true" and aria-dropeffect="move". Both are marked as "Deprecated", as a new method of conveying these are in the works, but I think they are still supported by some major screen-readers, and I have yet to find a proper alternative.
aria-grabbed: https://www.w3.org/TR/wai-aria-1.1/#aria-grabbed
aria-dropeffect: https://www.w3.org/TR/wai-aria-1.1/#aria-dropeffect

Buttons and links keyboard triggers

While doing research I came across this statement:
Warning: Be careful when marking up links with the button role.
Buttons are expected to be triggered using the Space key, while links
are expected to be triggered using the Enter key.
Does anyone know why a different key is used for buttons / links?
Is it ok to trigger using both Space and Enter?
Before reading this I, as a user, would have had no idea when to use Space or Enter.
Had a quick look at Google to see what they do.
For links Space scrolls down and Enter triggers
For buttons both Space and Enter trigger
Buttons are form elements.
If you select a checkbox element, space will toggle the checkbox while enter will submit the form.
So to be coherent, buttons act the same way. In practice, they accept both enter and space without any difference.
It is not only ok but you have to
Read inside the Third rule of ARIA:
For example, if using role=button the element must be able to receive focus and a user must be able to activate the action associated with the element using both the enter (on WIN OS) or return (MAC OS) and the space key.
This is for historical reason, not that it has been defined in any official recommendation, as far as I know
For instance an old bug from 2000 (https://bugzilla.mozilla.org/show_bug.cgi?id=56495) already stated that space bar was expected to work on buttons. Maybe an inheritance from Windows behavior.
I am speculating to answer #1, but I believe the keys used to activate buttons versus hyperlinks are holdovers from operating systems. For hyperlinks, think of Windows Help in Windows 95 and its reliance on in-content links, or Hypercard on the Mac prior to that. Also note that Space has scrolled a page in browsers since (IIRC) day one.
To answer number 2, no it is not OK. This is because a space bar triggers a page scroll and many users expect that when focus is on a hyperlink that pressing Space will just scroll the page.
In short, honor the keyboard mappings that are in place since there are users who rely on them and messing with them can have catastrophic consequences for users of assistive tech along with users with disabilities who do not use assistive tech.
Let me re-state what you saw at Mozilla:
A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful.
And then let me add this:
I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).
Source: Links, Buttons, Submits, and Divs, Oh Hell.

Is it more accessible to use a <button> or <a> to open/close a modal? [duplicate]

This question already has an answer here:
Why are buttons discouraged from navigation?
(1 answer)
Closed last year.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
From my understanding, buttons are used to carry out functions and links are used to navigate the user to a different page. But what is best practice in terms of opening and closing a modal?
<a id="testModal" href="#">Open Modal</a>
or
<button id="testModal">Open Modal</button>
<button>
Change the <a href="#"> to a <button> and put your event handler on it.
Some more context on which elements belongs where....
Does the Control Take Me to Another Page? Use an Anchor
If, when clicked, tapped, or activated by keyboard or voice (or insert novel interaction method here), the user is whisked to another URL (including an anchor on the same page), then use <a href="[URL]">. Make sure you use the href attribute and that it has a real URL, not a “#” (otherwise you’re probably relying on JavaScript, which is not at all necessary for a hyperlink). If an href points to just a “#”, then you’re probably doing it wrong. If it points to a named anchor as part of your progressive enhancement efforts, then that’s totally valid.
Does the Control Change Something on the Current Page? Use a Button
If, when activated, the user is not moved from the page (or to an anchor within the page), but instead is presented with a new view (message boxes, changes in layout, etc.), then use a <button>. While you could use an<input type="button">, it’s more likely you’ll get into conflicts with pre-existing styles and subsequent developers (like me).
Does the Control Submit Form Fields? Use a Submit
If, when activated, information the user has entered (either by manually typing or by choosing items on the screen) is being sent back to the server, then use an <input type="submit">. This has better live within a <form>. If you need more styling control or have to embed more than just a simple text string, use a <button type="submit"> instead.
Keyboard Considerations
Think of keyboard users for a moment. A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. If there isn’t more to scroll then the user just experiences nothing. Given a set of interface elements that look the same, if some work with a space bar and some don’t, you can’t expect users to have much confidence in how the page behaves.
I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).
I think there are two possible cases.
Your content is only visually hidden in page or visible in page (can be read by screen readers) and can be hash linked, then an anchor tag might be appropriate (this case is not so common, eg: use case is if you are highlighting a paragraph or image on the page as a modal).
In almost all other cases, your modal is loaded on the same page and is in no way navigated using a url link (except through ajax for accessing data possibly, which doesn't count). Hence it is a custom functionality and a button is the appropriate choice.
Sort of by definition, a dialog is something that will pop up over the current window. You're not really leaving the window, it's just temporarily unavailable. Once you're done with the dialog, you typically go back to the window. So in that respect, you don't want to use a link because you're not going to another page. You're doing some action on the current page. Use a button.
When using a screen reader, I will often bring up the list of links (Ins+F7 in JAWS) to see what pages I can link to. I'll also bring up a list of buttons (Ctrl+Ins+B) to see what actions are available on the page. I would expect the action to bring up a modal dialog to be in my button list.

Is an empty element (such as <a href="#">) valid for accessibility purposes?

I manage several websites that use a featured article scroller on their homepages, which allows the user to click a forward or back arrow in order to see the next article headline and blurb while remaining on the same page.
I use WAVE's accessibility checker and any sites that have this particular plugin throw an error back because within the code there is an empty link, written as <a href="#">. Is there any way around this? I've defined a title attribute but the # is causing the empty link error to still come up.
Some places I've seen that this is perfectly acceptable and others claim this is a problem. What's the actual answer and potential workaround?
Change the <a href="#"> to a <button> and put your event handler on it.
Some more context on which elements belongs where....
Does the Control Take Me to Another Page? Use an Anchor
If, when clicked, tapped, or activated by keyboard or voice (or insert novel interaction method here), the user is whisked to another URL (including an anchor on the same page), then use <a href="[URL]">. Make sure you use the href attribute and that it has a real URL, not a “#” (otherwise you’re probably relying on JavaScript, which is not at all necessary for a hyperlink). If an href points to just a “#”, then you’re probably doing it wrong. If it points to a named anchor as part of your progressive enhancement efforts, then that’s totally valid.
Does the Control Change Something on the Current Page? Use a Button
If, when activated, the user is not moved from the page (or to an anchor within the page), but instead is presented with a new view (message boxes, changes in layout, etc.), then use a <button>. While you could use an<input type="button">, it’s more likely you’ll get into conflicts with pre-existing styles and subsequent developers (like me).
Does the Control Submit Form Fields? Use a Submit
If, when activated, information the user has entered (either by manually typing or by choosing items on the screen) is being sent back to the server, then use an <input type="submit">. This has better live within a <form>. If you need more styling control or have to embed more than just a simple text string, use a <button type="submit"> instead.
Keyboard Considerations
Think of keyboard users for a moment. A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. If there isn’t more to scroll then the user just experiences nothing. Given a set of interface elements that look the same, if some work with a space bar and some don’t, you can’t expect users to have much confidence in how the page behaves.
I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).
Some source suggests that link would be an invalid hypertext reference, but in fact the problem would exist only in non javascript browsers which is out of the scope of WCAG 2. This is not your problem here as this is not an error that WAVE considers.
The problem here is the fact that you have an empty link content and that adding a title attribute does not satisfy WAVE algorithm.
If your only concern is to satisfy WAVE, just put some content in the link and use any CSS trick to hide this content.

Conflicts between JAWS table navigation short keys and custom implemented navigation keys(i.e. arrow keys)

Conflicts between JAWS table navigation short keys and custom implemented navigation keys(i.e. arrow keys)
I am trying to make an HTML table accessible using keyboard as well as readable using JAWS Screen reader.
To make it keyboard accessible i am doing following things:
- Added keypress events on table cells for arrow keys (left, right, top, bottom)
To make it JAWS readable i am doing following things:
- Added caption,summary to table
- Added scope=col to table headers
- Added ARIA roles like Application, row, grid, gridcell
Keyboard navigation is working fine when the page is run without using JAWS.
JAWS also read the table fine provided JAWS shortcuts are used.
When it is run with JAWS custom implemented keyboard navigation does not work properly.
To move focus to different cell using custom implemented keyboard navigation (i.e. arrow keys), i have use INSERT + 3 key followed by an arrow key.
This will move focus to different cell but it will not change JAWS current cell focus. So when JAWS read, it will read the cell other than the actual focused cell.
Example page URL : http://test.cita.illinois.edu/aria/grid/grid1.php
The above page supports custom keyboard navigation(i.e. arrow keys). Try to read above page using JAWS.
Please help to make it keyboard accessible at the same time readable by JAWS.
Appreciate your help!
Thanks a lot for your quick reply! That was very good information you provided.
However I have few more queries regarding this. It would be great if you could help.
JAWS provides support for various cursors like Virtual PC Cursor, PC Cursor, JAWS Cursor.
As per my knowledge when we specify role="application", JAWS runs on PC Cursor and whatever functionality provided in website are usable using the provided keystrokes.
The functionality i want to achieve especially with HTML Table is, user should be able to navigate using arrow keys as well as JAWS should read the currently focused content.
So the doubt here is why JAWS does not readout currently focused content in in PC Cursor.(in html table it can be currently focused cell).
It would be helpful if you could explain, how the JAWS user ideally uses web sites using JAWS (specifically with information rendered in HTML Table).
I have a complex table having following features and would like it to be accessible by keyboard and readable by JAWS:
Table with expand/collapse icon. Clicking on Expand/Collapse icon or pressing +/- from keyboard the nested table should be visible to user.
Each row of table is having some action items and pressing a key or clicking on it should perform an action. (like each row shows unique product information and user can buy(action item) by pressing some key or clicking on a button. )
I tried using dojo grid and it provides to navigate using keyboard arrow keys and there is a JAWS shortcut to readout the currently focused cell i.e INSERT + UP Arrow.
Try adding role="application" to the table or a surrounding element.
There is no way I know of to do what you want. I'm a Jaws user and the table is fine as is. I would not use your site if your custom navigation keys overrode Jaws defaults. The issue with overriding the defaults is it eliminates the ability to review character by character. If I wanted to check the spelling of a word in the table cell I could read letter by letter with the arrow keys. Disabling this ability of jaws is unacceptable. The reason I do not believe it is possible to do what you want is because Jaws uses a virtual buffer with information obtained from the internet browser to format the page in a way easier to read with a screen reader. In my experience it's murky where the boundary between the browser and Jaws is. This means that you probably cannot capture jaws specific keystrokes before Jaws does. Using the insert+3 key followed by an arrow key will not work with jaws because the key is being passed to the browser. This means the table focus is changing in the browser but there is no way to force that change in the model of the page Jaws uses.