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 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. |
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 below sample, alt+t keys are used to focus the DropDownList component.
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component<{}, {}> {
// defined the array of data
private gameList: { [key: string]: Object }[] = [
{ Id: 'Game1', Game: 'Badminton' },
{ Id: 'Game2', Game: 'Basketball' },
{ Id: 'Game3', Game: 'Cricket' },
{ Id: 'Game4', Game: 'Football' },
{ Id: 'Game5', Game: 'Golf' },
{ Id: 'Game6', Game: 'Hockey' },
{ Id: 'Game7', Game: 'Rugby' },
{ Id: 'Game8', Game: 'Snooker' },
{ Id: 'Game9', Game: 'Tennis' }
];
// maps the appropriate column to fields property
private fields: object = { text: 'Game', value: 'Id' };
// instance of DropDownList component
private dropDownListObj: any;
public componentDidMount() {
const proxy = this;
document.onkeyup = (e) => {
if (e.altKey && e.keyCode === 84 /* t */) {
// press alt+t to focus the control.
proxy.dropDownListObj.inputElement.focus();
}
};
}
public render() {
return (
// specifies the tag for render the DropDownList component
<DropDownListComponent id="ddlelement" ref={(scope) => { this.dropDownListObj = scope; }} popupHeight='200px' fields={this.fields} dataSource={this.gameList} placeholder="Select a game" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React DropDownList</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
</head>
<body>
<div id='sample' style="margin: 20px auto 0; width:250px;">
<div id='loader'>Loading....</div>
</div>
</body>
</html>