Slide 1

Slide 1 text

Accessibility in Angular Angulars features for a better and more inclusive web DB Systel GmbH | Danny Koppenhagen | 16.01.2024

Slide 2

Slide 2 text

Overview DB Systel GmbH | Danny Koppenhagen | 16.01.2024 3 1. Introduction to a11y 2. Angulars a11y features 3. Angular CDK 4. Linting, Testing & Tools

Slide 3

Slide 3 text

About me DB Systel GmbH | Danny Koppenhagen | 16.01.2024 4 Danny Koppenhagen GitHub: d-koppenhagen (Twitter): @d_koppenhagen LinkedIn: d-koppenhagen

Slide 4

Slide 4 text

Introduction to a11y DB Systel GmbH | Danny Koppenhagen | 16.01.2024 5

Slide 5

Slide 5 text

Types of limitations DB Systel GmbH | Danny Koppenhagen | 16.01.2024 6 type permanent temporary situational controlling only one arm broken arm parents with a child in their arms seeing blindness eye surgery distracted driver hearing deaf ear infection working on noisy machines speaking muteness laryngitis heavy accent thinking cognitive limitations headache distraction, fatigue

Slide 6

Slide 6 text

W3C, WAI, WCAG DB Systel GmbH | Danny Koppenhagen | 16.01.2024 7 World Wide Web Consortium WAI Web Accessibility Initiative publishes WCAG Web Content Accessibility Guidelines

Slide 7

Slide 7 text

Semantic HTML DB Systel GmbH | Danny Koppenhagen | 16.01.2024 8

Slide 8

Slide 8 text

ARIA and Roles – Just a part of the solution DB Systel GmbH | Danny Koppenhagen | 16.01.2024 9 • Prefer always the usage of Semantic HTML elements! • Roles are already embedded in some elements (such as regions, details/summary, dialog, etc.) • ARIA attributes often not needed - aria-required ⟶ required - aria-hidden ⟶ hidden - aria-label ⟶ visual Text - aria-readonly ⟶ readonly - div[role=button] ⟶

Slide 9

Slide 9 text

Choose your libs wisely DB Systel GmbH | Danny Koppenhagen | 16.01.2024 10 Project A Project B Project C Project N Inaccessible Library

Slide 10

Slide 10 text

Angulars a11y features DB Systel GmbH | Danny Koppenhagen | 16.01.2024 11

Slide 11

Slide 11 text

Template Syntax: ARIA Attributes DB Systel GmbH | Danny Koppenhagen | 16.01.2024 12 • Static ARIA attributes can be set directly • Bindings must be made using the attr. prefix

Slide 12

Slide 12 text

Template Syntax: Deferred Loading DB Systel GmbH | Danny Koppenhagen | 16.01.2024 13 Keep aware, lazy loaded content must maybe announced when loading state changes

@defer(on timer(10000)) { } @placeholder() { Placeholder... } @loading(minimum 1000) { Loading... } @error() { Error... }

Announce whole content within, not only changed parts Set politeness

Slide 13

Slide 13 text

ARIA Atomic DB Systel GmbH | Danny Koppenhagen | 16.01.2024 14

10 seconds left.

9 seconds left.

„10 seconds left.“ „9 seconds left.“

10 seconds left.

9 seconds left.

„10“ „9“

Slide 14

Slide 14 text

Track items by unique attribute DB Systel GmbH | Danny Koppenhagen | 16.01.2024 16 • Prevent DOM updates of the whole list • Restore on focus changes when rendering dynamic lists • Prevent errors when array is updated while interacting • Prevent using track $index @for(recipient of recipients; track recipient.id) {
DB Systel GmbH
c/o {{ recipient.fullname }}
Kynaststraße 1
10317 Berlin
}

Slide 15

Slide 15 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 17 Demo: Track list items

Slide 16

Slide 16 text

Angular Router: aria-current & active page styling DB Systel GmbH | Danny Koppenhagen | 16.01.2024 18 aria-current="page" • Angular Router has built-in mechanism to determine and style active pages • Current page indication with ARIA attribute aria-current

Slide 17

Slide 17 text

Angular Router: Unique page titles DB Systel GmbH | Danny Koppenhagen | 16.01.2024 19 • Page title can be set in the route config entry • Custom / dynamic titles possible using the TitleStrategy Examples - / ➡ My Awesome Blog: Home - /blog ➡ My Awesome Blog: Latests Blog Posts - /blog/:slug ➡ My Awesome Blog: Dynamic title fetched by service Title prefix added by TitleStrategy

Slide 18

Slide 18 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 20 Demo: Page Title

Slide 19

Slide 19 text

Angular CDK DB Systel GmbH | Danny Koppenhagen | 16.01.2024 21

Slide 20

Slide 20 text

Overview DB Systel GmbH | Danny Koppenhagen | 16.01.2024 22 material.angular.io/cdk

Slide 21

