No keyboard shortcut uses only printable characters

  • Rule Type:atomic
  • Rule Id: ffbc54
  • Last modified: Oct 15, 2020
  • Accessibility Requirements Mapping:
    • 2.1.4 Character Key Shortcuts (Level A)
      • Learn More about 2.1.4 Character Key Shortcuts
      • Required for conformance to WCAG 2.1 on level A and higher.
      • Outcome mapping:
        • Any failed outcomes: success criterion is not satisfied.
        • All passed outcomes: success criterion is satisfied.
        • An inapplicable outcome: success criterion needs further testing.
  • Input Aspects:

Description

This rule checks that if keyboard shortcuts are implemented using only printable characters, then there is a mechanism to disable the shortcut, or to remap the shortcut to use one or more non-printable character keys, or the shortcut for a user interface component is only available when that component has focus.

Applicability

The rule applies to any keyboard event for which all of the following is true:

Expectation

For each test target at least one of the following is true:

Assumptions

  • If there are ways to disable the result of keyboard events that do not require the user to interact with the web page (e.g. a setting at the operating system level), failing this rule might not be a failure of the success criterion.
  • After being disabled, the event remains disabled until being re-enabled again. If the event is re-enabled through other non-user controlled means (e.g. a timeout) then this rule may pass while Success Criterion 2.1.4: Character Key Shortcuts is not satisfied.

Accessibility Support

Currently keyboard events only support the types keydown and keyup. Keyboard events of type keypressed are considered legacy keyboard events and are thus ignored by this rule.

Background

Test Cases

Passed

Passed Example 1

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There exists an instrument to remap the keyboard event so that same key events are blocked unless getModifierState("Control") returns true.

<html>
	<head>
		<title>Passed Example 1</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body onload="registerShortcut({id: 'singleShortcut', shortcutKey: '+'}); activateShortcuts();">
		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<div>
			<div>Remap shortcut</div>
			<div>
				<label>
					<input id="remap" type="checkbox" onclick="toggleModifier('singleShortcut', this.checked)" />
					Use "ctrl" key together with the "+" key
				</label>
			</div>
		</div>
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Passed Example 2

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There exists an instrument to disable the keyboard event. A disabled event implies that the event is disabled when the getModifierState method returns false, therefore meeting the remap expectation.

<html>
	<head>
		<title>Passed Example 2</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body onload="registerShortcut({id: 'singleShortcut', shortcutKey: '+'}); activateShortcuts();">
		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<label>
			<input type="checkbox" onclick="toggleDisabled('singleShortcut', !this.checked)" checked />
			Toggle single character keyboard shortcut
		</label>
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Passed Example 3

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. For each keyboard event causing changes in content, there exists an instrument to remap it so that same key events are blocked unless getModifierState("Control") returns true.

<html>
	<head>
		<title>Passed Example 3</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body
		onload="registerShortcut({id: 'firstShortcut', shortcutKey: '+'}); registerShortcut({id: 'secondShortcut', shortcutKey: 'a'}); activateShortcuts();"
	>
		<label for="target">Add to list (press "+" or "a" to add):</label>
		<input type="text" id="target" />
		<div>
			<div>Remap shortcut</div>
			<div>
				<label>
					<input id="remap1" type="checkbox" onclick="toggleModifier('firstShortcut', this.checked)" />
					Use "ctrl" key together with the "+" key
				</label>
				<label>
					<input id="remap2" type="checkbox" onclick="toggleModifier('secondShortcut', this.checked)" />
					Use "ctrl" key together with the "a" key
				</label>
			</div>
		</div>
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Passed Example 4

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There exists an instrument to remap those keyboard events that cause changes in content so that same key events are blocked unless getModifierState("Control") returns true. In this example, the same instrument is used to remap all keyboard events.

<html>
	<head>
		<title>Passed Example 4</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body
		onload="registerShortcut({id: 'firstShortcut', shortcutKey: '+'}); registerShortcut({id: 'secondShortcut', shortcutKey: 'a'}); activateShortcuts();"
	>
		<label for="target">Add to list (press "+" or "a" to add):</label>
		<input type="text" id="target" />
		<div>
			<div>Remap shortcut</div>
			<div>
				<label>
					<input
						id="remap"
						type="checkbox"
						onclick="toggleModifier('firstShortcut', this.checked); toggleModifier('secondShortcut', this.checked);"
					/>
					Use "ctrl" key together with the "+" or "a" key
				</label>
			</div>
		</div>
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Passed Example 5

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content, but the events are blocked when no widget has focus.

