Angular Accordion - Keyboard Support

An end user can use the following keys to interact with the UI component.

KeyAction
↑ or PageUpSets focus to the previous panel.
↓ or PageDownSets focus to the next panel.
HomeSets focus to the first panel.
EndSets focus to the last panel.
EnterExpands the focused panel.
SpaceCollapses the focused panel.

You can implement a custom handler for a key using the registerKeyHandler(key, handler) method.

TypeScript
  • import { ..., ViewChild, AfterViewInit } from '@angular/core';
  • import { DxAccordionModule, DxAccordionComponent } from 'devextreme-angular';
  • // ...
  • export class AppComponent implements AfterViewInit {
  • @ViewChild(DxAccordionComponent, { static: false }) accordion: DxAccordionComponent;
  • // Prior to Angular 8
  • // @ViewChild(DxAccordionComponent) accordion: DxAccordionComponent;
  •  
  • ngAfterViewInit () {
  • this.accordion.instance.registerKeyHandler('backspace', function(e) {
  • // The argument "e" contains information on the event
  • });
  • this.accordion.instance.registerKeyHandler('space', function(e) {
  • // ...
  • });
  • }
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxAccordionModule
  • ],
  • // ...
  • })
See Also