From 05a1d96776e3c2445d52da5dfb37f41475155cd9 Mon Sep 17 00:00:00 2001 From: Adrian Petrov Date: Thu, 19 Nov 2026 16:11:53 +0200 Subject: [PATCH 1/4] fix(list): make selectable lists keyboard accessible --- CHANGELOG.md | 7 + projects/igniteui-angular/list/README.md | 49 +++- .../list/src/list/list-item.component.ts | 26 ++- .../list/src/list/list.common.ts | 38 ++++ .../list/src/list/list.component.spec.ts | 212 +++++++++++++++++- .../list/src/list/list.component.ts | 98 +++++++- .../list/src/list/themes/_base.scss | 8 + .../test-utils/list-components.spec.ts | 76 +++++++ src/app/list/list.sample.html | 15 +- 9 files changed, 510 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5582eeb8a87..88707bbd6ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes for each version of this project will be documented in this ## 22.3.1 +### Behavioral Changes + +- `IgxListComponent`, `IgxListItemComponent` + - When items bind `[selected]`, the list is now an accessible listbox: the list has `role="listbox"`, items have `role="option"` with `aria-selected`, and the list and its items can be focused with Tab. Arrow Up/Down and Home/End move between items, and Enter/Space click the focused item, so `itemClicked` fires. Lists without `[selected]` are unchanged. + - In this type of list, headers act as group names: each item gets the text of the header above it as its `aria-description`, so screen readers announce the group with every item. An item that has its own `aria-description` in the template keeps it. The headers themselves are hidden from screen readers. + - Recommended: give this type of list an `aria-label`, so it is announced when the list is focused. Set `aria-multiselectable="true"` when more than one item can be selected, and avoid focusable controls inside the items. If an item needs a selection control, such as a checkbox, make it `inert` so it does not interfere with the keyboard navigation and selection, and bind it to the item's selected state. + ### Bug Fixes - `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent` diff --git a/projects/igniteui-angular/list/README.md b/projects/igniteui-angular/list/README.md index 80dce3a1abc..0d40d90febd 100644 --- a/projects/igniteui-angular/list/README.md +++ b/projects/igniteui-angular/list/README.md @@ -67,6 +67,48 @@ In order to access its elements, the list provides the following: - an array with items only - an array with headers only +### Selectable lists and keyboard navigation +When items bind `[selected]`, the list becomes an accessible [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/): + +- The list gets `role="listbox"` and items get `role="option"` with `aria-selected`. +- Tab focuses the list, then each item. Headers and hidden items are skipped. +- Headers act as group names: each item gets the text of the header above it as its `aria-description`, and the headers are hidden from screen readers. A screen reader reads the item content followed by the group name, e.g. "Kate, selected, 1 of 8, Employees". An item that has its own `aria-description` in the template keeps it. + +| Key | Action | +| :--- | :--- | +| Arrow Down / Arrow Up | Next / previous item | +| Home / End | First / last item | +| Enter / Space | Clicks the item, so `(click)` and `itemClicked` fire | + +```html + + @for (item of items(); track item.id) { + + {{ item.name }} + + } + +``` + +Recommendations: + +- **Name the list.** Set `aria-label`, or `aria-labelledby` pointing to a visible title. Headers do not name the list, and without a name some screen readers read the first item instead of the list. +- **Mark multi-select lists.** If more than one item can be selected, set `aria-multiselectable="true"` on the list. Without it, screen readers treat the list as single-select and may not announce additional selections. +- **Avoid interactive controls inside items.** An option should not contain buttons, links or checkboxes that can be focused. To show the selection with a checkbox, make it `inert` and bind it to the item state, so clicking it selects the item: + +```html + + @for (employee of employees; track employee.id) { + + {{ employee.name }} + + + } + +``` + +Lists without `[selected]` are unchanged: they are not focusable, and controls inside their items work as before. + ### Empty list template By default if there are no items in the list, the default empty list template will be displayed. @@ -130,7 +172,7 @@ public rightPanPerformed(args) { | items | Array of items in the list | | headers | Array of headers in the list | | innerStyle | Currently used inner style depending on whether the list is empty or not | -| role | Gets the role of the list | +| role | Gets/sets the role of the list - _listbox_ when items bind `selected`, _list_ otherwise | ### Outputs @@ -141,7 +183,7 @@ public rightPanPerformed(args) { | panStateChange | Triggered when pan gesture is executed on list item | | leftPan | Triggered when left pan gesture is executed on list item | | rightPan | Triggered when right pan gesture is executed on list item | -| itemClicked | Triggered when a list item has been clicked | +| itemClicked | Triggered when a list item is clicked, or activated with Enter or Space | ---------- @@ -184,6 +226,7 @@ All list items implement `IListChild`. | index | The index of item in children collection | | hidden | Determines whether the item should be displayed | | isHeader | Determines whether the item should be displayed as a header, default value is _false_ | +| selected | Whether the item is selected, default _false_. Binding it makes the list a [listbox](#selectable-lists-and-keyboard-navigation) | ### Directives @@ -202,7 +245,7 @@ All list items implement `IListChild`. | :--- | :--- | | panState | Gets the item's pan state | | list | Gets the list that is associated with the item | -| role | Gets the role of the item within its respective list - _separator_ if isHeader is true and _listitem_ otherwise | +| role | Gets/sets the role of the item - _separator_ for headers; for items _option_ in a listbox, _listitem_ otherwise | | element | Gets the native element that is associated with the item | | width | Gets the width of the item | | maxLeft | Gets the maximum left position of the item | diff --git a/projects/igniteui-angular/list/src/list/list-item.component.ts b/projects/igniteui-angular/list/src/list/list-item.component.ts index e6aff5eccb0..ddeefec8fe3 100644 --- a/projects/igniteui-angular/list/src/list/list-item.component.ts +++ b/projects/igniteui-angular/list/src/list/list-item.component.ts @@ -40,6 +40,9 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { */ private _gestures: IgxTouchManager | null = null; + /** The `aria-description` set on the item in the template, which is kept instead of the group name. */ + private readonly _ownDescription = this.elementRef.nativeElement.getAttribute('aria-description'); + /** * Provides a reference to the template's base element shown when left panning a list item. * ```typescript @@ -258,6 +261,8 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { /** * Gets/Sets the `role` attribute of the `list item`. + * Defaults to `separator` for headers, and for items to `option` when the items of the list bind `selected` + * and to `listitem` otherwise. * ```typescript * let itemRole = this.listItem.role; * ``` @@ -267,7 +272,7 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { @HostBinding('attr.role') @Input() public get role() { - return this._role ? this._role : this.isHeader ? 'separator' : 'listitem'; + return this._role ? this._role : this.isHeader ? 'separator' : this.list.selectable ? 'option' : 'listitem'; } public set role(val: string) { @@ -301,6 +306,24 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { public set selected(value: boolean) { this._selected = value; + this.list.selectionItems.add(this); + } + + /** + * @hidden + * @internal + * In a list whose items bind `selected`, the options are tab stops that expose their selected state + * and are described by the header of their group, unless they have their own `aria-description`. + * The headers are hidden from assistive technology. Called by the list after rendering. + */ + public updateAttributes(selectable: boolean, header: IgxListItemComponent | null) { + const option = selectable && !this.isHeader; + this.list.syncAttribute(this.element, 'tabindex', option ? '0' : null); + this.list.syncAttribute(this.element, 'aria-selected', option ? String(this.selected) : null); + this.list.syncAttribute(this.element, 'aria-hidden', selectable && this.isHeader ? 'true' : null); + if (!this._ownDescription) { + this.list.syncAttribute(this.element, 'aria-description', (option && header?.element.textContent.trim()) || null); + } } /** @@ -371,6 +394,7 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { */ public ngOnDestroy() { this._gestures?.destroy(); + this.list.selectionItems.delete(this); } /** diff --git a/projects/igniteui-angular/list/src/list/list.common.ts b/projects/igniteui-angular/list/src/list/list.common.ts index 7a31b42f80f..ea69407ae7c 100644 --- a/projects/igniteui-angular/list/src/list/list.common.ts +++ b/projects/igniteui-angular/list/src/list/list.common.ts @@ -25,6 +25,44 @@ export class IgxListBaseDirective { public children!: QueryList; public listItemLeftPanningTemplate!: IgxListItemLeftPanningTemplateDirective; public listItemRightPanningTemplate!: IgxListItemRightPanningTemplateDirective; + + /** + * @hidden + * @internal + * The items that bind `selected`. + */ + public readonly selectionItems = new Set<{ isHeader: boolean }>(); + + /** + * @hidden + * @internal + * Whether an item that is not a header binds `selected`. + * Such a list follows the ARIA listbox pattern. + */ + public get selectable(): boolean { + for (const item of this.selectionItems) { + if (!item.isHeader) { + return true; + } + } + return false; + } + + /** + * @hidden + * @internal + * Sets or removes (with `null`) an attribute of the list or one of its items, when it changes. + */ + public syncAttribute(element: Element, name: string, value: string | null) { + if (element.getAttribute(name) === value) { + return; + } + if (value === null) { + element.removeAttribute(name); + } else { + element.setAttribute(name, value); + } + } } export enum IgxListPanState { NONE, LEFT, RIGHT } diff --git a/projects/igniteui-angular/list/src/list/list.component.spec.ts b/projects/igniteui-angular/list/src/list/list.component.spec.ts index 47ba0652a09..44b5f58dc50 100644 --- a/projects/igniteui-angular/list/src/list/list.component.spec.ts +++ b/projects/igniteui-angular/list/src/list/list.component.spec.ts @@ -1,11 +1,11 @@ import { NgZone, QueryList } from '@angular/core'; -import { TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { IgxListItemComponent } from './list-item.component'; import { IgxListPanState } from './list.common'; import { IgxListActionDirective, IgxListComponent, IgxListLineDirective, IgxListLineSubTitleDirective, IgxListLineTitleDirective, IgxListThumbnailDirective, IListItemClickEventArgs } from './list.component'; -import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent } from '../../../test-utils/list-components.spec'; +import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent, SelectableListComponent, GroupedSelectableListComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent } from '../../../test-utils/list-components.spec'; import { nextFrame } from '../../../test-utils/ui-interactions.spec'; import { advance, useFakeClock } from '../../../test-utils/helper-utils.spec'; import { GridFunctions } from '../../../test-utils/grid-functions.spec'; @@ -31,7 +31,11 @@ describe('List', () => { ListWithPanningTemplatesComponent, ListWithIgxForAndScrollingComponent, ListDirectivesComponent, - ListWithSelectedItemComponent + ListWithSelectedItemComponent, + SelectableListComponent, + GroupedSelectableListComponent, + ListWithOwnAttributesComponent, + ListWithBoundAttributesComponent ] }).compileComponents(); }); @@ -758,6 +762,208 @@ describe('List', () => { expect(headerItem.element.classList.contains('igx-list__item-base--selected')).toBe(false); }); + describe('Selectable list', () => { + let fixture: ComponentFixture; + let list: IgxListComponent; + + const pressKey = (target: HTMLElement, key: string): KeyboardEvent => { + const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true }); + target.dispatchEvent(event); + return event; + }; + + beforeEach(() => { + fixture = TestBed.createComponent(SelectableListComponent); + list = fixture.componentInstance.list; + fixture.detectChanges(); + }); + + it('should keep the attributes set by the app when no item binds selected', () => { + const ownFixture = TestBed.createComponent(ListWithOwnAttributesComponent); + ownFixture.detectChanges(); + const ownList = ownFixture.componentInstance.list; + const [header, item] = ownList.children.toArray(); + + expect(ownList.element.nativeElement.getAttribute('tabindex')).toBe('0'); + expect(header.element.getAttribute('aria-hidden')).toBe('true'); + expect(item.element.getAttribute('tabindex')).toBe('-1'); + expect(item.element.getAttribute('aria-selected')).toBe('true'); + }); + + it('should keep the attributes bound by the app when no item binds selected', () => { + const boundFixture = TestBed.createComponent(ListWithBoundAttributesComponent); + boundFixture.detectChanges(); + const boundList = boundFixture.componentInstance.list; + const [header, item] = boundList.children.toArray(); + + expect(boundList.element.nativeElement.getAttribute('tabindex')).toBe('0'); + expect(header.element.getAttribute('aria-hidden')).toBe('true'); + expect(item.element.getAttribute('tabindex')).toBe('0'); + expect(item.element.getAttribute('aria-selected')).toBe('true'); + expect(item.element.getAttribute('aria-description')).toBe('Note'); + + boundFixture.componentInstance.tabIndex = '-1'; + boundFixture.componentInstance.selected = 'false'; + boundFixture.detectChanges(); + expect(boundList.element.nativeElement.getAttribute('tabindex')).toBe('-1'); + expect(item.element.getAttribute('tabindex')).toBe('-1'); + expect(item.element.getAttribute('aria-selected')).toBe('false'); + }); + + it('should leave a list whose items do not bind selected unchanged', () => { + const plainFixture = TestBed.createComponent(ListWithHeaderComponent); + plainFixture.detectChanges(); + const plainList = plainFixture.componentInstance.list; + const listElement = plainList.element.nativeElement as HTMLElement; + + expect(listElement.getAttribute('role')).toBe('list'); + expect(listElement.hasAttribute('tabindex')).toBe(false); + plainList.headers.forEach(header => { + expect(header.element.getAttribute('role')).toBe('separator'); + expect(header.element.hasAttribute('aria-hidden')).toBe(false); + }); + plainList.items.forEach(item => { + expect(item.element.getAttribute('role')).toBe('listitem'); + expect(item.element.hasAttribute('tabindex')).toBe(false); + expect(item.element.hasAttribute('aria-selected')).toBe(false); + expect(item.element.hasAttribute('aria-description')).toBe(false); + }); + expect(pressKey(plainList.items[0].element, 'ArrowDown').defaultPrevented).toBe(false); + }); + + it('should be a focusable listbox with option items that expose their selected state', () => { + const listElement = list.element.nativeElement as HTMLElement; + const [header, ...items] = list.children.toArray(); + + expect(listElement.getAttribute('role')).toBe('listbox'); + expect(listElement.getAttribute('tabindex')).toBe('0'); + expect(header.element.getAttribute('role')).toBe('separator'); + expect(header.element.getAttribute('aria-hidden')).toBe('true'); + expect(header.element.hasAttribute('tabindex')).toBe(false); + expect(items.map(i => i.element.getAttribute('role'))).toEqual(['option', 'option', 'option']); + expect(items.map(i => i.element.getAttribute('tabindex'))).toEqual(['0', '0', '0']); + expect(items.map(i => i.element.getAttribute('aria-selected'))).toEqual(['false', 'true', 'false']); + + fixture.componentInstance.selectedId = 3; + fixture.detectChanges(); + expect(items.map(i => i.element.getAttribute('aria-selected'))).toEqual(['false', 'false', 'true']); + }); + + it('should go back to the list roles when the items that bind selected are removed', () => { + fixture.componentInstance.items = []; + fixture.detectChanges(); + + const listElement = list.element.nativeElement as HTMLElement; + expect(listElement.getAttribute('role')).toBe('list'); + expect(listElement.hasAttribute('tabindex')).toBe(false); + expect(list.children.first.element.hasAttribute('aria-hidden')).toBe(false); + }); + + it('should keep the roles set by the app and not follow the listbox pattern with a role other than listbox', () => { + list.role = 'menu'; + list.items[0].role = 'menuitem'; + fixture.detectChanges(); + + const listElement = list.element.nativeElement as HTMLElement; + expect(listElement.getAttribute('role')).toBe('menu'); + expect(listElement.hasAttribute('tabindex')).toBe(false); + expect(list.items[0].element.getAttribute('role')).toBe('menuitem'); + expect(list.items[1].element.getAttribute('role')).toBe('listitem'); + list.items.forEach(item => expect(item.element.hasAttribute('aria-selected')).toBe(false)); + expect(pressKey(list.items[1].element, 'ArrowDown').defaultPrevented).toBe(false); + + list.role = null; + fixture.detectChanges(); + expect(listElement.hasAttribute('role')).toBe(false); + }); + + it('should describe every option with the header of its group, unless it has its own description', () => { + const groupedFixture = TestBed.createComponent(GroupedSelectableListComponent); + groupedFixture.detectChanges(); + const [ungrouped, item1, item2, item3] = groupedFixture.componentInstance.list.items; + + expect(ungrouped.element.hasAttribute('aria-description')).toBe(false); + expect(item1.element.getAttribute('aria-description')).toBe('Employees'); + expect(item2.element.getAttribute('aria-description')).toBe('Part-time'); + expect(item3.element.getAttribute('aria-description')).toBe('Contractors'); + }); + + describe('Keyboard navigation', () => { + it('should move the focus with ArrowDown and ArrowUp without wrapping around', () => { + const items = list.items; + items[0].element.focus(); + + const event = pressKey(items[0].element, 'ArrowDown'); + expect(document.activeElement).toBe(items[1].element); + expect(event.defaultPrevented).toBe(true); + + pressKey(items[1].element, 'ArrowDown'); + pressKey(items[2].element, 'ArrowDown'); + expect(document.activeElement).toBe(items[2].element); + + pressKey(items[2].element, 'ArrowUp'); + expect(document.activeElement).toBe(items[1].element); + + pressKey(items[1].element, 'ArrowUp'); + pressKey(items[0].element, 'ArrowUp'); + expect(document.activeElement).toBe(items[0].element); + }); + + it('should move the focus to the first and last item with Home and End, also from the list', () => { + const listElement = list.element.nativeElement as HTMLElement; + const items = list.items; + items[1].element.focus(); + + pressKey(items[1].element, 'End'); + expect(document.activeElement).toBe(items[2].element); + + pressKey(items[2].element, 'Home'); + expect(document.activeElement).toBe(items[0].element); + + listElement.focus(); + pressKey(listElement, 'ArrowDown'); + expect(document.activeElement).toBe(items[0].element); + + listElement.focus(); + pressKey(listElement, 'ArrowUp'); + expect(document.activeElement).toBe(items[2].element); + }); + + it('should skip hidden items', () => { + const items = list.items; + items[1].hidden = true; + fixture.detectChanges(); + + items[0].element.focus(); + pressKey(items[0].element, 'ArrowDown'); + expect(document.activeElement).toBe(items[2].element); + }); + + it('should activate the focused item with Enter and Space like a click', () => { + const items = list.items; + const clickedItems: IgxListItemComponent[] = []; + list.itemClicked.subscribe((args: IListItemClickEventArgs) => clickedItems.push(args.item)); + items[1].element.focus(); + + expect(pressKey(items[1].element, 'Enter').defaultPrevented).toBe(true); + expect(pressKey(items[1].element, ' ').defaultPrevented).toBe(true); + expect(clickedItems).toEqual([items[1], items[1]]); + }); + + it('should not handle keys pressed in the content of an item, or Enter and Space on the list', () => { + const clickSpy = vi.fn(); + list.itemClicked.subscribe(clickSpy); + const listElement = list.element.nativeElement as HTMLElement; + const title = list.items[0].element.querySelector('[igxListLineTitle]') as HTMLElement; + + expect(pressKey(title, 'ArrowDown').defaultPrevented).toBe(false); + expect(pressKey(title, 'Enter').defaultPrevented).toBe(false); + expect(pressKey(listElement, ' ').defaultPrevented).toBe(false); + expect(clickSpy).not.toHaveBeenCalled(); + }); + }); + }); + it('Initializes igxListThumbnail directive', () => { const fixture = TestBed.createComponent(ListDirectivesComponent); fixture.detectChanges(); diff --git a/projects/igniteui-angular/list/src/list/list.component.ts b/projects/igniteui-angular/list/src/list/list.component.ts index 7c98ebf28f6..0a5b1770e3a 100644 --- a/projects/igniteui-angular/list/src/list/list.component.ts +++ b/projects/igniteui-angular/list/src/list/list.component.ts @@ -7,6 +7,7 @@ import { EventEmitter, forwardRef, HostBinding, + HostListener, Input, Output, QueryList, @@ -17,7 +18,8 @@ import { inject, DestroyRef, ChangeDetectionStrategy, - ViewEncapsulation + ViewEncapsulation, + afterEveryRender } from '@angular/core'; import { IgxListItemComponent } from './list-item.component'; @@ -478,6 +480,7 @@ export class IgxListComponent extends IgxListBaseDirective { constructor() { super(); + afterEveryRender({ write: () => this.updateAttributes() }); onResourceChangeHandle(this.destroyRef, () => { this._defaultResourceStrings = getCurrentResourceStrings(ListResourceStringsEN, false); this._customResourceStrings = this._resourceStrings ? Object.assign({}, this._defaultResourceStrings, this._resourceStrings) : null!; @@ -496,11 +499,39 @@ export class IgxListComponent extends IgxListBaseDirective { return null!; } - private _role = 'list'; + /** Whether the list has been selectable, so its attributes and those of its items are kept in sync. */ + private _synced = false; + + /** + * A list whose items bind `selected` is a tab stop, and so are its options. + * A list that has never been selectable and its items are left untouched. + */ + private updateAttributes() { + const selectable = this.selectable; + if (!selectable && !this._synced) { + return; + } + this._synced = true; + this.syncAttribute(this.element.nativeElement, 'tabindex', selectable ? '0' : null); + let header: IgxListItemComponent | null = null; + for (const item of this.children) { + if (item.list === this) { + header = item.isHeader ? item : header; + item.updateAttributes(selectable, header); + } + } + } + + /** The role set by the app. While not set, the role depends on whether the list is selectable. */ + private _role: string | undefined; /** * Gets/Sets the `role` attribute value. * + * @remarks + * Defaults to `listbox` when its items bind `selected` and to `list` otherwise. + * Setting a role other than `listbox` turns off the listbox roles, the focus and the keyboard navigation of the list and its items. + * * @example * ```typescript * let listRole = this.list.role; @@ -509,13 +540,74 @@ export class IgxListComponent extends IgxListBaseDirective { @HostBinding('attr.role') @Input() public get role() { - return this._role; + return this._role !== undefined ? this._role : this.selectable ? 'listbox' : 'list'; } public set role(val: string) { this._role = val; } + /** + * @hidden + * @internal + * Whether the list follows the ARIA listbox pattern: an item that is not a header binds `selected`, + * and no role other than `listbox` is set on the list. + */ + @HostBinding('class.igx-list--selectable') + public override get selectable(): boolean { + return (this._role === undefined || this._role === 'listbox') && super.selectable; + } + + /** + * @hidden + * @internal + * Moves the focus between the items of a list whose items bind `selected`. + * ArrowDown/ArrowUp go to the next/previous item, Home/End to the first/last one. + * Enter/Space activate the focused item like a click, so `itemClicked` and its `click` handlers fire. + * Keys pressed in the content of an item are not handled. + */ + @HostListener('keydown', ['$event']) + public onKeydown(event: KeyboardEvent) { + if (!this.selectable) { + return; + } + + const items = this.children.filter(item => item.list === this && !item.isHeader && !item.hidden); + const current = items.findIndex(item => item.element === event.target); + if (current === -1 && event.target !== this.element.nativeElement) { + return; + } + + if (event.key === 'Enter' || event.key === ' ') { + if (current !== -1) { + event.preventDefault(); + items[current].element.click(); + } + return; + } + + let next: number; + switch (event.key) { + case 'ArrowDown': + next = Math.min(current + 1, items.length - 1); + break; + case 'ArrowUp': + next = current === -1 ? items.length - 1 : Math.max(current - 1, 0); + break; + case 'Home': + next = 0; + break; + case 'End': + next = items.length - 1; + break; + default: + return; + } + + event.preventDefault(); + items[next]?.element.focus(); + } + /** * @hidden * @internal diff --git a/projects/igniteui-angular/list/src/list/themes/_base.scss b/projects/igniteui-angular/list/src/list/themes/_base.scss index bdf9bf454b1..33df8749baf 100644 --- a/projects/igniteui-angular/list/src/list/themes/_base.scss +++ b/projects/igniteui-angular/list/src/list/themes/_base.scss @@ -53,6 +53,14 @@ $theme: digest-schema($light-list); z-index: 1; } } + + @include m(selectable) { + @include e(item-base) { + &:focus-visible { + outline: none; + } + } + } } @include b(igx-list-item) { diff --git a/projects/igniteui-angular/test-utils/list-components.spec.ts b/projects/igniteui-angular/test-utils/list-components.spec.ts index 350c756a2f6..6033a6bbee4 100644 --- a/projects/igniteui-angular/test-utils/list-components.spec.ts +++ b/projects/igniteui-angular/test-utils/list-components.spec.ts @@ -84,6 +84,82 @@ export class ListWithHeaderComponent extends BasicListComponent { export class ListWithSelectedItemComponent extends BasicListComponent { } +@Component({ + template: ` +
+ + Header + @for (item of items; track item.id) { + + {{ item.name }} + + } + +
`, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxListComponent, IgxListItemComponent, IgxListLineTitleDirective] +}) +export class SelectableListComponent extends BasicListComponent { + public selectedId: number | null = 2; + public items = [ + { id: 1, name: 'Item 1' }, + { id: 2, name: 'Item 2' }, + { id: 3, name: 'Item 3' } + ]; +} + +@Component({ + template: ` +
+ + Ungrouped + Employees + Item 1 + Item 2 + Contractors + Item 3 + +
`, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxListComponent, IgxListItemComponent] +}) +export class GroupedSelectableListComponent extends BasicListComponent { +} + +@Component({ + template: ` +
+ + + Item 1 + +
`, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxListComponent, IgxListItemComponent] +}) +export class ListWithOwnAttributesComponent extends BasicListComponent { +} + +@Component({ + template: ` +
+ + Header + + Item 1 + + +
`, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxListComponent, IgxListItemComponent] +}) +export class ListWithBoundAttributesComponent extends BasicListComponent { + public tabIndex = '0'; + public hidden = 'true'; + public selected = 'true'; + public description = 'Note'; +} + @Component({ template: `
diff --git a/src/app/list/list.sample.html b/src/app/list/list.sample.html index adf5295ae88..b67d1549452 100644 --- a/src/app/list/list.sample.html +++ b/src/app/list/list.sample.html @@ -2,7 +2,7 @@
Angular List
- +
deleteDelete @@ -13,10 +13,10 @@
Angular List
callDial
- Employees List + Employees List @for (employee of employeeItems; track employee) { - + @if(properties.addAvatarThumbnail) { } @@ -30,19 +30,16 @@

{{ employee.name }}

{{ employee.position }}

} @if(properties.addCheckboxAction) { - - + } @if(properties.addIconAction) { info } @if(properties.addOutlinedButton){ - + } @if(properties.addContainedButton) { - + }
} From cb068502f1ba46218031bd57598fbb13e54abc4b Mon Sep 17 00:00:00 2001 From: Adrian Petrov Date: Mon, 23 Nov 2026 13:08:28 +0200 Subject: [PATCH 2/4] feat(list): add listbox mode with keyboard navigation --- CHANGELOG.md | 8 +- package-lock.json | 431 +----------------- package.json | 2 +- projects/igniteui-angular/list/README.md | 34 +- .../list/src/list/list-item.component.ts | 54 ++- .../list/src/list/list.common.ts | 44 +- .../list/src/list/list.component.html | 2 +- .../list/src/list/list.component.spec.ts | 158 +++++-- .../list/src/list/list.component.ts | 100 ++-- .../list/src/list/themes/_base.scss | 19 +- .../list/src/list/themes/shared/_indigo.scss | 1 + .../test-utils/list-components.spec.ts | 25 +- .../references/data-display.md | 12 + src/app/list/list.sample.html | 14 +- src/app/list/list.sample.ts | 21 - 15 files changed, 310 insertions(+), 615 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88707bbd6ac..8f6697a945b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,12 @@ All notable changes for each version of this project will be documented in this ## 22.3.1 -### Behavioral Changes +### New Features - `IgxListComponent`, `IgxListItemComponent` - - When items bind `[selected]`, the list is now an accessible listbox: the list has `role="listbox"`, items have `role="option"` with `aria-selected`, and the list and its items can be focused with Tab. Arrow Up/Down and Home/End move between items, and Enter/Space click the focused item, so `itemClicked` fires. Lists without `[selected]` are unchanged. - - In this type of list, headers act as group names: each item gets the text of the header above it as its `aria-description`, so screen readers announce the group with every item. An item that has its own `aria-description` in the template keeps it. The headers themselves are hidden from screen readers. - - Recommended: give this type of list an `aria-label`, so it is announced when the list is focused. Set `aria-multiselectable="true"` when more than one item can be selected, and avoid focusable controls inside the items. If an item needs a selection control, such as a checkbox, make it `inert` so it does not interfere with the keyboard navigation and selection, and bind it to the item's selected state. + - Setting `role="listbox"` on the list makes it an accessible listbox (#17952): items get `role="option"` with `aria-selected` from their `selected` state, and the list has a single tab stop on the option that was focused last, else the first selected one, else the first one. Arrow Up/Down and Home/End move between options, and Enter/Space click the focused option, so `itemClicked` fires. While `isLoading` is set, the list has `aria-busy="true"`. The focused option shows an inset focus ring, also when it is selected, colored by the new `item-focus-outline-color` token of the list theme. Lists with another role, and listboxes that manage the focus with `aria-activedescendant`, are unchanged. A list that already sets `role="listbox"` now gets this behavior. + - In a listbox, headers act as group names: each option points to the header above it with `aria-describedby`, so screen readers announce the group with every option, and the headers themselves are hidden from screen readers. An option that has its own `aria-describedby`, set or bound in the template, keeps it. + - Recommended: give a listbox an `aria-label`, so it is announced when the focus moves into the list. Set `aria-multiselectable="true"` when more than one item can be selected, and avoid focusable controls inside the items. If an item needs a selection control, such as a checkbox, make it `inert` so it does not interfere with the keyboard navigation and selection, and bind it to the item's selected state. ### Bug Fixes diff --git a/package-lock.json b/package-lock.json index 1f722b5f815..377f446196c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -80,7 +80,7 @@ "igniteui-grid-lite": "~0.12.0", "igniteui-i18n-resources": "^2.0.0", "igniteui-sassdoc-theme": "^3.0.0", - "igniteui-theming": "^30.2.0", + "igniteui-theming": "^30.3.0", "igniteui-webcomponents": "^7.5.0", "lit-html": "^3.2.1", "ng-packagr": "^22.0.0", @@ -9017,13 +9017,6 @@ "ieee754": "^1.1.13" } }, - "node_modules/buffer-builder": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/buffer-builder/-/buffer-builder-0.2.0.tgz", - "integrity": "sha512-7VPMEPuYznPSoR21NE1zvd2Xna6c/CloiZCfcMXR1Jny6PjX0N4Nsa38zcBFo/FMK+BlA+FLKbJCQ0i2yxp+Xg==", - "dev": true, - "license": "MIT/X11" - }, "node_modules/buffer-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.1.tgz", @@ -14307,429 +14300,27 @@ } }, "node_modules/igniteui-theming": { - "version": "30.2.0", - "resolved": "https://registry.npmjs.org/igniteui-theming/-/igniteui-theming-30.2.0.tgz", - "integrity": "sha512-nYdHKYG1FjuzB3rpz6sLlc2sYTR4HOABB3wuWokQwZj8i/cfvoBbJrsH9JESXGwcyYuq++3ZaaFG4yWBWEZG7Q==", + "version": "30.3.0", + "resolved": "https://registry.npmjs.org/igniteui-theming/-/igniteui-theming-30.3.0.tgz", + "integrity": "sha512-wBA819JhqdDYkCUF6Y/EE1n93rfflJuYEZhd1U28zvQlRBBaM702BLoNb1pno1tziQ63BaXqHv1QMjPpn0i8iQ==", "dev": true, "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.32.1", - "sass-embedded": "~1.92.1", + "sass-embedded": "^1.97.1", "zod": "^4.6.7" }, "bin": { "igniteui-theming": "dist/mcp/index.js", "igniteui-theming-mcp": "dist/mcp/index.js" - } - }, - "node_modules/igniteui-theming/node_modules/chokidar": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", - "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "readdirp": "^4.0.1" - }, - "engines": { - "node": ">= 14.16.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/igniteui-theming/node_modules/colorjs.io": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/colorjs.io/-/colorjs.io-0.5.2.tgz", - "integrity": "sha512-twmVoizEW7ylZSN32OgKdXRmo1qg+wT5/6C3xu5b9QsWzSFAhHLn2xd8ro0diCsKfCj1RdaTP/nrcW+vAoQPIw==", - "dev": true, - "license": "MIT" - }, - "node_modules/igniteui-theming/node_modules/readdirp": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", - "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", - "dev": true, - "license": "MIT", - "optional": true, - "engines": { - "node": ">= 14.18.0" }, - "funding": { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/igniteui-theming/node_modules/sass": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass/-/sass-1.92.1.tgz", - "integrity": "sha512-ffmsdbwqb3XeyR8jJR6KelIXARM9bFQe8A6Q3W4Klmwy5Ckd5gz7jgUNHo4UOqutU5Sk1DtKLbpDP0nLCg1xqQ==", - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "chokidar": "^4.0.0", - "immutable": "^5.0.2", - "source-map-js": ">=0.6.2 <2.0.0" - }, - "bin": { - "sass": "sass.js" - }, - "engines": { - "node": ">=14.0.0" - }, - "optionalDependencies": { - "@parcel/watcher": "^2.4.1" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded/-/sass-embedded-1.92.1.tgz", - "integrity": "sha512-28YwLnF5atAhogt3E4hXzz/NB9dwKffyw08a7DEasLh94P7+aELkG3ENSHYCWB9QFN14hYNLfwr9ozUsPDhcDQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@bufbuild/protobuf": "^2.5.0", - "buffer-builder": "^0.2.0", - "colorjs.io": "^0.5.0", - "immutable": "^5.0.2", - "rxjs": "^7.4.0", - "supports-color": "^8.1.1", - "sync-child-process": "^1.0.2", - "varint": "^6.0.0" - }, - "bin": { - "sass": "dist/bin/sass.js" - }, - "engines": { - "node": ">=16.0.0" + "peerDependencies": { + "sass": ">=1.97.1" }, - "optionalDependencies": { - "sass-embedded-all-unknown": "1.92.1", - "sass-embedded-android-arm": "1.92.1", - "sass-embedded-android-arm64": "1.92.1", - "sass-embedded-android-riscv64": "1.92.1", - "sass-embedded-android-x64": "1.92.1", - "sass-embedded-darwin-arm64": "1.92.1", - "sass-embedded-darwin-x64": "1.92.1", - "sass-embedded-linux-arm": "1.92.1", - "sass-embedded-linux-arm64": "1.92.1", - "sass-embedded-linux-musl-arm": "1.92.1", - "sass-embedded-linux-musl-arm64": "1.92.1", - "sass-embedded-linux-musl-riscv64": "1.92.1", - "sass-embedded-linux-musl-x64": "1.92.1", - "sass-embedded-linux-riscv64": "1.92.1", - "sass-embedded-linux-x64": "1.92.1", - "sass-embedded-unknown-all": "1.92.1", - "sass-embedded-win32-arm64": "1.92.1", - "sass-embedded-win32-x64": "1.92.1" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-all-unknown": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-all-unknown/-/sass-embedded-all-unknown-1.92.1.tgz", - "integrity": "sha512-5t6/YZf+vhO3OY/49h8RCL6Cwo78luva0M+TnTM9gu9ASffRXAuOVLNKciSXa3loptyemDDS6IU5/dVH5w0KmA==", - "cpu": [ - "!arm", - "!arm64", - "!riscv64", - "!x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "sass": "1.92.1" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-android-arm": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-android-arm/-/sass-embedded-android-arm-1.92.1.tgz", - "integrity": "sha512-4EjpVVzuksERdgAd4BqeSXFnWtWN3DSRyEIUPJ7BhcS9sfDh2Gf6miI2kNTvIQLJ2XIJynDDcEQ8a1U9KwKUTQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-android-arm64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-android-arm64/-/sass-embedded-android-arm64-1.92.1.tgz", - "integrity": "sha512-Q+UruGb7yKawHagVmVDRRKsnc4mJZvWMBnuRCu2coJo2FofyqBmXohVGXbxko97sYceA9TJTrUEx3WVKQUNCbQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-android-riscv64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-android-riscv64/-/sass-embedded-android-riscv64-1.92.1.tgz", - "integrity": "sha512-nCY5btLlX7W7Jc6cCL6D2Yklpiu540EJ2G08YVGu12DrAMCBzqM347CSRf2ojp1H8jyhvmLkaFwnrJWzh+6S+w==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-android-x64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-android-x64/-/sass-embedded-android-x64-1.92.1.tgz", - "integrity": "sha512-qYWR3bftJ77aLYwYDFuzDI4dcwVVixxqQxlIQWNGkHRCexj614qGSSHemr18C2eVj3mjXAQxTQxU68U7pkGPAA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-darwin-arm64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-darwin-arm64/-/sass-embedded-darwin-arm64-1.92.1.tgz", - "integrity": "sha512-g2yQ3txjMYLKMjL2cW1xRO9nnV3ijf95NbX/QShtV6tiVUETZNWDsRMDEwBNGYY6PTE/UZerjJL1R/2xpQg6WA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-darwin-x64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-darwin-x64/-/sass-embedded-darwin-x64-1.92.1.tgz", - "integrity": "sha512-eH+fgxLQhTEPjZPCgPAVuX5e514Qp/4DMAUMtlNShv4cr4TD5qOp1XlsPYR/b7uE7p2cKFkUpUn/bHNqJ2ay4A==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-arm": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-arm/-/sass-embedded-linux-arm-1.92.1.tgz", - "integrity": "sha512-cT3w8yoQTqrtZvWLJeutEGmawITDTY4J6oSVQjeDcPnnoPt0gOFxem8YMznraACXvahw/2+KJDH33BTNgiPo0A==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-arm64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-arm64/-/sass-embedded-linux-arm64-1.92.1.tgz", - "integrity": "sha512-dNmlpGeZkry1BofhAdGFBXrpM69y9LlYuNnncf+HfsOOUtj8j0q1RwS+zb5asknhKFUOAG8GCGRY1df7Rwu35g==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-musl-arm": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-musl-arm/-/sass-embedded-linux-musl-arm-1.92.1.tgz", - "integrity": "sha512-nPBos6lI31ef2zQhqTZhFOU7ar4impJbLIax0XsqS269YsiCwjhk11VmUloJTpFlJuKMiVXNo7dPx+katxhD/Q==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-musl-arm64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-musl-arm64/-/sass-embedded-linux-musl-arm64-1.92.1.tgz", - "integrity": "sha512-TfiEBkCyNzVoOhjHXUT+vZ6+p0ueDbvRw6f4jHdkvljZzXdXMby4wh7BU1odl69rgRTkSvYKhgbErRLDR/F7pQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-musl-riscv64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-musl-riscv64/-/sass-embedded-linux-musl-riscv64-1.92.1.tgz", - "integrity": "sha512-R+RcJA4EYpJDE9JM1GgPYgZo7x94FlxZ6jPodOQkEaZ1S9kvXVCuP5X/0PXRPhu08KJOfeMsAElzfdAjUf7KJg==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-musl-x64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-musl-x64/-/sass-embedded-linux-musl-x64-1.92.1.tgz", - "integrity": "sha512-/HolYRGXJjx8nLw6oj5ZrkR7PFM7X/5kE4MYZaFMpDIPIcw3bqB2fUXLo/MYlRLsw7gBAT6hJAMBrNdKuTphfw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-riscv64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-riscv64/-/sass-embedded-linux-riscv64-1.92.1.tgz", - "integrity": "sha512-b9bxe0CMsbSsLx3nrR0cq8xpIkoAC6X36o4DGMITF3m2v3KsojC7ru9X0Gz+zUFr6rwpq/0lTNzFLNu6sPNo3w==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-linux-x64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-linux-x64/-/sass-embedded-linux-x64-1.92.1.tgz", - "integrity": "sha512-xuiK5Jp5NldW4bvlC7AuX1Wf7o0gLZ3md/hNg+bkTvxtCDgnUHtfdo8Q+xWP11bD9QX31xXFWpmUB8UDLi6XQQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-unknown-all": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-unknown-all/-/sass-embedded-unknown-all-1.92.1.tgz", - "integrity": "sha512-AT9oXvtNY4N+Nd0wvoWqq9A5HjdH/X3aUH4boQUtXyaJ/9DUwnQmBpP5Gtn028ZS8exOGBdobmmWAuigv0k/OA==", - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "!android", - "!darwin", - "!linux", - "!win32" - ], - "dependencies": { - "sass": "1.92.1" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-win32-arm64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-win32-arm64/-/sass-embedded-win32-arm64-1.92.1.tgz", - "integrity": "sha512-KvmpQjY9yTBMtTYz4WBqetlv9bGaDW1aStcu7MSTbH7YiSybX/9fnxlCAEQv1WlIidQhcJAiyk0Eae+LGK7cIQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=14.0.0" - } - }, - "node_modules/igniteui-theming/node_modules/sass-embedded-win32-x64": { - "version": "1.92.1", - "resolved": "https://registry.npmjs.org/sass-embedded-win32-x64/-/sass-embedded-win32-x64-1.92.1.tgz", - "integrity": "sha512-B6Nz/GbH7Vkpb2TkQHsGcczWM5t+70VWopWF1x5V5yxLpA8ZzVQ7NTKKi+jDoVY2Efu6ZyzgT9n5KgG2kWliXA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=14.0.0" + "peerDependenciesMeta": { + "sass": { + "optional": true + } } }, "node_modules/igniteui-theming/node_modules/zod": { diff --git a/package.json b/package.json index 78aa64625dd..00c896e3252 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "igniteui-grid-lite": "~0.12.0", "igniteui-i18n-resources": "^2.0.0", "igniteui-sassdoc-theme": "^3.0.0", - "igniteui-theming": "^30.2.0", + "igniteui-theming": "^30.3.0", "igniteui-webcomponents": "^7.5.0", "lit-html": "^3.2.1", "ng-packagr": "^22.0.0", diff --git a/projects/igniteui-angular/list/README.md b/projects/igniteui-angular/list/README.md index 0d40d90febd..e83d63e1a76 100644 --- a/projects/igniteui-angular/list/README.md +++ b/projects/igniteui-angular/list/README.md @@ -67,21 +67,25 @@ In order to access its elements, the list provides the following: - an array with items only - an array with headers only -### Selectable lists and keyboard navigation -When items bind `[selected]`, the list becomes an accessible [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/): +### Listbox and keyboard navigation +Set `role="listbox"` on the list to make it an accessible [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/): -- The list gets `role="listbox"` and items get `role="option"` with `aria-selected`. -- Tab focuses the list, then each item. Headers and hidden items are skipped. -- Headers act as group names: each item gets the text of the header above it as its `aria-description`, and the headers are hidden from screen readers. A screen reader reads the item content followed by the group name, e.g. "Kate, selected, 1 of 8, Employees". An item that has its own `aria-description` in the template keeps it. +- Items get `role="option"` with `aria-selected`, from their `selected` state. +- The list has a single tab stop. Tab focuses the option that was focused last, else the first selected option, else the first option, and the next Tab leaves the list. Headers and hidden items are skipped. +- Headers act as group names: they are hidden from screen readers, and each option points to the header above it with `aria-describedby`. A header without an `id` gets one. A screen reader reads the option content followed by the group name, e.g. "Kate, selected, 1 of 8, Employees". An option that has its own `aria-describedby`, set or bound in the template, keeps it. +- The focused option shows an inset focus ring, also when it is selected. Its color is the `item-focus-outline-color` of the list theme. +- While `isLoading` is set, the list has `aria-busy="true"`. When the list has items, the default loading message is hidden from screen readers. | Key | Action | | :--- | :--- | -| Arrow Down / Arrow Up | Next / previous item | -| Home / End | First / last item | -| Enter / Space | Clicks the item, so `(click)` and `itemClicked` fire | +| Arrow Down / Arrow Up | Next / previous option | +| Home / End | First / last option | +| Enter / Space | Clicks the option, so `(click)` and `itemClicked` fire. Holding the key down clicks once. | + +When an option is activated with Enter or Space, the `event` of `itemClicked` is the synthetic `MouseEvent` of that click. ```html - + @for (item of items(); track item.id) { {{ item.name }} @@ -92,12 +96,12 @@ When items bind `[selected]`, the list becomes an accessible [listbox](https://w Recommendations: -- **Name the list.** Set `aria-label`, or `aria-labelledby` pointing to a visible title. Headers do not name the list, and without a name some screen readers read the first item instead of the list. +- **Name the list.** Set `aria-label`, or `aria-labelledby` pointing to a visible title. When the focus moves into the list, screen readers announce its name and role together with the focused option. Without a name, they only announce the role. Headers do not name the list. - **Mark multi-select lists.** If more than one item can be selected, set `aria-multiselectable="true"` on the list. Without it, screen readers treat the list as single-select and may not announce additional selections. - **Avoid interactive controls inside items.** An option should not contain buttons, links or checkboxes that can be focused. To show the selection with a checkbox, make it `inert` and bind it to the item state, so clicking it selects the item: ```html - + @for (employee of employees; track employee.id) { {{ employee.name }} @@ -107,7 +111,9 @@ Recommendations: ``` -Lists without `[selected]` are unchanged: they are not focusable, and controls inside their items work as before. +Lists with another role are unchanged: they are not focusable, and controls inside their items work as before. A listbox that manages the focus itself with `aria-activedescendant`, like the grid's Excel-style filter list, is also left as it is: the two focus models cannot be combined, because the list would move the focus to an option while the app keeps a different option active. Do not set `aria-activedescendant` on a listbox unless the app handles the focus and the keys itself. + +The keyboard navigation only moves between the rendered items. A list virtualized with `igxFor` is not scrolled to the items that are not rendered, so do not set `role="listbox"` on it. Handle the focus and the keys of a virtualized list in the app with `aria-activedescendant`, like the grid's Excel-style filter list does. ### Empty list template @@ -172,7 +178,7 @@ public rightPanPerformed(args) { | items | Array of items in the list | | headers | Array of headers in the list | | innerStyle | Currently used inner style depending on whether the list is empty or not | -| role | Gets/sets the role of the list - _listbox_ when items bind `selected`, _list_ otherwise | +| role | Gets/sets the role of the list, default _list_. _listbox_ makes it an accessible [listbox](#listbox-and-keyboard-navigation) with keyboard navigation | ### Outputs @@ -226,7 +232,7 @@ All list items implement `IListChild`. | index | The index of item in children collection | | hidden | Determines whether the item should be displayed | | isHeader | Determines whether the item should be displayed as a header, default value is _false_ | -| selected | Whether the item is selected, default _false_. Binding it makes the list a [listbox](#selectable-lists-and-keyboard-navigation) | +| selected | Whether the item is selected, default _false_. In a [listbox](#listbox-and-keyboard-navigation) it sets `aria-selected` | ### Directives diff --git a/projects/igniteui-angular/list/src/list/list-item.component.ts b/projects/igniteui-angular/list/src/list/list-item.component.ts index ddeefec8fe3..9d73606068a 100644 --- a/projects/igniteui-angular/list/src/list/list-item.component.ts +++ b/projects/igniteui-angular/list/src/list/list-item.component.ts @@ -3,12 +3,15 @@ import { ChangeDetectionStrategy, Component, ElementRef, HostBinding, HostListen import { IgxListPanState, IListChild, - IgxListBaseDirective + IgxListBaseDirective, + syncAttribute } from './list.common'; import { rem, IgxTouchManager, IgxGestureEvent } from 'igniteui-angular/core'; import { NgTemplateOutlet } from '@angular/common'; +let NEXT_HEADER_ID = 0; + /** * The Ignite UI List Item component is a container intended for row items in the Ignite UI for Angular List component. * @@ -40,8 +43,8 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { */ private _gestures: IgxTouchManager | null = null; - /** The `aria-description` set on the item in the template, which is kept instead of the group name. */ - private readonly _ownDescription = this.elementRef.nativeElement.getAttribute('aria-description'); + /** The `aria-describedby` the list set last, to tell it apart from one set or bound by the app, which is kept. */ + private _describedBy: string | null = null; /** * Provides a reference to the template's base element shown when left panning a list item. @@ -261,8 +264,7 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { /** * Gets/Sets the `role` attribute of the `list item`. - * Defaults to `separator` for headers, and for items to `option` when the items of the list bind `selected` - * and to `listitem` otherwise. + * Defaults to `separator` for headers, and for items to `option` in a listbox and to `listitem` otherwise. * ```typescript * let itemRole = this.listItem.role; * ``` @@ -272,7 +274,7 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { @HostBinding('attr.role') @Input() public get role() { - return this._role ? this._role : this.isHeader ? 'separator' : this.list.selectable ? 'option' : 'listitem'; + return this._role ? this._role : this.isHeader ? 'separator' : this.list.isListbox ? 'option' : 'listitem'; } public set role(val: string) { @@ -306,23 +308,32 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { public set selected(value: boolean) { this._selected = value; - this.list.selectionItems.add(this); } /** * @hidden * @internal - * In a list whose items bind `selected`, the options are tab stops that expose their selected state - * and are described by the header of their group, unless they have their own `aria-description`. - * The headers are hidden from assistive technology. Called by the list after rendering. - */ - public updateAttributes(selectable: boolean, header: IgxListItemComponent | null) { - const option = selectable && !this.isHeader; - this.list.syncAttribute(this.element, 'tabindex', option ? '0' : null); - this.list.syncAttribute(this.element, 'aria-selected', option ? String(this.selected) : null); - this.list.syncAttribute(this.element, 'aria-hidden', selectable && this.isHeader ? 'true' : null); - if (!this._ownDescription) { - this.list.syncAttribute(this.element, 'aria-description', (option && header?.element.textContent.trim()) || null); + * Syncs the listbox attributes of the item. Options expose their selected state, only the active one is a tab stop, + * and they are described by the header of their group, unless they have their own `aria-describedby`. + * Headers are hidden from assistive technology and get an `id` when they have none, so options can point to them. + * Called by the list after rendering. + * + * @param listbox Whether the list is a listbox. + * @param tabStop Whether the item is the active option. + * @param header The header of the item's group. + */ + public updateAttributes(listbox: boolean, tabStop: boolean, header: IgxListItemComponent | null) { + const option = listbox && !this.isHeader; + syncAttribute(this.element, 'tabindex', option ? (tabStop ? '0' : '-1') : null); + syncAttribute(this.element, 'aria-selected', option ? String(this.selected) : null); + syncAttribute(this.element, 'aria-hidden', listbox && this.isHeader ? 'true' : null); + if (listbox && this.isHeader && !this.element.id) { + this.element.id = `igx-list-header-${NEXT_HEADER_ID++}`; + } + const describedBy = this.element.getAttribute('aria-describedby'); + if (describedBy === null || describedBy === this._describedBy) { + this._describedBy = (option && header?.element.id) || null; + syncAttribute(this.element, 'aria-describedby', this._describedBy); } } @@ -359,6 +370,12 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { return false; } + /** @hidden @internal Applies the option style when the item is an option of a listbox. */ + @HostBinding('class.igx-list-item--option') + public get optionStyle(): boolean { + return !this.isHeader && this.list.isListbox; + } + /** * Returns string value which describes the display mode of the `list item`. * ```typescript @@ -394,7 +411,6 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { */ public ngOnDestroy() { this._gestures?.destroy(); - this.list.selectionItems.delete(this); } /** diff --git a/projects/igniteui-angular/list/src/list/list.common.ts b/projects/igniteui-angular/list/src/list/list.common.ts index ea69407ae7c..1c1c77305ad 100644 --- a/projects/igniteui-angular/list/src/list/list.common.ts +++ b/projects/igniteui-angular/list/src/list/list.common.ts @@ -29,39 +29,25 @@ export class IgxListBaseDirective { /** * @hidden * @internal - * The items that bind `selected`. + * Whether the list follows the ARIA listbox pattern. */ - public readonly selectionItems = new Set<{ isHeader: boolean }>(); - - /** - * @hidden - * @internal - * Whether an item that is not a header binds `selected`. - * Such a list follows the ARIA listbox pattern. - */ - public get selectable(): boolean { - for (const item of this.selectionItems) { - if (!item.isHeader) { - return true; - } - } + public get isListbox(): boolean { return false; } +} - /** - * @hidden - * @internal - * Sets or removes (with `null`) an attribute of the list or one of its items, when it changes. - */ - public syncAttribute(element: Element, name: string, value: string | null) { - if (element.getAttribute(name) === value) { - return; - } - if (value === null) { - element.removeAttribute(name); - } else { - element.setAttribute(name, value); - } +/** + * @hidden + * Sets an attribute, or removes it with `null`, only when its value changes. + */ +export function syncAttribute(element: Element, name: string, value: string | null) { + if (element.getAttribute(name) === value) { + return; + } + if (value === null) { + element.removeAttribute(name); + } else { + element.setAttribute(name, value); } } diff --git a/projects/igniteui-angular/list/src/list/list.component.html b/projects/igniteui-angular/list/src/list/list.component.html index 46bafca512b..0ddc2d33e13 100644 --- a/projects/igniteui-angular/list/src/list/list.component.html +++ b/projects/igniteui-angular/list/src/list/list.component.html @@ -7,7 +7,7 @@ -
+
{{resourceStrings.igx_list_loading}}
diff --git a/projects/igniteui-angular/list/src/list/list.component.spec.ts b/projects/igniteui-angular/list/src/list/list.component.spec.ts index 44b5f58dc50..2a859511e00 100644 --- a/projects/igniteui-angular/list/src/list/list.component.spec.ts +++ b/projects/igniteui-angular/list/src/list/list.component.spec.ts @@ -5,7 +5,7 @@ import { IgxListItemComponent } from './list-item.component'; import { IgxListPanState } from './list.common'; import { IgxListActionDirective, IgxListComponent, IgxListLineDirective, IgxListLineSubTitleDirective, IgxListLineTitleDirective, IgxListThumbnailDirective, IListItemClickEventArgs } from './list.component'; -import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent, SelectableListComponent, GroupedSelectableListComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent } from '../../../test-utils/list-components.spec'; +import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent, ListboxComponent, GroupedListboxComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent } from '../../../test-utils/list-components.spec'; import { nextFrame } from '../../../test-utils/ui-interactions.spec'; import { advance, useFakeClock } from '../../../test-utils/helper-utils.spec'; import { GridFunctions } from '../../../test-utils/grid-functions.spec'; @@ -32,8 +32,8 @@ describe('List', () => { ListWithIgxForAndScrollingComponent, ListDirectivesComponent, ListWithSelectedItemComponent, - SelectableListComponent, - GroupedSelectableListComponent, + ListboxComponent, + GroupedListboxComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent ] @@ -762,23 +762,23 @@ describe('List', () => { expect(headerItem.element.classList.contains('igx-list__item-base--selected')).toBe(false); }); - describe('Selectable list', () => { - let fixture: ComponentFixture; + describe('Listbox', () => { + let fixture: ComponentFixture; let list: IgxListComponent; - const pressKey = (target: HTMLElement, key: string): KeyboardEvent => { - const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true }); + const pressKey = (target: HTMLElement, key: string, repeat = false): KeyboardEvent => { + const event = new KeyboardEvent('keydown', { key, repeat, bubbles: true, cancelable: true }); target.dispatchEvent(event); return event; }; beforeEach(() => { - fixture = TestBed.createComponent(SelectableListComponent); + fixture = TestBed.createComponent(ListboxComponent); list = fixture.componentInstance.list; fixture.detectChanges(); }); - it('should keep the attributes set by the app when no item binds selected', () => { + it('should keep the attributes set by the app on a listbox that manages the focus with aria-activedescendant', () => { const ownFixture = TestBed.createComponent(ListWithOwnAttributesComponent); ownFixture.detectChanges(); const ownList = ownFixture.componentInstance.list; @@ -788,9 +788,20 @@ describe('List', () => { expect(header.element.getAttribute('aria-hidden')).toBe('true'); expect(item.element.getAttribute('tabindex')).toBe('-1'); expect(item.element.getAttribute('aria-selected')).toBe('true'); + expect(item.element.classList).not.toContain('igx-list-item--option'); + + ownList.isLoading = true; + ownFixture.detectChanges(); + expect(ownList.element.nativeElement.hasAttribute('aria-busy')).toBe(false); + + const clickSpy = vi.fn(); + ownList.itemClicked.subscribe(clickSpy); + expect(pressKey(item.element, 'ArrowDown').defaultPrevented).toBe(false); + expect(pressKey(item.element, ' ').defaultPrevented).toBe(false); + expect(clickSpy).not.toHaveBeenCalled(); }); - it('should keep the attributes bound by the app when no item binds selected', () => { + it('should keep the attributes bound by the app when the list is not a listbox', () => { const boundFixture = TestBed.createComponent(ListWithBoundAttributesComponent); boundFixture.detectChanges(); const boundList = boundFixture.componentInstance.list; @@ -800,7 +811,7 @@ describe('List', () => { expect(header.element.getAttribute('aria-hidden')).toBe('true'); expect(item.element.getAttribute('tabindex')).toBe('0'); expect(item.element.getAttribute('aria-selected')).toBe('true'); - expect(item.element.getAttribute('aria-description')).toBe('Note'); + expect(item.element.getAttribute('aria-describedby')).toBe('Note'); boundFixture.componentInstance.tabIndex = '-1'; boundFixture.componentInstance.selected = 'false'; @@ -810,8 +821,9 @@ describe('List', () => { expect(item.element.getAttribute('aria-selected')).toBe('false'); }); - it('should leave a list whose items do not bind selected unchanged', () => { - const plainFixture = TestBed.createComponent(ListWithHeaderComponent); + it('should leave a list that is not a listbox unchanged, even when its items bind selected', () => { + const plainFixture = TestBed.createComponent(ListboxComponent); + plainFixture.componentInstance.listbox = false; plainFixture.detectChanges(); const plainList = plainFixture.componentInstance.list; const listElement = plainList.element.nativeElement as HTMLElement; @@ -826,22 +838,22 @@ describe('List', () => { expect(item.element.getAttribute('role')).toBe('listitem'); expect(item.element.hasAttribute('tabindex')).toBe(false); expect(item.element.hasAttribute('aria-selected')).toBe(false); - expect(item.element.hasAttribute('aria-description')).toBe(false); + expect(item.element.hasAttribute('aria-describedby')).toBe(false); }); expect(pressKey(plainList.items[0].element, 'ArrowDown').defaultPrevented).toBe(false); }); - it('should be a focusable listbox with option items that expose their selected state', () => { + it('should be a listbox that only owns options and hidden headers, and exposes their selected state', () => { const listElement = list.element.nativeElement as HTMLElement; const [header, ...items] = list.children.toArray(); + const owned = Array.from(listElement.children).filter(child => child.getAttribute('aria-hidden') !== 'true'); expect(listElement.getAttribute('role')).toBe('listbox'); - expect(listElement.getAttribute('tabindex')).toBe('0'); - expect(header.element.getAttribute('role')).toBe('separator'); - expect(header.element.getAttribute('aria-hidden')).toBe('true'); + expect(listElement.hasAttribute('tabindex')).toBe(false); + expect(owned.map(child => child.getAttribute('role'))).toEqual(['option', 'option', 'option']); expect(header.element.hasAttribute('tabindex')).toBe(false); - expect(items.map(i => i.element.getAttribute('role'))).toEqual(['option', 'option', 'option']); - expect(items.map(i => i.element.getAttribute('tabindex'))).toEqual(['0', '0', '0']); + expect(header.element.classList).not.toContain('igx-list-item--option'); + expect(items.every(i => i.element.classList.contains('igx-list-item--option'))).toBe(true); expect(items.map(i => i.element.getAttribute('aria-selected'))).toEqual(['false', 'true', 'false']); fixture.componentInstance.selectedId = 3; @@ -849,14 +861,43 @@ describe('List', () => { expect(items.map(i => i.element.getAttribute('aria-selected'))).toEqual(['false', 'false', 'true']); }); - it('should go back to the list roles when the items that bind selected are removed', () => { - fixture.componentInstance.items = []; + it('should keep a single tab stop on the option focused last, else the selected one, else the first one', () => { + const items = list.items; + const tabIndexes = () => list.items.map(i => i.element.getAttribute('tabindex')); + expect(tabIndexes()).toEqual(['-1', '0', '-1']); + + fixture.componentInstance.selectedId = null; + fixture.detectChanges(); + expect(tabIndexes()).toEqual(['0', '-1', '-1']); + + items[0].element.focus(); + pressKey(items[0].element, 'End'); + fixture.detectChanges(); + expect(document.activeElement).toBe(items[2].element); + expect(tabIndexes()).toEqual(['-1', '-1', '0']); + + items[2].hidden = true; + fixture.detectChanges(); + expect(tabIndexes()).toEqual(['0', '-1', '-1']); + + fixture.componentInstance.items = fixture.componentInstance.items.slice(1); + fixture.detectChanges(); + expect(tabIndexes()).toEqual(['0', '-1']); + }); + + it('should reset the list and its items when its role is no longer listbox', () => { + fixture.componentInstance.listbox = false; fixture.detectChanges(); const listElement = list.element.nativeElement as HTMLElement; expect(listElement.getAttribute('role')).toBe('list'); - expect(listElement.hasAttribute('tabindex')).toBe(false); expect(list.children.first.element.hasAttribute('aria-hidden')).toBe(false); + list.items.forEach(item => { + expect(item.element.getAttribute('role')).toBe('listitem'); + expect(item.element.hasAttribute('tabindex')).toBe(false); + expect(item.element.hasAttribute('aria-selected')).toBe(false); + expect(item.element.classList).not.toContain('igx-list-item--option'); + }); }); it('should keep the roles set by the app and not follow the listbox pattern with a role other than listbox', () => { @@ -877,15 +918,41 @@ describe('List', () => { expect(listElement.hasAttribute('role')).toBe(false); }); - it('should describe every option with the header of its group, unless it has its own description', () => { - const groupedFixture = TestBed.createComponent(GroupedSelectableListComponent); + it('should describe every option with the header of its group, unless it has its own aria-describedby', () => { + const groupedFixture = TestBed.createComponent(GroupedListboxComponent); + groupedFixture.detectChanges(); + const groupedList = groupedFixture.componentInstance.list; + const [employees, contractors] = groupedList.headers; + const [ungrouped, item1, item2, item3, item4] = groupedList.items; + + expect(employees.element.id).toBeTruthy(); + expect(contractors.element.id).toBeTruthy(); + expect(ungrouped.element.hasAttribute('aria-describedby')).toBe(false); + expect(item1.element.getAttribute('aria-describedby')).toBe(employees.element.id); + expect(item2.element.getAttribute('aria-describedby')).toBe('item-2-note'); + expect(item3.element.getAttribute('aria-describedby')).toBe('item-3-note'); + expect(item4.element.getAttribute('aria-describedby')).toBe(contractors.element.id); + + groupedFixture.componentInstance.note = 'item-3-other-note'; + groupedFixture.detectChanges(); + expect(item3.element.getAttribute('aria-describedby')).toBe('item-3-other-note'); + + groupedFixture.componentInstance.note = null; groupedFixture.detectChanges(); - const [ungrouped, item1, item2, item3] = groupedFixture.componentInstance.list.items; + expect(item3.element.getAttribute('aria-describedby')).toBe(employees.element.id); + }); + + it('should mark the listbox busy and hide the loading message while loading', () => { + const listElement = list.element.nativeElement as HTMLElement; + list.isLoading = true; + fixture.detectChanges(); + expect(listElement.getAttribute('aria-busy')).toBe('true'); + expect(listElement.querySelector('.igx-list__message').getAttribute('aria-hidden')).toBe('true'); - expect(ungrouped.element.hasAttribute('aria-description')).toBe(false); - expect(item1.element.getAttribute('aria-description')).toBe('Employees'); - expect(item2.element.getAttribute('aria-description')).toBe('Part-time'); - expect(item3.element.getAttribute('aria-description')).toBe('Contractors'); + list.isLoading = false; + fixture.detectChanges(); + expect(listElement.hasAttribute('aria-busy')).toBe(false); + expect(listElement.querySelector('.igx-list__message')).toBeNull(); }); describe('Keyboard navigation', () => { @@ -909,8 +976,7 @@ describe('List', () => { expect(document.activeElement).toBe(items[0].element); }); - it('should move the focus to the first and last item with Home and End, also from the list', () => { - const listElement = list.element.nativeElement as HTMLElement; + it('should move the focus to the first and last item with Home and End', () => { const items = list.items; items[1].element.focus(); @@ -919,14 +985,25 @@ describe('List', () => { pressKey(items[2].element, 'Home'); expect(document.activeElement).toBe(items[0].element); + }); - listElement.focus(); - pressKey(listElement, 'ArrowDown'); - expect(document.activeElement).toBe(items[0].element); - - listElement.focus(); - pressKey(listElement, 'ArrowUp'); - expect(document.activeElement).toBe(items[2].element); + it('should follow the displayed order of virtualized items', async () => { + const forFixture = TestBed.createComponent(ListWithIgxForAndScrollingComponent); + forFixture.componentInstance.listbox = true; + forFixture.detectChanges(); + await nextFrame(); + // Scrolling down and back up reuses the views, so the children are no longer in the displayed order. + for (const index of [8, 0]) { + forFixture.componentInstance.igxFor.scrollTo(index); + await nextFrame(); + forFixture.detectChanges(); + } + + const items = forFixture.componentInstance.forOfList.items; + items[0].element.focus(); + pressKey(items[0].element, 'ArrowDown'); + expect(document.activeElement).toBe(items[1].element); + expect(items[1].index).toBe(1); }); it('should skip hidden items', () => { @@ -947,10 +1024,11 @@ describe('List', () => { expect(pressKey(items[1].element, 'Enter').defaultPrevented).toBe(true); expect(pressKey(items[1].element, ' ').defaultPrevented).toBe(true); + expect(pressKey(items[1].element, ' ', true).defaultPrevented).toBe(true); expect(clickedItems).toEqual([items[1], items[1]]); }); - it('should not handle keys pressed in the content of an item, or Enter and Space on the list', () => { + it('should not handle keys pressed in the content of an item or on the list', () => { const clickSpy = vi.fn(); list.itemClicked.subscribe(clickSpy); const listElement = list.element.nativeElement as HTMLElement; diff --git a/projects/igniteui-angular/list/src/list/list.component.ts b/projects/igniteui-angular/list/src/list/list.component.ts index 0a5b1770e3a..8a9b8b51056 100644 --- a/projects/igniteui-angular/list/src/list/list.component.ts +++ b/projects/igniteui-angular/list/src/list/list.component.ts @@ -29,7 +29,8 @@ import { IgxEmptyListTemplateDirective, IgxListPanState, IgxListItemLeftPanningTemplateDirective, - IgxListItemRightPanningTemplateDirective + IgxListItemRightPanningTemplateDirective, + syncAttribute } from './list.common'; import { IBaseEventArgs } from 'igniteui-angular/core'; import { IListResourceStrings, ListResourceStringsEN } from 'igniteui-angular/core'; @@ -499,38 +500,52 @@ export class IgxListComponent extends IgxListBaseDirective { return null!; } - /** Whether the list has been selectable, so its attributes and those of its items are kept in sync. */ + /** Whether the list was a listbox at the last render, so its items are reset when it stops being one. */ private _synced = false; + /** The option that was focused last, which keeps the tab stop. */ + private _activeItem: IgxListItemComponent | null = null; + /** - * A list whose items bind `selected` is a tab stop, and so are its options. - * A list that has never been selectable and its items are left untouched. + * Syncs the listbox attributes of the list and its items, in the order the items are displayed. + * Only the active option is a tab stop: the one focused last, else the first selected option, else the first option. + * While loading, the listbox is marked busy. A list that is not a listbox, and has not just stopped being one, is left untouched. */ private updateAttributes() { - const selectable = this.selectable; - if (!selectable && !this._synced) { + const listbox = this.isListbox; + if (!listbox && !this._synced) { return; } - this._synced = true; - this.syncAttribute(this.element.nativeElement, 'tabindex', selectable ? '0' : null); + this._synced = listbox; + syncAttribute(this.element.nativeElement, 'aria-busy', listbox && this.isLoading ? 'true' : null); + const children = this.sortedChildren.filter(item => item.list === this); + const options = children.filter(item => !item.isHeader && !item.hidden); + const tabStop = options.includes(this._activeItem!) ? this._activeItem + : options.find(item => item.selected) ?? options[0]; let header: IgxListItemComponent | null = null; - for (const item of this.children) { - if (item.list === this) { - header = item.isHeader ? item : header; - item.updateAttributes(selectable, header); - } + for (const item of children) { + header = item.isHeader ? item : header; + item.updateAttributes(listbox, item === tabStop, header); } } - /** The role set by the app. While not set, the role depends on whether the list is selectable. */ - private _role: string | undefined; + private _role = 'list'; /** * Gets/Sets the `role` attribute value. * * @remarks - * Defaults to `listbox` when its items bind `selected` and to `list` otherwise. - * Setting a role other than `listbox` turns off the listbox roles, the focus and the keyboard navigation of the list and its items. + * Defaults to `list`. With `listbox`, the list follows the ARIA listbox pattern: its items become options + * that expose their `selected` state, Tab focuses the selected option, Arrow Up/Down and Home/End + * move between the options, and Enter/Space click the focused option. + * A listbox that manages the focus itself with `aria-activedescendant` is left as it is. + * + * @example + * ```html + * + * Kate + * + * ``` * * @example * ```typescript @@ -540,7 +555,7 @@ export class IgxListComponent extends IgxListBaseDirective { @HostBinding('attr.role') @Input() public get role() { - return this._role !== undefined ? this._role : this.selectable ? 'listbox' : 'list'; + return this._role; } public set role(val: string) { @@ -550,37 +565,52 @@ export class IgxListComponent extends IgxListBaseDirective { /** * @hidden * @internal - * Whether the list follows the ARIA listbox pattern: an item that is not a header binds `selected`, - * and no role other than `listbox` is set on the list. + * Whether the list follows the ARIA listbox pattern: its role is `listbox`, + * and it does not manage the focus itself with `aria-activedescendant`, like the grid's Excel-style filter list. */ - @HostBinding('class.igx-list--selectable') - public override get selectable(): boolean { - return (this._role === undefined || this._role === 'listbox') && super.selectable; + public override get isListbox(): boolean { + return this._role === 'listbox' && !this.element.nativeElement.hasAttribute('aria-activedescendant'); } /** * @hidden * @internal - * Moves the focus between the items of a list whose items bind `selected`. - * ArrowDown/ArrowUp go to the next/previous item, Home/End to the first/last one. - * Enter/Space activate the focused item like a click, so `itemClicked` and its `click` handlers fire. - * Keys pressed in the content of an item are not handled. + * Keeps the tab stop on the option that was focused last. + * + * @param event The focusin event of the list. + */ + @HostListener('focusin', ['$event']) + public onFocusIn(event: FocusEvent) { + const target = event.composedPath()[0]; + this._activeItem = this.items.find(item => item.list === this && item.element === target) ?? this._activeItem; + } + + /** + * @hidden + * @internal + * Moves the focus between the options of a listbox. + * ArrowDown/ArrowUp go to the next/previous option, Home/End to the first/last one. + * Enter/Space activate the focused option like a click, so `itemClicked` and its `click` handlers fire, + * once per key press, also when the key is held down. Keys pressed in the content of an option are not handled. + * + * @param event The keydown event that bubbled up from an option. */ @HostListener('keydown', ['$event']) public onKeydown(event: KeyboardEvent) { - if (!this.selectable) { + if (!this.isListbox) { return; } - const items = this.children.filter(item => item.list === this && !item.isHeader && !item.hidden); - const current = items.findIndex(item => item.element === event.target); - if (current === -1 && event.target !== this.element.nativeElement) { + const target = event.composedPath()[0]; + const items = this.items.filter(item => item.list === this && !item.hidden); + const current = items.findIndex(item => item.element === target); + if (current === -1) { return; } if (event.key === 'Enter' || event.key === ' ') { - if (current !== -1) { - event.preventDefault(); + event.preventDefault(); + if (!event.repeat) { items[current].element.click(); } return; @@ -592,7 +622,7 @@ export class IgxListComponent extends IgxListBaseDirective { next = Math.min(current + 1, items.length - 1); break; case 'ArrowUp': - next = current === -1 ? items.length - 1 : Math.max(current - 1, 0); + next = Math.max(current - 1, 0); break; case 'Home': next = 0; @@ -605,7 +635,7 @@ export class IgxListComponent extends IgxListBaseDirective { } event.preventDefault(); - items[next]?.element.focus(); + items[next].element.focus(); } /** diff --git a/projects/igniteui-angular/list/src/list/themes/_base.scss b/projects/igniteui-angular/list/src/list/themes/_base.scss index 33df8749baf..0114087968e 100644 --- a/projects/igniteui-angular/list/src/list/themes/_base.scss +++ b/projects/igniteui-angular/list/src/list/themes/_base.scss @@ -53,14 +53,6 @@ $theme: digest-schema($light-list); z-index: 1; } } - - @include m(selectable) { - @include e(item-base) { - &:focus-visible { - outline: none; - } - } - } } @include b(igx-list-item) { @@ -185,6 +177,17 @@ $theme: digest-schema($light-list); background: var-get($theme, 'header-background'); } + @include m(option) { + &:focus-visible { + outline: none; + + @include e(content) { + outline: var(--_focus-ring-width, #{rem(1px)}) solid var-get($theme, 'item-focus-outline-color'); + outline-offset: calc(var(--_focus-ring-width, #{rem(1px)}) * -1); + } + } + } + @include m(base) { border-radius: var-get($theme, 'item-border-radius'); border-bottom: var-get($theme, 'border-width') solid diff --git a/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss b/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss index 50ae9a13f28..98116369e63 100644 --- a/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss +++ b/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss @@ -9,6 +9,7 @@ @include themed-block(igx-list-item, indigo) { --_padding-block: #{pad-block(rem(4px), rem(6px), rem(8px))}; --_padding-inline: #{pad-block(rem(8px), rem(12px), rem(16px))}; + --_focus-ring-width: #{rem(2px)}; igx-avatar { --ig-size: 2; diff --git a/projects/igniteui-angular/test-utils/list-components.spec.ts b/projects/igniteui-angular/test-utils/list-components.spec.ts index 6033a6bbee4..5a269babd4f 100644 --- a/projects/igniteui-angular/test-utils/list-components.spec.ts +++ b/projects/igniteui-angular/test-utils/list-components.spec.ts @@ -87,7 +87,7 @@ export class ListWithSelectedItemComponent extends BasicListComponent { @Component({ template: `
- + Header @for (item of items; track item.id) { @@ -99,7 +99,8 @@ export class ListWithSelectedItemComponent extends BasicListComponent { changeDetection: ChangeDetectionStrategy.Eager, imports: [IgxListComponent, IgxListItemComponent, IgxListLineTitleDirective] }) -export class SelectableListComponent extends BasicListComponent { +export class ListboxComponent extends BasicListComponent { + public listbox = true; public selectedId: number | null = 2; public items = [ { id: 1, name: 'Item 1' }, @@ -111,27 +112,29 @@ export class SelectableListComponent extends BasicListComponent { @Component({ template: `
- + Ungrouped Employees Item 1 - Item 2 + Item 2 + Item 3 Contractors - Item 3 + Item 4
`, changeDetection: ChangeDetectionStrategy.Eager, imports: [IgxListComponent, IgxListItemComponent] }) -export class GroupedSelectableListComponent extends BasicListComponent { +export class GroupedListboxComponent extends BasicListComponent { + public note: string | null = 'item-3-note'; } @Component({ template: `
- + - Item 1 + Item 1
`, changeDetection: ChangeDetectionStrategy.Eager, @@ -145,7 +148,7 @@ export class ListWithOwnAttributesComponent extends BasicListComponent {
Header - + Item 1 @@ -292,7 +295,7 @@ export class ListWithPanningTemplatesComponent extends ListWithPanningComponent @Component({ template: ` - +
; + public listbox = false; + public data = [ { key: 1, name: 'John' }, { key: 2, name: 'Brian' }, diff --git a/skills/igniteui-angular-components/references/data-display.md b/skills/igniteui-angular-components/references/data-display.md index 5f0e5102787..1d03130cf88 100644 --- a/skills/igniteui-angular-components/references/data-display.md +++ b/skills/igniteui-angular-components/references/data-display.md @@ -40,6 +40,18 @@ import { IgxIconComponent } from 'igniteui-angular/icon'; Auxiliary directives for list items: `igxListThumbnail`, `igxListAction`, `igxListLine`, `igxListLineTitle`, `igxListLineSubTitle`. +For a list where the user selects items, set `role="listbox"` on it and name it. It becomes an accessible listbox with one tab stop, arrow key navigation and Enter/Space to click the focused option. Bind `[selected]` on the items, add `aria-multiselectable="true"` when more than one item can be selected, and keep focusable controls out of the items (an `inert` checkbox bound to the state is fine). Do not set `aria-activedescendant` on it: a list with that attribute is expected to handle the focus and the keys itself, so the built-in listbox behavior turns off. The keyboard navigation only reaches rendered items, so do not use `role="listbox"` on a list virtualized with `igxFor`: + +```html + + @for (contact of contacts; track contact.id) { + + {{ contact.name }} + + } + +``` + ## Tree ```typescript diff --git a/src/app/list/list.sample.html b/src/app/list/list.sample.html index b67d1549452..bdf497c8c45 100644 --- a/src/app/list/list.sample.html +++ b/src/app/list/list.sample.html @@ -2,7 +2,7 @@
Angular List
- +
deleteDelete @@ -35,12 +35,6 @@

{{ employee.name }}

@if(properties.addIconAction) { info } - @if(properties.addOutlinedButton){ - - } - @if(properties.addContainedButton) { - - } } @@ -72,12 +66,6 @@
WC List
@if(properties.addIconAction) { } - @if(properties.addOutlinedButton){ - Text - } - @if(properties.addContainedButton) { - Call - } } diff --git a/src/app/list/list.sample.ts b/src/app/list/list.sample.ts index fcc3d3e99d3..2464a02f4dd 100644 --- a/src/app/list/list.sample.ts +++ b/src/app/list/list.sample.ts @@ -9,10 +9,8 @@ import { FormsModule } from '@angular/forms'; import { IGX_LIST_DIRECTIVES, IgxAvatarComponent, - IgxButtonDirective, IgxCheckboxComponent, IgxIconComponent, - IgxButtonModule, } from 'igniteui-angular'; import { defineComponents, @@ -22,7 +20,6 @@ import { IgcListItemComponent, IgcIconComponent, IgcCheckboxComponent, - IgcButtonComponent, registerIconFromText, } from 'igniteui-webcomponents'; import { @@ -38,7 +35,6 @@ defineComponents( IgcAvatarComponent, IgcIconComponent, IgcCheckboxComponent, - IgcButtonComponent ); const icons = [ @@ -77,9 +73,6 @@ interface Employee { IgxIconComponent, IgxCheckboxComponent, IgxAvatarComponent, - IgxButtonModule, - IgxButtonModule, - IgxButtonDirective, ], changeDetection: ChangeDetectionStrategy.Eager }) @@ -127,20 +120,6 @@ export class ListSampleComponent { defaultValue: true } }, - addOutlinedButton: { - label: 'Add Outlined Button', - control: { - type: 'boolean', - defaultValue: false - } - }, - addContainedButton: { - label: 'Add Contained Button', - control: { - type: 'boolean', - defaultValue: false - } - }, enablePanning: { label: 'Item Panning', control: { From e8cde4fcdcc304d73d2ed319b06c8fa28498af9b Mon Sep 17 00:00:00 2001 From: Adrian Petrov Date: Mon, 23 Nov 2026 18:20:24 +0200 Subject: [PATCH 3/4] fix(list): address latest comments --- CHANGELOG.md | 2 +- projects/igniteui-angular/list/README.md | 3 +- .../list/src/list/list-item.component.ts | 16 +++- .../list/src/list/list.component.html | 10 ++- .../list/src/list/list.component.spec.ts | 73 +++++++++++++++---- .../list/src/list/list.component.ts | 38 +++++++++- .../list/src/list/themes/_base.scss | 11 +++ .../list/src/list/themes/shared/_indigo.scss | 3 +- projects/igniteui-angular/package.json | 2 +- .../test-utils/list-components.spec.ts | 21 ++++++ 10 files changed, 153 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6697a945b..9711dd66474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ All notable changes for each version of this project will be documented in this ### New Features - `IgxListComponent`, `IgxListItemComponent` - - Setting `role="listbox"` on the list makes it an accessible listbox (#17952): items get `role="option"` with `aria-selected` from their `selected` state, and the list has a single tab stop on the option that was focused last, else the first selected one, else the first one. Arrow Up/Down and Home/End move between options, and Enter/Space click the focused option, so `itemClicked` fires. While `isLoading` is set, the list has `aria-busy="true"`. The focused option shows an inset focus ring, also when it is selected, colored by the new `item-focus-outline-color` token of the list theme. Lists with another role, and listboxes that manage the focus with `aria-activedescendant`, are unchanged. A list that already sets `role="listbox"` now gets this behavior. + - Setting `role="listbox"` on the list makes it an accessible listbox (#17952): items get `role="option"` with `aria-selected` from their `selected` state, and the list has a single tab stop on the option that was focused last, else the first selected one, else the first one. Arrow Up/Down and Home/End move between options, and Enter/Space click the focused option, so `itemClicked` fires. While `isLoading` is set, the list has `aria-busy="true"`. While the list has no options, the list itself is the tab stop and its empty or loading message is read as an option. The focused option shows an inset focus ring, also when it is selected, colored by the new `item-focus-outline-color` token of the list theme. Lists with another role, and listboxes that manage the focus with `aria-activedescendant`, are unchanged. A list that already sets `role="listbox"` now gets this behavior. - In a listbox, headers act as group names: each option points to the header above it with `aria-describedby`, so screen readers announce the group with every option, and the headers themselves are hidden from screen readers. An option that has its own `aria-describedby`, set or bound in the template, keeps it. - Recommended: give a listbox an `aria-label`, so it is announced when the focus moves into the list. Set `aria-multiselectable="true"` when more than one item can be selected, and avoid focusable controls inside the items. If an item needs a selection control, such as a checkbox, make it `inert` so it does not interfere with the keyboard navigation and selection, and bind it to the item's selected state. diff --git a/projects/igniteui-angular/list/README.md b/projects/igniteui-angular/list/README.md index e83d63e1a76..4633f2e0b74 100644 --- a/projects/igniteui-angular/list/README.md +++ b/projects/igniteui-angular/list/README.md @@ -74,7 +74,8 @@ Set `role="listbox"` on the list to make it an accessible [listbox](https://www. - The list has a single tab stop. Tab focuses the option that was focused last, else the first selected option, else the first option, and the next Tab leaves the list. Headers and hidden items are skipped. - Headers act as group names: they are hidden from screen readers, and each option points to the header above it with `aria-describedby`. A header without an `id` gets one. A screen reader reads the option content followed by the group name, e.g. "Kate, selected, 1 of 8, Employees". An option that has its own `aria-describedby`, set or bound in the template, keeps it. - The focused option shows an inset focus ring, also when it is selected. Its color is the `item-focus-outline-color` of the list theme. -- While `isLoading` is set, the list has `aria-busy="true"`. When the list has items, the default loading message is hidden from screen readers. +- While `isLoading` is set, the list has `aria-busy="true"`. +- While the list has no options, the list itself is the tab stop and shows the focus ring, and its empty or loading message, the default or a custom template, is read as an option. When options are added while the list has the focus, the focus moves to them. While the list has options, the loading message is hidden from screen readers. | Key | Action | | :--- | :--- | diff --git a/projects/igniteui-angular/list/src/list/list-item.component.ts b/projects/igniteui-angular/list/src/list/list-item.component.ts index 9d73606068a..cddd51d4c12 100644 --- a/projects/igniteui-angular/list/src/list/list-item.component.ts +++ b/projects/igniteui-angular/list/src/list/list-item.component.ts @@ -46,6 +46,9 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { /** The `aria-describedby` the list set last, to tell it apart from one set or bound by the app, which is kept. */ private _describedBy: string | null = null; + /** The `id` the item generated as a header of a listbox, so it is removed when the item is no longer one. */ + private _headerId: string | null = null; + /** * Provides a reference to the template's base element shown when left panning a list item. * ```typescript @@ -316,6 +319,7 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { * Syncs the listbox attributes of the item. Options expose their selected state, only the active one is a tab stop, * and they are described by the header of their group, unless they have their own `aria-describedby`. * Headers are hidden from assistive technology and get an `id` when they have none, so options can point to them. + * The generated `id` is removed when the list is no longer a listbox. * Called by the list after rendering. * * @param listbox Whether the list is a listbox. @@ -327,8 +331,16 @@ export class IgxListItemComponent implements IListChild, OnInit, OnDestroy { syncAttribute(this.element, 'tabindex', option ? (tabStop ? '0' : '-1') : null); syncAttribute(this.element, 'aria-selected', option ? String(this.selected) : null); syncAttribute(this.element, 'aria-hidden', listbox && this.isHeader ? 'true' : null); - if (listbox && this.isHeader && !this.element.id) { - this.element.id = `igx-list-header-${NEXT_HEADER_ID++}`; + if (listbox && this.isHeader) { + if (!this.element.id) { + this._headerId = `igx-list-header-${NEXT_HEADER_ID++}`; + this.element.id = this._headerId; + } + } else if (this._headerId !== null) { + if (this.element.id === this._headerId) { + this.element.removeAttribute('id'); + } + this._headerId = null; } const describedBy = this.element.getAttribute('aria-describedby'); if (describedBy === null || describedBy === this._describedBy) { diff --git a/projects/igniteui-angular/list/src/list/list.component.html b/projects/igniteui-angular/list/src/list/list.component.html index 0ddc2d33e13..16f5a8454fa 100644 --- a/projects/igniteui-angular/list/src/list/list.component.html +++ b/projects/igniteui-angular/list/src/list/list.component.html @@ -7,12 +7,16 @@ -
+
{{resourceStrings.igx_list_loading}}
@if (!children || children.length === 0 || isLoading) { - - +
+ + +
} diff --git a/projects/igniteui-angular/list/src/list/list.component.spec.ts b/projects/igniteui-angular/list/src/list/list.component.spec.ts index 2a859511e00..06214cf2728 100644 --- a/projects/igniteui-angular/list/src/list/list.component.spec.ts +++ b/projects/igniteui-angular/list/src/list/list.component.spec.ts @@ -5,7 +5,7 @@ import { IgxListItemComponent } from './list-item.component'; import { IgxListPanState } from './list.common'; import { IgxListActionDirective, IgxListComponent, IgxListLineDirective, IgxListLineSubTitleDirective, IgxListLineTitleDirective, IgxListThumbnailDirective, IListItemClickEventArgs } from './list.component'; -import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent, ListboxComponent, GroupedListboxComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent } from '../../../test-utils/list-components.spec'; +import { ListWithHeaderComponent, ListWithPanningComponent, EmptyListComponent, CustomEmptyListComponent, ListLoadingComponent, ListWithPanningTemplatesComponent, ListCustomLoadingComponent, ListWithIgxForAndScrollingComponent, TwoHeadersListComponent, TwoHeadersListNoPanningComponent, ListDirectivesComponent, ListWithSelectedItemComponent, ListboxComponent, GroupedListboxComponent, ListWithOwnAttributesComponent, ListWithBoundAttributesComponent, EmptyListboxComponent } from '../../../test-utils/list-components.spec'; import { nextFrame } from '../../../test-utils/ui-interactions.spec'; import { advance, useFakeClock } from '../../../test-utils/helper-utils.spec'; import { GridFunctions } from '../../../test-utils/grid-functions.spec'; @@ -767,7 +767,7 @@ describe('List', () => { let list: IgxListComponent; const pressKey = (target: HTMLElement, key: string, repeat = false): KeyboardEvent => { - const event = new KeyboardEvent('keydown', { key, repeat, bubbles: true, cancelable: true }); + const event = new KeyboardEvent('keydown', { key, repeat, bubbles: true, cancelable: true, composed: true }); target.dispatchEvent(event); return event; }; @@ -886,12 +886,16 @@ describe('List', () => { }); it('should reset the list and its items when its role is no longer listbox', () => { + const header = list.children.first.element; + expect(header.id).toMatch(/^igx-list-header-\d+$/); + fixture.componentInstance.listbox = false; fixture.detectChanges(); const listElement = list.element.nativeElement as HTMLElement; expect(listElement.getAttribute('role')).toBe('list'); - expect(list.children.first.element.hasAttribute('aria-hidden')).toBe(false); + expect(header.hasAttribute('aria-hidden')).toBe(false); + expect(header.hasAttribute('id')).toBe(false); list.items.forEach(item => { expect(item.element.getAttribute('role')).toBe('listitem'); expect(item.element.hasAttribute('tabindex')).toBe(false); @@ -942,17 +946,49 @@ describe('List', () => { expect(item3.element.getAttribute('aria-describedby')).toBe(employees.element.id); }); - it('should mark the listbox busy and hide the loading message while loading', () => { - const listElement = list.element.nativeElement as HTMLElement; - list.isLoading = true; - fixture.detectChanges(); + it('should be the tab stop with its empty or loading message as an option while it has no options', () => { + const emptyFixture = TestBed.createComponent(EmptyListboxComponent); + emptyFixture.detectChanges(); + const emptyList = emptyFixture.componentInstance.list; + const listElement = emptyList.element.nativeElement as HTMLElement; + const message = () => listElement.querySelector('.igx-list__message-wrapper') as HTMLElement; + const owned = () => Array.from(listElement.children).filter(child => child.getAttribute('aria-hidden') !== 'true'); + + expect(listElement.getAttribute('tabindex')).toBe('0'); + expect(listElement.classList).toContain('igx-list--focusable'); + expect(owned()).toEqual([message()]); + expect(message().getAttribute('role')).toBe('option'); + expect(message().textContent.trim()).toBe(emptyList.resourceStrings.igx_list_no_items); + + emptyFixture.componentInstance.isLoading = true; + emptyFixture.detectChanges(); expect(listElement.getAttribute('aria-busy')).toBe('true'); - expect(listElement.querySelector('.igx-list__message').getAttribute('aria-hidden')).toBe('true'); + expect(owned()).toEqual([message()]); + expect(message().getAttribute('role')).toBe('option'); + expect(message().textContent.trim()).toBe('Loading data...'); - list.isLoading = false; - fixture.detectChanges(); + listElement.focus(); + emptyFixture.componentInstance.items = ['Item 1', 'Item 2']; + emptyFixture.detectChanges(); + expect(listElement.hasAttribute('tabindex')).toBe(false); + expect(listElement.classList).not.toContain('igx-list--focusable'); + expect(message().hasAttribute('role')).toBe(false); + expect(message().getAttribute('aria-hidden')).toBe('true'); + expect(owned().map(child => child.getAttribute('role'))).toEqual(['option', 'option']); + expect(document.activeElement).toBe(emptyList.items[0].element); + + emptyFixture.componentInstance.isLoading = false; + emptyFixture.detectChanges(); expect(listElement.hasAttribute('aria-busy')).toBe(false); - expect(listElement.querySelector('.igx-list__message')).toBeNull(); + expect(message()).toBeNull(); + + emptyFixture.componentInstance.items = []; + emptyFixture.componentInstance.listbox = false; + emptyFixture.detectChanges(); + expect(listElement.hasAttribute('tabindex')).toBe(false); + expect(listElement.classList).not.toContain('igx-list--focusable'); + expect(message().hasAttribute('role')).toBe(false); + expect(message().hasAttribute('aria-hidden')).toBe(false); }); describe('Keyboard navigation', () => { @@ -1028,16 +1064,27 @@ describe('List', () => { expect(clickedItems).toEqual([items[1], items[1]]); }); - it('should not handle keys pressed in the content of an item or on the list', () => { + it('should not handle keys pressed in the content of an item, also inside a shadow root, or on the list', () => { const clickSpy = vi.fn(); list.itemClicked.subscribe(clickSpy); const listElement = list.element.nativeElement as HTMLElement; - const title = list.items[0].element.querySelector('[igxListLineTitle]') as HTMLElement; + const option = list.items[0].element; + const title = option.querySelector('[igxListLineTitle]') as HTMLElement; + const shadowHost = document.createElement('div'); + option.appendChild(shadowHost); + const shadowRoot = shadowHost.attachShadow({ mode: 'open' }); + shadowRoot.innerHTML = ''; + const input = shadowRoot.querySelector('input')!; expect(pressKey(title, 'ArrowDown').defaultPrevented).toBe(false); expect(pressKey(title, 'Enter').defaultPrevented).toBe(false); + expect(pressKey(input, 'ArrowDown').defaultPrevented).toBe(false); + expect(pressKey(input, 'Enter').defaultPrevented).toBe(false); + expect(pressKey(input, ' ').defaultPrevented).toBe(false); expect(pressKey(listElement, ' ').defaultPrevented).toBe(false); expect(clickSpy).not.toHaveBeenCalled(); + + expect(pressKey(option, 'ArrowDown').defaultPrevented).toBe(true); }); }); }); diff --git a/projects/igniteui-angular/list/src/list/list.component.ts b/projects/igniteui-angular/list/src/list/list.component.ts index 8a9b8b51056..4d3b4778a0c 100644 --- a/projects/igniteui-angular/list/src/list/list.component.ts +++ b/projects/igniteui-angular/list/src/list/list.component.ts @@ -506,9 +506,27 @@ export class IgxListComponent extends IgxListBaseDirective { /** The option that was focused last, which keeps the tab stop. */ private _activeItem: IgxListItemComponent | null = null; + /** The `tabindex` the list set on itself, so a `tabindex` set by the app is kept. */ + private _tabIndex: string | null = null; + + /** + * @hidden + * @internal + * Whether the list has options that are not hidden. Without them, the empty or loading message of a listbox is an option. + */ + protected get hasOptions(): boolean { + return this.ownItems.some(item => !item.isHeader && !item.hidden); + } + + /** The items of this list, without those of nested lists, in the order they are displayed. */ + private get ownItems(): IgxListItemComponent[] { + return this.sortedChildren?.filter(item => item.list === this) ?? []; + } + /** * Syncs the listbox attributes of the list and its items, in the order the items are displayed. * Only the active option is a tab stop: the one focused last, else the first selected option, else the first option. + * Without options, the list itself is the tab stop, and when options are added while it has the focus, the focus moves to them. * While loading, the listbox is marked busy. A list that is not a listbox, and has not just stopped being one, is left untouched. */ private updateAttributes() { @@ -517,16 +535,28 @@ export class IgxListComponent extends IgxListBaseDirective { return; } this._synced = listbox; - syncAttribute(this.element.nativeElement, 'aria-busy', listbox && this.isLoading ? 'true' : null); - const children = this.sortedChildren.filter(item => item.list === this); + const element = this.element.nativeElement as HTMLElement; + syncAttribute(element, 'aria-busy', listbox && this.isLoading ? 'true' : null); + const children = this.ownItems; const options = children.filter(item => !item.isHeader && !item.hidden); const tabStop = options.includes(this._activeItem!) ? this._activeItem : options.find(item => item.selected) ?? options[0]; + const tabIndex = element.getAttribute('tabindex'); + const focused = tabIndex !== null && tabIndex === this._tabIndex + && (element.getRootNode() as Document | ShadowRoot).activeElement === element; + if (tabIndex === null || tabIndex === this._tabIndex) { + this._tabIndex = listbox && !tabStop ? '0' : null; + element.classList.toggle('igx-list--focusable', this._tabIndex !== null); + syncAttribute(element, 'tabindex', this._tabIndex); + } let header: IgxListItemComponent | null = null; for (const item of children) { header = item.isHeader ? item : header; item.updateAttributes(listbox, item === tabStop, header); } + if (listbox && tabStop && focused) { + tabStop.element.focus(); + } } private _role = 'list'; @@ -582,7 +612,7 @@ export class IgxListComponent extends IgxListBaseDirective { @HostListener('focusin', ['$event']) public onFocusIn(event: FocusEvent) { const target = event.composedPath()[0]; - this._activeItem = this.items.find(item => item.list === this && item.element === target) ?? this._activeItem; + this._activeItem = this.ownItems.find(item => item.element === target) ?? this._activeItem; } /** @@ -602,7 +632,7 @@ export class IgxListComponent extends IgxListBaseDirective { } const target = event.composedPath()[0]; - const items = this.items.filter(item => item.list === this && !item.hidden); + const items = this.ownItems.filter(item => !item.isHeader && !item.hidden); const current = items.findIndex(item => item.element === target); if (current === -1) { return; diff --git a/projects/igniteui-angular/list/src/list/themes/_base.scss b/projects/igniteui-angular/list/src/list/themes/_base.scss index 0114087968e..078838737c3 100644 --- a/projects/igniteui-angular/list/src/list/themes/_base.scss +++ b/projects/igniteui-angular/list/src/list/themes/_base.scss @@ -42,6 +42,17 @@ $theme: digest-schema($light-list); outline-style: none; } + @include e(message-wrapper) { + display: contents; + } + + @include m(focusable) { + &:focus-visible { + outline: var(--_focus-ring-width, #{rem(1px)}) solid var-get($theme, 'item-focus-outline-color'); + outline-offset: calc(var(--_focus-ring-width, #{rem(1px)}) * -1); + } + } + @include m(empty) { justify-content: center; align-items: center; diff --git a/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss b/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss index 98116369e63..80766aa2b14 100644 --- a/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss +++ b/projects/igniteui-angular/list/src/list/themes/shared/_indigo.scss @@ -3,13 +3,14 @@ @use '../../../../../core/src/core/styles/themes/scoping' as *; @include themed-block(igx-list, indigo) { + --_focus-ring-width: #{rem(2px)}; + gap: rem(4px); } @include themed-block(igx-list-item, indigo) { --_padding-block: #{pad-block(rem(4px), rem(6px), rem(8px))}; --_padding-inline: #{pad-block(rem(8px), rem(12px), rem(16px))}; - --_focus-ring-width: #{rem(2px)}; igx-avatar { --ig-size: 2; diff --git a/projects/igniteui-angular/package.json b/projects/igniteui-angular/package.json index dc07f364428..4f23407bf59 100644 --- a/projects/igniteui-angular/package.json +++ b/projects/igniteui-angular/package.json @@ -75,7 +75,7 @@ "igniteui-trial-watermark": "^3.1.0", "jspdf": "^4.2.1", "lodash-es": "^4.17.21", - "igniteui-theming": "^30.2.0", + "igniteui-theming": "^30.3.0", "igniteui-i18n-core": "^2.0.0", "@igniteui/material-icons-extended": "^3.1.0" }, diff --git a/projects/igniteui-angular/test-utils/list-components.spec.ts b/projects/igniteui-angular/test-utils/list-components.spec.ts index 5a269babd4f..0d3bd07d995 100644 --- a/projects/igniteui-angular/test-utils/list-components.spec.ts +++ b/projects/igniteui-angular/test-utils/list-components.spec.ts @@ -129,6 +129,27 @@ export class GroupedListboxComponent extends BasicListComponent { public note: string | null = 'item-3-note'; } +@Component({ + template: ` +
+ + @for (item of items; track item) { + {{ item }} + } + +

Loading data...

+
+
+
`, + changeDetection: ChangeDetectionStrategy.Eager, + imports: [IgxListComponent, IgxListItemComponent, IgxDataLoadingTemplateDirective] +}) +export class EmptyListboxComponent extends BasicListComponent { + public listbox = true; + public isLoading = false; + public items: string[] = []; +} + @Component({ template: `
From 486853688faef9ae85a524d55a7a81aea413a7e0 Mon Sep 17 00:00:00 2001 From: Adrian Petrov Date: Wed, 25 Nov 2026 15:01:49 +0200 Subject: [PATCH 4/4] feat(list): add selectable input --- CHANGELOG.md | 7 +++- projects/igniteui-angular/list/README.md | 16 +++++--- .../list/src/list/list.component.spec.ts | 7 ++-- .../list/src/list/list.component.ts | 37 ++++++++++++------- .../test-utils/list-components.spec.ts | 8 ++-- .../references/data-display.md | 4 +- src/app/list/list.sample.html | 2 +- 7 files changed, 49 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9711dd66474..a4fda7eda6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,18 @@ All notable changes for each version of this project will be documented in this file. -## 22.3.1 +## 22.4.0 ### New Features - `IgxListComponent`, `IgxListItemComponent` - - Setting `role="listbox"` on the list makes it an accessible listbox (#17952): items get `role="option"` with `aria-selected` from their `selected` state, and the list has a single tab stop on the option that was focused last, else the first selected one, else the first one. Arrow Up/Down and Home/End move between options, and Enter/Space click the focused option, so `itemClicked` fires. While `isLoading` is set, the list has `aria-busy="true"`. While the list has no options, the list itself is the tab stop and its empty or loading message is read as an option. The focused option shows an inset focus ring, also when it is selected, colored by the new `item-focus-outline-color` token of the list theme. Lists with another role, and listboxes that manage the focus with `aria-activedescendant`, are unchanged. A list that already sets `role="listbox"` now gets this behavior. + - The new `selectable` input makes the list an accessible listbox (#17952): the list gets `role="listbox"`, items get `role="option"` with `aria-selected` from their `selected` state, and the list has a single tab stop on the option that was focused last, else the first selected one, else the first one. Arrow Up/Down and Home/End move between options, and Enter/Space click the focused option, so `itemClicked` fires. While `isLoading` is set, the list has `aria-busy="true"`. While the list has no options, the list itself is the tab stop and its empty or loading message is read as an option. The focused option shows an inset focus ring, also when it is selected, colored by the new `item-focus-outline-color` token of the list theme. Lists that are not `selectable` are unchanged. - In a listbox, headers act as group names: each option points to the header above it with `aria-describedby`, so screen readers announce the group with every option, and the headers themselves are hidden from screen readers. An option that has its own `aria-describedby`, set or bound in the template, keeps it. + - **Deprecation** - The `role` input of the list has been deprecated. The role of the list is `list`, and `listbox` when the list is `selectable`, so use `selectable` to make the list a listbox instead. - Recommended: give a listbox an `aria-label`, so it is announced when the focus moves into the list. Set `aria-multiselectable="true"` when more than one item can be selected, and avoid focusable controls inside the items. If an item needs a selection control, such as a checkbox, make it `inert` so it does not interfere with the keyboard navigation and selection, and bind it to the item's selected state. +## 22.3.1 + ### Bug Fixes - `IgxGridComponent`, `IgxTreeGridComponent`, `IgxHierarchicalGridComponent` diff --git a/projects/igniteui-angular/list/README.md b/projects/igniteui-angular/list/README.md index 4633f2e0b74..b399a0fbff4 100644 --- a/projects/igniteui-angular/list/README.md +++ b/projects/igniteui-angular/list/README.md @@ -68,8 +68,9 @@ In order to access its elements, the list provides the following: - an array with headers only ### Listbox and keyboard navigation -Set `role="listbox"` on the list to make it an accessible [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/): +Set `selectable` on the list to make it an accessible [listbox](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/): +- The list gets `role="listbox"`. - Items get `role="option"` with `aria-selected`, from their `selected` state. - The list has a single tab stop. Tab focuses the option that was focused last, else the first selected option, else the first option, and the next Tab leaves the list. Headers and hidden items are skipped. - Headers act as group names: they are hidden from screen readers, and each option points to the header above it with `aria-describedby`. A header without an `id` gets one. A screen reader reads the option content followed by the group name, e.g. "Kate, selected, 1 of 8, Employees". An option that has its own `aria-describedby`, set or bound in the template, keeps it. @@ -86,7 +87,7 @@ Set `role="listbox"` on the list to make it an accessible [listbox](https://www. When an option is activated with Enter or Space, the `event` of `itemClicked` is the synthetic `MouseEvent` of that click. ```html - + @for (item of items(); track item.id) { {{ item.name }} @@ -102,7 +103,7 @@ Recommendations: - **Avoid interactive controls inside items.** An option should not contain buttons, links or checkboxes that can be focused. To show the selection with a checkbox, make it `inert` and bind it to the item state, so clicking it selects the item: ```html - + @for (employee of employees; track employee.id) { {{ employee.name }} @@ -112,9 +113,11 @@ Recommendations: ``` -Lists with another role are unchanged: they are not focusable, and controls inside their items work as before. A listbox that manages the focus itself with `aria-activedescendant`, like the grid's Excel-style filter list, is also left as it is: the two focus models cannot be combined, because the list would move the focus to an option while the app keeps a different option active. Do not set `aria-activedescendant` on a listbox unless the app handles the focus and the keys itself. +If an item really needs a button or another control for a separate action, such as deleting the item, call `$event.stopPropagation()` in the control's `(click)` handler, so using it does not select the item. -The keyboard navigation only moves between the rendered items. A list virtualized with `igxFor` is not scrolled to the items that are not rendered, so do not set `role="listbox"` on it. Handle the focus and the keys of a virtualized list in the app with `aria-activedescendant`, like the grid's Excel-style filter list does. +Lists that are not `selectable` are unchanged: they are not focusable, and controls inside their items work as before. This includes a list that only sets `role="listbox"`, like the grid's Excel-style filter list, which manages the focus itself with `aria-activedescendant`. + +The keyboard navigation only moves between the rendered items. A list virtualized with `igxFor` is not scrolled to the items that are not rendered, so do not set `selectable` on it. Handle the focus and the keys of a virtualized list in the app with `aria-activedescendant`, like the grid's Excel-style filter list does. ### Empty list template @@ -169,6 +172,7 @@ public rightPanPerformed(args) { | allowRightPanning | Determines whether the right panning of an item is allowed | | emptyListTemplate | Sets a reference to a custom empty list template, otherwise default template is used | | dataLoadingTemplate | Sets a reference to a custom data loading template, otherwise default template is used | +| selectable | Whether the user selects items in the list, default _false_. Makes the list an accessible [listbox](#listbox-and-keyboard-navigation) with keyboard navigation | | panEndTriggeringThreshold | Number | Specifies the threshold after which a panning event is emitted. By default this property has a value of 0.5 which means 50% of list item's width. | ### Properties @@ -179,7 +183,7 @@ public rightPanPerformed(args) { | items | Array of items in the list | | headers | Array of headers in the list | | innerStyle | Currently used inner style depending on whether the list is empty or not | -| role | Gets/sets the role of the list, default _list_. _listbox_ makes it an accessible [listbox](#listbox-and-keyboard-navigation) with keyboard navigation | +| role | **Deprecated**, use `selectable` instead. Gets/sets the role of the list, default _list_, _listbox_ when the list is `selectable` | ### Outputs diff --git a/projects/igniteui-angular/list/src/list/list.component.spec.ts b/projects/igniteui-angular/list/src/list/list.component.spec.ts index 06214cf2728..30c4eb497c8 100644 --- a/projects/igniteui-angular/list/src/list/list.component.spec.ts +++ b/projects/igniteui-angular/list/src/list/list.component.spec.ts @@ -778,7 +778,7 @@ describe('List', () => { fixture.detectChanges(); }); - it('should keep the attributes set by the app on a listbox that manages the focus with aria-activedescendant', () => { + it('should leave a list with role listbox that is not selectable unchanged', () => { const ownFixture = TestBed.createComponent(ListWithOwnAttributesComponent); ownFixture.detectChanges(); const ownList = ownFixture.componentInstance.list; @@ -885,7 +885,7 @@ describe('List', () => { expect(tabIndexes()).toEqual(['0', '-1']); }); - it('should reset the list and its items when its role is no longer listbox', () => { + it('should reset the list and its items when it is no longer selectable', () => { const header = list.children.first.element; expect(header.id).toMatch(/^igx-list-header-\d+$/); @@ -904,7 +904,8 @@ describe('List', () => { }); }); - it('should keep the roles set by the app and not follow the listbox pattern with a role other than listbox', () => { + it('should keep the roles set by the app on a list that is not selectable', () => { + fixture.componentInstance.listbox = false; list.role = 'menu'; list.items[0].role = 'menuitem'; fixture.detectChanges(); diff --git a/projects/igniteui-angular/list/src/list/list.component.ts b/projects/igniteui-angular/list/src/list/list.component.ts index 4d3b4778a0c..0c1985320a4 100644 --- a/projects/igniteui-angular/list/src/list/list.component.ts +++ b/projects/igniteui-angular/list/src/list/list.component.ts @@ -345,6 +345,24 @@ export class IgxListComponent extends IgxListBaseDirective { @Input({ transform: booleanAttribute }) public isLoading = false; + /** + * Sets/gets whether the user selects items in the list. + * + * @remarks + * Default value is `false`. When set, the list follows the ARIA listbox pattern: it has `role="listbox"`, + * its items become options that expose their `selected` state, Tab focuses the selected option, + * Arrow Up/Down and Home/End move between the options, and Enter/Space click the focused option. + * + * @example + * ```html + * + * Kate + * + * ``` + */ + @Input({ transform: booleanAttribute }) + public selectable = false; + /** * Event emitted when a left pan gesture is executed on a list item. * @@ -565,17 +583,9 @@ export class IgxListComponent extends IgxListBaseDirective { * Gets/Sets the `role` attribute value. * * @remarks - * Defaults to `list`. With `listbox`, the list follows the ARIA listbox pattern: its items become options - * that expose their `selected` state, Tab focuses the selected option, Arrow Up/Down and Home/End - * move between the options, and Enter/Space click the focused option. - * A listbox that manages the focus itself with `aria-activedescendant` is left as it is. + * Defaults to `list`, and is `listbox` when the list is `selectable`. * - * @example - * ```html - * - * Kate - * - * ``` + * @deprecated in version 22.4.0. Use `selectable` to make the list a listbox instead. * * @example * ```typescript @@ -585,7 +595,7 @@ export class IgxListComponent extends IgxListBaseDirective { @HostBinding('attr.role') @Input() public get role() { - return this._role; + return this.selectable ? 'listbox' : this._role; } public set role(val: string) { @@ -595,11 +605,10 @@ export class IgxListComponent extends IgxListBaseDirective { /** * @hidden * @internal - * Whether the list follows the ARIA listbox pattern: its role is `listbox`, - * and it does not manage the focus itself with `aria-activedescendant`, like the grid's Excel-style filter list. + * Whether the list follows the ARIA listbox pattern, which it does when it is `selectable`. */ public override get isListbox(): boolean { - return this._role === 'listbox' && !this.element.nativeElement.hasAttribute('aria-activedescendant'); + return this.selectable; } /** diff --git a/projects/igniteui-angular/test-utils/list-components.spec.ts b/projects/igniteui-angular/test-utils/list-components.spec.ts index 0d3bd07d995..6c910016133 100644 --- a/projects/igniteui-angular/test-utils/list-components.spec.ts +++ b/projects/igniteui-angular/test-utils/list-components.spec.ts @@ -87,7 +87,7 @@ export class ListWithSelectedItemComponent extends BasicListComponent { @Component({ template: `
- + Header @for (item of items; track item.id) { @@ -112,7 +112,7 @@ export class ListboxComponent extends BasicListComponent { @Component({ template: `
- + Ungrouped Employees Item 1 @@ -132,7 +132,7 @@ export class GroupedListboxComponent extends BasicListComponent { @Component({ template: `
- + @for (item of items; track item) { {{ item }} } @@ -316,7 +316,7 @@ export class ListWithPanningTemplatesComponent extends ListWithPanningComponent @Component({ template: ` - +
+ @for (contact of contacts; track contact.id) { {{ contact.name }} diff --git a/src/app/list/list.sample.html b/src/app/list/list.sample.html index bdf497c8c45..116c9abf5f7 100644 --- a/src/app/list/list.sample.html +++ b/src/app/list/list.sample.html @@ -2,7 +2,7 @@
Angular List
- +
deleteDelete