<html>
	<head>
		<title>Passed Example 5</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>

	<body onload="registerShortcut({shortcutKey: '+', focusOnly: true}); activateShortcuts();">
		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Passed Example 6

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There exists a set of clearly labeled instruments to disable the keyboard event or to remap the keyboard event so that same key events are blocked unless getModifierState("Control") returns true.

<html>
	<head>
		<title>Passed Example 6</title>
		<link rel="stylesheet" type="text/css" href="/test-assets/ffbc54/styles.css" />
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body onload="registerShortcut({id: 'singleShortcut', shortcutKey: '+'}); activateShortcuts();">
		<div id="overlay">
			<p>Disable/remap shortcut</p>
			<label>
				<input type="checkbox" onclick="toggleDisabled('singleShortcut', !this.checked)" checked />
				Toggle single character keyboard shortcut
			</label>
			<br />
			<label>
				<input id="remap" type="checkbox" onclick="toggleModifier('singleShortcut', this.checked)" />
				Use "ctrl" key together with the "+" key
			</label>
			<br />
			<button onclick="closeModal();">Dismiss</button>
		</div>
		<p>To control the shortcuts activate the "Control shortcuts" button.</p>
		<input type="button" onclick="openModal()" value="Control shortcuts" />

		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Failed

Failed Example 1

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There is no instrument to remap the keyboard event and the keyboard events are not blocked when no widget has focus.

<html>
	<head>
		<title>Failed Example 1</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body onload="registerShortcut({shortcutKey: '+', disabled: false}); activateShortcuts();">
		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Failed Example 2

Open in a new tab

This HTML document is listening to keyboard events for which the attribute key is a printable character and the method getModifierState returns false, and which cause changes in content. There is an instrument to remap the keyboard event so that same key events are blocked unless getModifierState("Control") returns true, but the instrument is not in a clearly labeled location.

<html>
	<head>
		<title>Failed Example 2</title>
		<link rel="stylesheet" type="text/css" href="/test-assets/ffbc54/styles.css" />
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>
	<body onload="registerShortcut({id: 'singleShortcut', shortcutKey: '+'}); activateShortcuts();">
		<div id="overlay">
			<p>Disable/remap shortcut</p>
			<label>
				<input type="checkbox" onclick="toggleDisabled('singleShortcut', !this.checked)" checked />
				Toggle single character keyboard shortcut
			</label>
			<br />
			<label>
				<input id="remap" type="checkbox" onclick="toggleModifier('singleShortcut', this.checked)" />
				Use "ctrl" key together with the "+" key
			</label>
			<br />
			<button onclick="closeModal();">Dismiss</button>
		</div>

		<input type="button" onclick="openModal()" value="Open modal" />

		<label for="target">Add to list (press "+" to add):</label>
		<input type="text" id="target" />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Inapplicable

Inapplicable Example 1

Open in a new tab

This HTML document has a keyboard event dispatched to an event target but it only causes changes in content if the event's attribute key is not a printable character (in this example, the Escape key).

<html>
	<head>
		<title>Inapplicable Example 1</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>

	<body onload="registerShortcut({shortcutKey: 'Escape'}); activateShortcuts();">
		<label for="target">Add to list (press "esc" to add):</label>
		<input type="text" id="target" />
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Inapplicable Example 2

Open in a new tab

This HTML document has a keyboard event dispatched to an event target with the attribute key being a printable character but it does not cause changes in content unless the getModifierState returns true.

<html>
	<head>
		<title>Inapplicable Example 2</title>
		<script src="/test-assets/ffbc54/shortcut.js"></script>
	</head>

	<body onload="registerShortcut({shortcutKey: '+', ctrlKey: true}); activateShortcuts();">
		<label for="target">Add to list (press "ctrl" and "+" to add):</label>
		<input type="text" id="target" />
		<br />
		<div>
			To do list
		</div>
		<ul id="list"></ul>
	</body>
</html>

Glossary

Changes in content