Slide 21 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 23 Examples…

Slide 22

Slide 22 text

Listbox – General Focus Strategies DB Systel GmbH | Danny Koppenhagen | 16.01.2024 24 Roving Tabindex Dropdown
  • #1
  • #2
  • #3
Aria active decendant Dropdown
  • #1
  • #2
  • #3

Slide 23

Slide 23 text

CDK Listbox DB Systel GmbH | Danny Koppenhagen | 16.01.2024 25 Dropdown
  • #1
  • #2
  • #3

Slide 24

Slide 24 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 26 Demo: Listbox

Slide 25

Slide 25 text

Overlay DB Systel GmbH | Danny Koppenhagen | 16.01.2024 27 … is mounted in the apps element Two strategies: • GlobalPositionStrategy: specific viewport position (for modals, appl-level notifications, etc.) • ConnectedPositionStrategy: placed relative to the origin (for menus, pickers, tooltips, etc.) • CDK Overlay is the most generic and flexible implementation • It‘s used / implemented by other CDK features such as Menu or Dialog

Slide 26

Slide 26 text

Live Announcer DB Systel GmbH | Danny Koppenhagen | 16.01.2024 28 • Creates a visually hidden aria-live region in the apps element and inserts/updates conent within so the content/changes will be announced by screenreaders @Component({ //... }) export class MyComponent { constructor(liveAnnouncer: LiveAnnouncer) { liveAnnouncer.announce("Hello Angular Berlin Meetup!"); } }

Slide 27

Slide 27 text

Strategies for hiding elements DB Systel GmbH | Danny Koppenhagen | 16.01.2024 29 For screenreaders For all Only visual .visually-hidden:not(:focus):not(:active), .sr-only:not(:focus):not(:active) { height: 1px; overflow: hidden; width: 1px; position: absolute; clip: rect(1px, 1px, 1px, 1px); clip-path: inset(50%); white-space: nowrap; } shrink to 1px size remove visualiy (e. g. background) prevent wrapping content

Slide 28

Slide 28 text

CKD helper: cdk-visually-hidden DB Systel GmbH | Danny Koppenhagen | 16.01.2024 30 @use '@angular/cdk'; @include cdk.a11y-visually-hidden();
My visually hidden text

Slide 29

Slide 29 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 31 Demo: Overlay + Live Announcer

Slide 30

Slide 30 text

Trees DB Systel GmbH | Danny Koppenhagen | 16.01.2024 32 • Build (expandable) tree structures • Sets role="tree", role="treeitem" automatically Demos: https://k9n.dev/blog/2020-11-twa (Open the navigation on the right site) https://material.angular.io/cdk/tree/examples

Slide 31

Slide 31 text

DB Systel GmbH | Danny Koppenhagen | 16.01.2024 33 Demo: Tree

Slide 32

Slide 32 text

Linting, Testing & Tools DB Systel GmbH | Danny Koppenhagen | 16.01.2024 34

Slide 33

Slide 33 text

ESLint DB Systel GmbH | Danny Koppenhagen | 16.01.2024 35 ng add @angular-eslint/schematics npm run lint .eslintrc.json is created and pre-configured including the following accessibility rules: "@angular-eslint/template/alt-text": "error", "@angular-eslint/template/click-events-have-key-events": "error", "@angular-eslint/template/elements-content": "error", "@angular-eslint/template/interactive-supports-focus": "error", "@angular-eslint/template/label-has-associated-control": "error", "@angular-eslint/template/mouse-events-have-key-events": "error", "@angular-eslint/template/no-autofocus": "error", "@angular-eslint/template/no-distracting-elements": "error", "@angular-eslint/template/role-has-required-aria": "error", "@angular-eslint/template/table-scope": "error", "@angular-eslint/template/valid-aria": "error",

Slide 34

Slide 34 text

e2e Tools DB Systel GmbH | Danny Koppenhagen | 16.01.2024 36 • Lighthouse-ci • @axe-core/playwright • cypress-axe • jest-axe • pa11y

Slide 35

Slide 35 text

Storybook DB Systel GmbH | Danny Koppenhagen | 16.01.2024 37 npx storybook@latest init && npm install @storybook/addon-a11y -D

Slide 36

Slide 36 text

Its about the human! DB Systel GmbH | Danny Koppenhagen | 16.01.2024 38

Slide 37

Slide 37 text

Slides & Demo DB Systel GmbH | Danny Koppenhagen | 16.01.2024 39 https://techstories.dbsystel.de/blog/2024/2024-01-16-Accessibility-in-Angular.html

Slide 38

Slide 38 text

Contact Danny Koppenhagen Platforms for New Mobility (PlaNeMo) [email protected] DB Systel GmbH Kynaststr. 1 | 10317 Berlin Thank you for your attention www.dbsystel.de GitHub d-koppenhagen X (Twitter) @d_koppenhagen LinkedIn d-koppenhagen Slides and Source Code