Accessibility in Angular Drop down list component
27 Apr 20248 minutes to read
The DropDownList component has been designed, keeping in mind the WAI-ARIA
specifications, and applies the WAI-ARIA roles, states, and properties along with keyboard support
. This component is characterized by complete keyboard interaction support and ARIA accessibility support that makes it easy for people who use assistive technologies (AT) or those who completely rely on keyboard navigation.
The DropDownList component followed the accessibility guidelines and standards, including ADA, Section 508, WCAG 2.2 standards, and WCAG roles that are commonly used to evaluate accessibility.
The accessibility compliance for the DropDownList component is outlined below.
WAI-ARIA attributes
The DropDownList component uses the Listbox
role, and each list item has an option
role. The following ARIA attributes
denote the DropDownList state.
Properties | Functionalities |
---|---|
aria-haspopup | Indicates whether the DropDownList input element has a popup list or not. |
aria-expanded | Indicates whether the popup list has expanded or not. |
aria-selected | Indicates the selected option. |
aria-readonly | Indicates the readonly state of the DropDownList element. |
aria-disabled | Indicates whether the DropDownList component is in a disabled state or not. |
aria-activedescendent | This attribute holds the ID of the active list item to focus its descendant child element. |
aria-owns | This attribute contains the ID of the popup list to indicate popup as a child element. |
Keyboard Interaction
You can use the following key shortcuts to access the DropDownList without interruptions.
Keyboard shortcuts | Actions |
---|---|
Arrow Down | Selects the first item in the DropDownList when no item selected. Otherwise, selects the item next to the currently selected item. |
Arrow Up | Selects the item previous to the currently selected one. |
Page Down | Scrolls down to the next page and selects the first item when popup list opens. |
Page Up | Scrolls up to the previous page and selects the first item when popup list opens. |
Enter | Selects the focused item, and when it is in an open state the popup list closes. Otherwise, toggles the popup list. |
Tab | Focuses on the next TabIndex element on the page when the popup is closed. Otherwise, closes the popup list and remains the focus of the component. |
Shift + tab | Focuses on the previous TabIndex element on the page when the popup is closed. Otherwise, closes the popup list and remains the focus of the component. |
Alt + Down | Opens the popup list. |
Alt + Up | Closes the popup list. |
Esc(Escape) | Closes the popup list when it is in an open state and the currently selected item remains the same. |
Home | Selects the first item. |
End | Selects the last item. |
In the following sample, alt+t keys are used to focus the DropDownList component.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { ButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component, HostListener, ViewChild } from '@angular/core';
import { DropDownListComponent } from '@syncfusion/ej2-angular-dropdowns';
@Component({
imports: [
FormsModule, ReactiveFormsModule, DropDownListModule, ButtonModule
],
standalone: true,
selector: 'app-root',
// specifies the template string for the DropDownList component with change event
template: `<ejs-dropdownlist id='ddlelement' #samples [dataSource]='data' [placeholder]='text' [popupHeight]='height'></ejs-dropdownlist>`
})
export class AppComponent {
@ViewChild('samples')
public sports?: DropDownListComponent;
constructor() {
}
// defined the array of data
public data: string[] = ['Badminton', 'Basketball', 'Cricket', 'FootBall', 'Golf', 'Hockey', 'Rugby', 'Snooker', 'Tennis'];
// set placeholder to DropDownList input element
public text: string = "Select a game";
// set the popup list height
public height: string = '200px';
@HostListener('document:keyup', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
if (event.altKey && event.keyCode === 84 /* t */) {
// press alt+t to focus the control.
this.sports!.focusIn();
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Ensuring accessibility
The DropDownList component’s accessibility levels are ensured through an accessibility-checker and axe-core software tools during automated testing.
The accessibility compliance of the DropDownList component is shown in the following sample. Open the sample in a new window to evaluate the accessibility of the DropDownList component with accessibility tools.