A event originated change in the content of a web page occurs when, by comparing the web page before and 1 minute after the event firing, at least one of the following occurs:

  • visible changes: the rendered pixels change in any part of the document that is currently within the viewport or that can be brought into the viewport via scrolling; or
  • accessibility tree changes: any state, property or event of a node representing an accessible object of the accessibility tree changes, or any node is inserted in, or removed from the accessibility tree; or
  • audible changes: the audio rendered by the web page changes.
  • If the web page is rendering time-based media, rendered pixels and audio will be changing as part of the playback. The comparison in this instance should compare the pixels and audio that are rendered if the event is not fired, with the ones that are rendered if the event is fired.

Assumptions:

  • This definition assumes that there are no changes in the content of the web page caused by another event. If this is not the case, changes may be attributed to the wrong event.
  • This definition assumes that the changes happen within a 1 minute time span after the event firing and therefore the comparison between the page before and after the event firing can be made at any time after that time span elapses. If there are changes after this time span, this definition may not detect them. The arbitrary 1 minute time span, selected so that testing this rule would not be impractical, is not included in WCAG.

Clearly labeled location

Secondary information and alternative controls of functionality are often not displayed together with primary information or functionality. For example, an option to change a web page to dark mode may be placed on an options page instead of being available on every page and page state of a website. Another example is a maps application, where, instead of using GPS, an option is available in a dropdown menu to set the current location of the device. Such content should be placed in a clearly labeled location.

The location of a target is said to be clearly labeled when the target can be found by activating "identifiable" instruments which either lead the user to find the target, or to another page or page state from which this action can be repeated until the target is found.

Whether or not the content is "clearly labeled" depends on the starting point of the search. If page A has a link which clearly "identifies" some piece of content, then the location of the content is clearly labeled. Page B, which can be in the same website, may not have such a link or may have a link with a link text that does not "identify" target content or which can be interpreted to "identify" more than one target, and so the location of the content starting from page B is not clearly labeled.

For the purpose of this definition, an instrument is identifiable if any text or other content with a text alternative, allows any user to identify an element with a semantic role that inherits from widget.

A web page changes state when the document's body changes without a change in the document's URL.

Explicit Semantic Role

The explicit semantic role of an element is determined by its role attribute (if any).

The role attribute takes a list of tokens. The explicit semantic role is the first valid role in this list. The valid roles are all non-abstract roles from WAI-ARIA Specifications. If the element has no role attribute, or if it has one with no valid role, then this element has no explicit semantic role.

Other roles may be added as they become available. Not all roles will be supported in all assistive technologies. Testers are encouraged to adjust which roles are allowed according to the accessibility support base line. For the purposes of executing test cases in all rules, it should be assumed that all roles are supported by assistive technologies so that none of the roles fail due to lack of accessibility support.

Accessibility Support for Explicit Semantic Role

Some browsers and assistive technologies treat the tokens of the role attribute as case-sensitive. Unless lowercase letters are used for the value of the role attribute, not all user agents will be able to interpret the tokens correctly. ARIA in HTML (working draft) also specifies that authors must use lowercase letters for the role and aria-* attributes.

Hidden State

An HTML element's hidden state is "true" if at least one of the following is true for itself or any of its ancestors in the flat tree:

  • has a hidden attribute; or
  • has a computed CSS property display of none; or
  • has a computed CSS property visibility of hidden; or
  • has an aria-hidden attribute set to true

In any other case, the element's hidden state is "false".

Implicit Semantic Role

The implicit semantic role of an element is a pre-defined value given by the host language which depends on the element and its ancestors.

Implicit roles for HTML and SVG, are documented in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).

Accessibility Support for Implicit Semantic Role

  • Images with an empty alt attribute should have an implicit role of presentation, according to the HTML Accessibility API Mapping (work in progress). However, there are several popular browsers that do not treat images with empty alt attribute as having a role of presentation. Instead, they add the img element to the accessibility tree with a role of either img or graphic.

Included in the accessibility tree

Elements included in the accessibility tree of platform specific accessibility APIs. Elements in the accessibility tree are exposed to assistive technologies, allowing users to interact with the elements in a way that meet the requirements of the individual user.

The general rules for when elements are included in the accessibility tree are defined in the core accessibility API mappings. For native markup languages, such as HTML and SVG, additional rules for when elements are included in the accessibility tree can be found in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).

