5๏ธโƒฃCreating custom ARIA widgets

In this chapter, we will explore how to make custom components accessible and user-friendly for everyone using ARIA with the assistance of Flowy.

We will begin by demonstrating how to use Flowy on simple components and then proceed to complex components.

Simple Components

These components are "simple" in that they typically serve a single, specific function and are easy to understand and integrate.

Introduction

A button element is typically used to trigger an action when activated by a user. Think of a button as a remote for doing cool stuff but cool stuff on a website.

Best Practices for Accessible Buttons:

  1. Use a button for triggering actions such as submitting a form, opening a dialog, canceling an action, showing and hiding elements, inserting new information,or displaying information.

  2. Adding role="button" to an element informs assistive technologies to treat the element as a button.

  3. Keyboard support (enter and space keypress) must be provided especially when used on generic elements such as divs or spans.

  4. Ensure to add tabindex="0" on generic elements that have the role="button" so that they can receive keyboard focus and also appear in the tab order.

  5. Elements with role="button" must have labels to identify them. This helps users who rely on assistive technologies to understand the purpose of the button:

  6. Use aria-label to provide accessible labels to a button element or elements with role="button"

How to Fix with Flowy

  1. Determine the elements in your web page that will require to perform specific actions such as such as submitting forms, triggering navigation, triggering hidden content, initiating downloads, or executing JavaScript functions.

  2. Identify the appropriate elements for which you want to enable 'button' functionalities.

  3. Click on the Elements tool and select element.

  4. Select the CSS selectors that will represent the <button> elements for your web page

  5. Choose the attribute <button>, click rock and roll and thatโ€™s it.

Sample Code Implementing Button Element Using ARIA


<!-- Using aria-label on button or elements with role="button"--> 
<button type="button" aria-label="Add to Cart"></button>
<div role="button" tabindex="0" aria-label="Close"> X </div>
<span role="button" tabindex="0" aria-label="Save User Interface"> Save UI </span>

Introduction

The figure role attribute can be utilized in situations where an image, illustration, or diagram has a caption represented by a 'p', 'span', or 'div' element.

Think of it like a label that informs assistive technology that โ€˜Hey this is a diagram or picture that includes a short description for the image so that users can understand what it represents.

Best Accessibility Practices for using role="figure"

  1. Using role="figure" informs assistive technologies to treat an element as a figure element.

  2. Use ARIA role="figure" when providing short descriptions of images, illustrations, diagrams, audio, code snippets, video, or other multimedia elements.

  3. Use an aria-label when there is no visible text caption.

  4. Use an aria-labelledby when there is a visible text caption.

  5. Use aria-describedby when the present text has a longer description

How to Fix with Flowy

  1. Determine the multimedia (images, code snippets, or diagrams) elements on your web page that need to be grouped together to associate related pieces of information clearly.

  2. Identify the appropriate elements for which you want to implement role="figure"

  3. Click on the Elements tool and select element.

  4. Select the CSS selectors that will represent the ARIA "figure" role.

  5. Choose the "role" and the "figure" attribute for your selected element(s)

  6. Provide an accessible name or description depending on your use case. Use an aria-label when there is no visible text caption. Use aria-labelledby when there is a visible text caption. Use aria-describedby when the present text has a longer description.

  7. Click rock and roll and thatโ€™s it!

Sample code for creating a figure element with ARIA

<!-- ARIA figure using aria-label -->
<div role="figure" aria-label="Planet earth known to support life "> <img src="earth.jpg" alt="A satelite view of Earth">
</div>
<!-- ARIA figure using aria-labelledby -->
<div role="figure" aria-labelledby="figure1">
<img src="earth.jpg" alt="A satelite view of Earth">
<p id="figure1">Planet earth known to support life </p> </div>
<!-- ARIA figure using aria-describedby -->
<div role="figure" aria-labelledby="">
<img src="earth.jpg" alt="A satellite view of Earth">
surface is
<p id="figure1">Planet Earth known to support life. It's divided into seven continents: Asia, Africa, North America, South America, Antarctica, Europe, and Australia</p>
</div>

Complex Components

These are components involve multiple functionalities, states, or even nested components. These are designed to handle more complex interactions

A combobox is a component/widget that allows users to select a value from a predefined set list of options presented in a dropdown list or popup item. Imagine a combobox as a magical box that lets you choose something from a bunch of cool options.

A combobox can take the form of a widget that supports editing or typing, or it can be in the form of a widget that only displays content. A common component is the calender or datepicker.

