Skip to content

Commit 583dc03

Browse files
authored
Merge pull request microsoft#92019 from microsoft/isidorn/list-multi-select
list: improve aria-selected to be set on each selected element. Set a…
2 parents d686620 + 7aca51e commit 583dc03

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,17 @@ class Trait<T> implements ISpliceable<boolean>, IDisposable {
182182

183183
class FocusTrait<T> extends Trait<T> {
184184

185-
constructor() {
185+
constructor(private isAriaSelected: (index: number) => boolean) {
186186
super('focused');
187187
}
188188

189189
renderIndex(index: number, container: HTMLElement): void {
190190
super.renderIndex(index, container);
191191

192-
if (this.contains(index)) {
192+
if (this.contains(index) || this.isAriaSelected(index)) {
193193
container.setAttribute('aria-selected', 'true');
194194
} else {
195-
container.removeAttribute('aria-selected');
195+
container.setAttribute('aria-selected', 'false');
196196
}
197197
}
198198
}
@@ -1198,8 +1198,8 @@ export class List<T> implements ISpliceable<T>, IDisposable {
11981198
renderers: IListRenderer<any /* TODO@joao */, any>[],
11991199
private _options: IListOptions<T> = DefaultOptions
12001200
) {
1201-
this.focus = new FocusTrait();
12021201
this.selection = new Trait('selected');
1202+
this.focus = new FocusTrait(this.selection.contains);
12031203

12041204
mixin(_options, defaultStyles, false);
12051205

@@ -1272,6 +1272,9 @@ export class List<T> implements ISpliceable<T>, IDisposable {
12721272
if (_options.ariaLabel) {
12731273
this.view.domNode.setAttribute('aria-label', localize('aria list', "{0}. Use the navigation keys to navigate.", _options.ariaLabel));
12741274
}
1275+
if (_options.multipleSelectionSupport) {
1276+
this.view.domNode.setAttribute('aria-multiselectable', 'true');
1277+
}
12751278
}
12761279

12771280
protected createMouseController(options: IListOptions<T>): MouseController<T> {

src/vs/base/parts/tree/browser/treeView.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,11 @@ export class ViewItem implements IViewItem {
218218
}
219219
if (this.model.hasTrait('focused')) {
220220
const base64Id = strings.safeBtoa(this.model.id);
221-
222-
this.element.setAttribute('aria-selected', 'true');
223221
this.element.setAttribute('id', base64Id);
222+
this.element.setAttribute('aria-selected', 'true');
224223
} else {
225-
this.element.setAttribute('aria-selected', 'false');
226224
this.element.removeAttribute('id');
225+
this.element.setAttribute('aria-selected', 'false');
227226
}
228227
if (this.model.hasChildren()) {
229228
this.element.setAttribute('aria-expanded', String(!!this._styles['expanded']));

0 commit comments

Comments
 (0)