For more details, see examples of included in the accessibility tree.

Note: Users of assistive technologies might still be able to interact with elements that are not included in the accessibility tree. An example of this is a focusable element with an aria-hidden attribute with a value of true. Such an element could still be interacted using sequential keyboard navigation regardless of the assistive technologies used, even though the element would not be included in the accessibility tree.

Marked as decorative

An element is marked as decorative if one of the following conditions is true:

  • it has an explicit role of none or presentation; or
  • it is an img element with an alt attribute whose value is the empty string (alt=""), and with no explicit role.

Elements are marked as decorative as a way to convey the intention of the author that they are pure decoration. It is different from the element actually being pure decoration as authors may make mistakes. It is different from the element being effectively ignored by assistive technologies as rules such as presentational roles conflict resolution may overwrite this intention.

Elements can also be ignored by assistive technologies if their hidden state is true. This is different from marking the element as decorative and does not convey the same intention. Notably, the hidden state of an element may change as users interact with the page (showing and hiding elements) while being marked as decorative should stay the same through all states of the page.

Outcome

An outcome is a conclusion that comes from evaluating an ACT Rule on a test subject or one of its constituent test target. An outcome can be one of the three following types:

  • Inapplicable: No part of the test subject matches the applicability
  • Passed: A test target meets all expectations
  • Failed: A test target does not meet all expectations

Note: A rule has one passed or failed outcome for every test target. When there are no test targets the rule has one inapplicable outcome. This means that each test subject will have one or more outcomes.

Note: Implementations using the EARL10-Schema can express the outcome with the outcome property. In addition to passed, failed and inapplicable, EARL 1.0 also defined an incomplete outcome. While this cannot be the outcome of an ACT Rule when applied in its entirety, it often happens that rules are only partially evaluated. For example, when applicability was automated, but the expectations have to be evaluated manually. Such "interim" results can be expressed with the incomplete outcome.

Printable characters

A printable character is a character that occupies a printing position on a display.

These characters correspond to the following Unicode categories:

  • Letter: 'LC', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu'
  • Number: 'Nd', 'Nl', 'No'
  • Mark: 'Mc', 'Me', 'Mn'
  • Punctuation: 'Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po', 'Ps'
  • Symbol: 'Sc', 'Sk', 'Sm', 'So'
  • Space: 'Zs'

Same key events

Two keyboard events are same key events if they have the same value for all the following attributes:

  • key
  • code
  • location
  • repeat
  • isComposing

Semantic Role

The semantic role of an element is determined by the first of these cases that applies:

  1. Conflict If the element is marked as decorative, but the element is included in the accessibility tree; or would be included in the accessibility tree when its hidden state is false, then its semantic role is its implicit role.
  2. Explicit If the element has an explicit role, then its semantic role is its explicit role.
  3. Implicit The semantic role of the element is its implicit role.

Accessibility Support for Definition of Semantic Role for Semantic Role

  • There exist popular web browsers and assistive technologies which do not correctly implement Presentational Roles Conflict Resolution. These technologies will not include in the accessibility tree elements that should be, according to Specifications. Thus, some elements that should have their semantic role fixed by case Conflict above are instead falling into case Explicit and are hidden for users of assistive technologies.
  • A similar conflict exists for focusable elements with a aria-hidden="true" attribute. The WAI ARIA specification does not explain how to solve it. Some browsers give precedence to the element being focusable (and expose it in the accessibility tree) while some give precedence to the aria-hidden attribute (and hide the element).

Web page (HTML)

An HTML web page is the set of all fully active documents which share the same top-level browsing context.

Note: Nesting of browsing context mostly happens with iframe and object. Thus a web page will most of the time be a "top-level" document and all its iframe and object (recursively).

Note: Web pages as defined by WCAG are not restricted to the HTML technology but can also include, e.g., PDF or DOCX documents.

Note: Although web pages as defined here are sets of documents (and do not contain other kind of nodes), one can abusively write that any node is "in a web page" if it is a shadow-including descendant of a document that is part of that web page.


Useful Links


Implementations

This section is not part of the official rule. It is populated dynamically and not accounted for in the change history or the last modified date. This section will not be included in the rule when it is published on the W3C website.

No Implementations

Implementation reports are not provided for this rule.

Acknowledgments

Table of Contents