Best Accessibility Practices for using role="combobox"

  1. Using role="combobox" informs assistive technologies to treat an element as a combobox.

  2. The element with the role "combobox" must have the โ€˜aria-controlsโ€™ attribute to communicate to assistive technologies the relationship between the combobox and the popup element

  3. The element with the role "combobox" must have an " aria-expanded" attribute to communicate to assistive technologies the shown and hidden states of the popup elements.

  4. Tabindex (tabindex=โ€0โ€) must be implemented to ensure the elements are focusable and are included in the tab order of your website.

How to Fix with Flowy

  1. Determine the element(s) on your web page that requires a user to select a value from a predefined set list of options presented in a dropdown list or popup item.

  2. Identify the appropriate elements that contain items that users can select a value from a predefined set list of options presented in a dropdown list or popup item.

  3. Click on the Elements tool and select element.

  4. Select the CSS selectors that will represent element(s) with role=โ€comboboxโ€

  5. Choose the 'role' and the โ€˜checkboxโ€™ attribute for your selected element(s).

  6. Choose the 'aria-controls' attribute to match the dropdown list or popup item ID attribute.

  7. Choose the โ€˜aria-expandedโ€™ attribute initially set to false. When the popup/dropdown element is visible, aria-expanded is set to true.

  8. Provide accessible labels(names) with the โ€˜aria-labelโ€™ or โ€˜aria-labelledbyโ€™ attributes so that assistive technologies can understand the purpose of the checkboxes.

  9. Click rock and roll and thatโ€™s it.

Sample Code Snippet for Implementing a Combobox Using ARIA.


<!-- ARIA combobox -->
<input type="text" role=" combobox" aria- expanded="false" aria-autocomplete="list" aria- controls="exl-grid" id="ex1-input">
<div aria-labelledby="cb-label" id="grid"></div>

Introduction

ARIA table is a static table-like structure without interactive features, and its cells are not focusable or selectable.

Best Accessibility Practices for using role=โ€tableโ€.

  1. Using role="table" on an element informs assistive technologies to treat the element as table.

  2. An ARIA table must contain role="rowgroup" to organize or structure the table's content as needed.

  3. An ARIA table must contain role="row" on the container holding the ARIA table cells, column headers, or row headers.

  4. An ARIA table must contain role="columnheader"โ€™. This defines the title or header information for the column.

  5. An ARIA table must contain role="rowheader". This defines the title or header information for the column.

  6. An ARIA table must contain โ€˜role=cellโ€™. This Identifies elements containing content for a single cell.

  7. An accessible label/name can be provided with the 'aria-label' and 'aria-labelledby' attributes.

  8. An ARIA table must have an accessible label/name. This can be provided with the 'aria-label' or 'aria-labelledby' attributes.

  9. In the event a description of an ARIA table is present, use the 'aria-describedby' attribute as a reference to provide a description for the table.

How to Fix with Flowy

  1. Determine the element(s) on your web page that hold any form of data that is presented to users.

  2. Identify the appropriate elements that will comprise all the table elements. This includes rowgroups,rowheader,columnheader, rows and cells.

  3. Click on the Elements tool and select the appropriate elements.

  4. Select the CSS selectors that will: Represent element(s) with role="table".This will be the main container holding all the table contents. Represent element(s) with role="rowgroup" to identify the elements that serve as containers for the table header and table body rows. Represent element(s) with role="row" to identify each element that contains the cells for a row. Represent element(s) with role="columnheader" to Identify elements that serve as a cell(s) containing a column label. Represent element(s) with role="columnheader" Identifies elements containing content for a single cell.

  5. Choose the choose all the ARIA roles and their respective attribute(s) as laid out in step number 4 for your selected element(s)

  6. Provide accessible name or description depending on your use case. Use aria-label when there is no visible text caption. Use aria-labelledby when there is a visible text caption. Use aria-describedby if present to provide a description for the table.

  7. Click rock and roll and thatโ€™s it!

Sample Code Snippet for Creating a Table with ARIA

๏ปฟ

โ–ผ <!-- ARIA Table -->
<div id="table" role="table" aria-label="Table Name" aria- describedby="table_caption">
<div id="table_caption">Table description</div>
<div role="rowgroup">
<div role="row">
<div role="column header">Header 1</div>
<div role="columnheader">Header 2</div>
<div role="column header">Header 3</div> </div>
</div>
<div role="rowgroup">
<div role="row">
<div role="rowheader">Row 1 Header</div> <div role="cell">Row 1 Data 1</div>
<div role="cell">Row 1 Data 2</div> </div>
</div>
</div>

Last updated