Skip to content

Commit dd9e1be

Browse files
authored
Merge pull request microsoft#97057 from microsoft/isidorn/list-navigation-aria
List: re-anounce element when focus did not change on typing
2 parents 709a350 + 01a7dfc commit dd9e1be

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/vs/base/browser/ui/list/listWidget.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { CombinedSpliceable } from 'vs/base/browser/ui/list/splice';
2626
import { clamp } from 'vs/base/common/numbers';
2727
import { matchesPrefix } from 'vs/base/common/filters';
2828
import { IDragAndDropData } from 'vs/base/browser/dnd';
29+
import { alert } from 'vs/base/browser/ui/aria/aria';
2930

3031
interface ITraitChangeEvent {
3132
indexes: number[];
@@ -344,6 +345,7 @@ class TypeLabelController<T> implements IDisposable {
344345

345346
private automaticKeyboardNavigation = true;
346347
private triggered = false;
348+
private previouslyFocused = -1;
347349

348350
private readonly enabledDisposables = new DisposableStore();
349351
private readonly disposables = new DisposableStore();
@@ -393,6 +395,7 @@ class TypeLabelController<T> implements IDisposable {
393395
const onInput = Event.reduce<string | null, string | null>(Event.any(onChar, onClear), (r, i) => i === null ? null : ((r || '') + i));
394396

395397
onInput(this.onInput, this, this.enabledDisposables);
398+
onClear(this.onClear, this, this.enabledDisposables);
396399

397400
this.enabled = true;
398401
this.triggered = false;
@@ -408,6 +411,19 @@ class TypeLabelController<T> implements IDisposable {
408411
this.triggered = false;
409412
}
410413

414+
private onClear(): void {
415+
const focus = this.list.getFocus();
416+
if (focus.length > 0 && focus[0] === this.previouslyFocused) {
417+
// List: re-anounce element on typing end since typed keys will interupt aria label of focused element
418+
// Do not announce if there was a focus change at the end to prevent duplication https://github.com/microsoft/vscode/issues/95961
419+
const ariaLabel = this.list.options.accessibilityProvider?.getAriaLabel(this.list.element(focus[0]));
420+
if (ariaLabel) {
421+
alert(ariaLabel);
422+
}
423+
}
424+
this.previouslyFocused = -1;
425+
}
426+
411427
private onInput(word: string | null): void {
412428
if (!word) {
413429
this.state = TypeLabelControllerState.Idle;
@@ -426,6 +442,7 @@ class TypeLabelController<T> implements IDisposable {
426442
const labelStr = label && label.toString();
427443

428444
if (typeof labelStr === 'undefined' || matchesPrefix(word, labelStr)) {
445+
this.previouslyFocused = start;
429446
this.list.setFocus([index]);
430447
this.list.reveal(index);
431448
return;

0 commit comments

Comments
 (0)