Skip to content

Commit 7aca51e

Browse files
committed
set aria-selected on focused and selected list items
1 parent 4740213 commit 7aca51e

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ class Trait<T> implements ISpliceable<boolean>, IDisposable {
180180
}
181181
}
182182

183-
class SelectionTrait<T> extends Trait<T> {
183+
class FocusTrait<T> extends Trait<T> {
184184

185-
constructor() {
186-
super('selected');
185+
constructor(private isAriaSelected: (index: number) => boolean) {
186+
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 Trait('focused');
1202-
this.selection = new SelectionTrait();
1201+
this.selection = new Trait('selected');
1202+
this.focus = new FocusTrait(this.selection.contains);
12031203

12041204
mixin(_options, defaultStyles, false);
12051205

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,9 @@ export class ViewItem implements IViewItem {
219219
if (this.model.hasTrait('focused')) {
220220
const base64Id = strings.safeBtoa(this.model.id);
221221
this.element.setAttribute('id', base64Id);
222-
} else {
223-
this.element.removeAttribute('id');
224-
}
225-
if (this.model.hasTrait('selected')) {
226222
this.element.setAttribute('aria-selected', 'true');
227223
} else {
224+
this.element.removeAttribute('id');
228225
this.element.setAttribute('aria-selected', 'false');
229226
}
230227
if (this.model.hasChildren()) {

0 commit comments

Comments
 (0)