Accessibility in Angular Button group component

15 Sep 20224 minutes to read

The web accessibility makes web content and web applications more accessible for people with disabilities. It especially helps in dynamic content change and development of advanced user interface controls with AJAX, HTML, JavaScript, and related technologies.
ButtonGroup provides built-in compliance with WAI-ARIA specifications. It helps the people with disabilities by providing information about the widget for assistive
technology in the screen readers. ButtonGroup component contains the group role.

Properties Functionality
role Indicates the group for the container that holds two or more buttons.

Keyboard interaction

Normal behavior

Keyboard shortcuts Actions
Tab Focuses the next button in the ButtonGroup.
Enter/Space Activates the focussed button in the ButtonGroup.

Checkbox behavior

Keyboard shortcuts Actions
Tab Focuses the next button in the ButtonGroup.
Space Activates the focussed button in the ButtonGroup.

Radiobutton behavior

Keyboard shortcuts Actions
Tab Focuses the active button in the ButtonGroup.
Arrow Keys Activates next/previous button in the ButtonGroup.
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<!-- To render ButtonGroup. -->
            <h5>Normal behavior</h5>
            <div class='e-btn-group' role='group'>
                <button class="e-btn">HTML</button>
                <button class="e-btn">CSS</button>
                <button class="e-btn">Javascript</button>
            </div>
            <h5>Checkbox type behavior</h5>
            <div class='e-btn-group' role='group'>
                <input type="checkbox" id="check_bold" name="font" value="bold"/>
                <label class="e-btn" for="check_bold">Bold</label>
                <input type="checkbox" id="check_italic" name="font" value="italic"/>
                <label class="e-btn" for="check_italic">Italic</label>
                <input type="checkbox" id="check_underline" name="font" value="underline"/>
                <label class="e-btn" for="check_underline">Underline</label>
            </div>
            <h5>Radiobutton type behavior</h5>
            <div class='e-btn-group' role='group'>
                <input type="radio" id="radioleft" name="align" value="left"/>
                <label class="e-btn" for="radioleft">Left</label>
                <input type="radio" id="radiomiddle" name="align" value="middle"/>
                <label class="e-btn" for="radiomiddle">Center</label>
                <input type="radio" id="radioright" name="align" value="right"/>
                <label class="e-btn" for="radioright">Right</label>
            </div>`
})

export class AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ButtonModule } from '@syncfusion/ej2-angular-buttons';
import { AppComponent } from './app.component';
import { enableRipple } from '@syncfusion/ej2-base';

enableRipple(true);

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);