third_party/aria-practices/src/content/patterns/toolbar/examples/toolbar.html
The following example of an editor toolbar implements the Toolbar Pattern and demonstrates how a toolbar can group a set of interactive widgets into a single tab stop. For illustrative and interoperability assessment purposes, this implementation includes a diverse set of widgets, some of which may not be ordinarily grouped in the same toolbar. For instance, it includes both a checkbox and toggle buttons. In a typical implementation, the design would use either one or the other but not both. Similarly, the edit field is included to help simulate actual implementation and is not intended to represent an actual rich text editor. This example also illustrates the practice of Managing Focus Within Components Using a Roving tabindex.
BoldItalicUnderline
Text Align LeftText Align CenterText Align Right
CopyPasteCut
SANS-SERIF
14pt
Night ModeHelp
Text Sample
Abraham Lincoln's Gettysburg Address Four score and seven years ago our fathers brought forth on this continent a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation, so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow, this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us, that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion, that we here highly resolve that these dead shall not have died in vain, that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.
The bold, italic, underline, and text align buttons have popup labels that implement the requirements of WCAG Success Criterion 1.4.13 Content on Hover or Focus:
The toolbar provides the following keyboard support described in the toolbar pattern.
| Key | Function |
|---|---|
| Tab |
| | Right Arrow |
| | Left Arrow |
| | Home | Moves focus to the first control. | | End | Moves focus to the last control. | | ESC | If a button popup label is visible, hides it. |
The toggle buttons for choosing to apply Bold , Italic, and Underline styling provide the following keyboard support described in the Button Pattern.
| Key | Function |
|---|---|
| Enter | |
| Space | Toggle the pressed state of the button. |
The buttons for choosing left, center, or right text alignment are styled like toggle buttons. However, since pressing one toggles off another so that only one button in the group is in the pressed state, the toggles behave like radio buttons. Because ARIA is designed to inform assistive technologies about UI semantics and behaviors, not styling, the alignment toggles provide the following keyboard support described in the Radio Group Pattern. As described in the pattern, nesting a radio group in a toolbar calls for an important behavioral difference compared to radios outside a toolbar: moving focus inside the group does not automatically change which button is checked. In addition, because Left Arrow and Right Arrow are needed by the parent toolbar, they are not captured by the radio group. The toolbar thus provides navigation into, inside, and out of the nested radio group.
| Key | Function |
|---|---|
| Enter | |
| Space |
| | Down Arrow |
| | Up Arrow |
|
The buttons for cut, copy, and paste provide the following keyboard support described in the Button Pattern. While they are HTML button elements, as described in the accessibility features section above, in order to remain focusable when disabled, they have aria-disabled instead of the HTML disabled attribute.
| Key | Function |
|---|---|
| Enter | |
| Space | If the button is enabled, execute the action associated with the button. Otherwise, do nothing. |
The menu button for opening the font family menu provides the following keyboard support described in the Menu Button Pattern.
| Key | Function |
|---|---|
| Enter | |
| Space | |
| Down Arrow | |
| Up Arrow | Open the menu and place focus on a menu item. In this implementation, the focus is set on the currently selected font family when the menu opens. |
The menu for choosing a font family provides the following keyboard support described in the Menu and Menubar Pattern.
| Key | Function |
|---|---|
| Enter | |
| Space | Activate the menu item, close the menu, and place focus on the menu button. |
| Down Arrow |
| | Up Arrow |
| | ESC | Closes the menu and moves focus to the menu button. |
The spin button for changing font size provides the following keyboard support described in the Spin Button Pattern.
| Key | Function |
|---|---|
| Down Arrow | Decreases the font size of the text in the textarea by 1 point. |
| Up Arrow | Increases the font size of the text in the textarea by 1 point. |
| Page Down | Decreases the font size of the text in the textarea by 5 points. |
| Page Up | Increases the font size of the text in the textarea by 5 points. |
The checkbox for toggling night mode provides the following keyboard support defined in the Checkbox Pattern. As an HTML input element, the browser provides the keyboard support.
| Key | Function |
|---|---|
| Space | Toggles the state of the checkbox. |
The link for opening a help page provides the following keyboard support described in the Link Pattern. As an HTML link, the keyboard support is provided by the browser.
| Key | Function |
|---|---|
| Enter | |
| Space | Activate the link. |
The toolbar implements the following ARIA attributes described in the Toolbar Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
toolbar | div |
toolbar.|
| | aria-label="Text Formatting" | div | Provides the toolbar with an accessible name of "Text Formatting". |
| | aria-controls="IDREF" | div | Set to a value that references the text area, indicating the toolbar controls the text area. |
| | tabindex="-1" | button, div, input[type="checkbox"], a |
|
| | tabindex="0" | button, div, input[type="checkbox"], a |
|
The toggle buttons for choosing to apply Bold , Italic, and Underline styling implement the following ARIA attributes described in the Button Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-pressed="true" | button | Indicates the button is a toggle and that the styling controlled by the button has been applied. | |
aria-pressed=false | button | Indicates the button is a toggle and that the styling controlled by the button has NOT been applied. | |
aria-hidden="true" | span | Hides the icon character from being included in the accessible name. |
The buttons for choosing left, center, or right text alignment are styled like toggle buttons. However, since pressing one toggles off another so that only one button in the group is in the pressed state, the toggles behave like radio buttons. Because ARIA is designed to inform assistive technologies about UI semantics and behavior, not styling, the alignment toggles implement the following ARIA attributes described in the Radio Group Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
radiogroup | div | Identifies the div element as a container for group of radio buttons. | |
aria-label="Text Alignment" | div | Defines the accessible name for the group of radio buttons as "Text Alignment". | |
radio | button |
button element as a radio button.button element.|
| | aria-checked="true" | button |
aria-checked set to true at any given time.|
| | aria-checked="false" | button |
aria-checked set to false.|
| | aria-hidden="true" | span | Hides the icon character from being included in the accessible name. |
The buttons for cut, copy, and paste implement the following ARIA attributes described in the Button Pattern. While they are HTML button elements, as described in the accessibility features section above, in order to remain focusable when disabled, they have aria-disabled instead of the HTML disabled attribute.
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-disabled="true" | button | Set when the button is disable to inform assistive technologies of the disabled state. | |
aria-disabled="false" | button | Set when the function provided by the button is available. |
The menu button for opening the font family menu implements the following ARIA attributes described in the Menu Button Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
aria-label="Font: FONT_FAMILY_NAME" | button |
|
| | aria-haspopup="true" | button |
button opens a menu.menubutton, most platform accessibility APIs have a menubutton role. On those platforms, assistive technologies identify buttons with aria-haspopup set to either true or menu as menu buttons.|
| | aria-controls="IDREF" | button |
menu.|
| | aria-expanded="false" | button | Indicates the menu is not displayed and that activating the menu button opens the menu. |
| | aria-expanded="true" | button | Indicates the menu is displayed and that activating the menu button closes the menu. |
The menu for choosing a font family implements the following ARIA attributes described in the Menu and Menubar Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
menu | ul | Identifies the ul element as a menu. | |
aria-label="Font Family" | ul | Defines the accessible name for the menu as "Font Family". | |
menuitemradio | li |
li element as a menuitemradio.li element provides the accessible name of the menuitemradio.|
| | aria-checked="true" | li |
menuitemradio to indicate the item is checked, informing users which font is applied to the text area.|
| | aria-checked="false" | li |
menuitemradio to indicate the items are NOT checked.|
| | tabindex="-1" | li |
menuitemradio element focusable so DOM focus can be set on the menu item.|
The spin button for changing font size implements the following ARIA attributes described in the Spin Button Pattern.
| Role | Attribute | Element | Usage |
|---|---|---|---|
spinbutton | div | Identifies the div element as a spinbutton. | |
aria-label="Font size in points" | div | Defines the accessible name for the spin button as "Font size in points". | |
aria-valuenow="NUMBER_POINTS" | div |
|
| | aria-valuetext="NUMBER_POINTS Points" | div |
NUMBER_POINTS is updated by JavaScript as the user adjusts the value of the spin button.|
| | aria-valuemin="8" | div | Indicates the minimum allowed value for the spin button, i.e., smallest supported font size. |
| | aria-valuemax="40" | div | Indicates the maximum allowed value for the spin button, i.e., largest supported font size. |
To copy the following HTML code, please open it in CodePen.