提交 7aca51e3 编写于 作者: I isidor

set aria-selected on focused and selected list items

上级 47402135
......@@ -180,19 +180,19 @@ class Trait<T> implements ISpliceable<boolean>, IDisposable {
}
}
class SelectionTrait<T> extends Trait<T> {
class FocusTrait<T> extends Trait<T> {
constructor() {
super('selected');
constructor(private isAriaSelected: (index: number) => boolean) {
super('focused');
}
renderIndex(index: number, container: HTMLElement): void {
super.renderIndex(index, container);
if (this.contains(index)) {
if (this.contains(index) || this.isAriaSelected(index)) {
container.setAttribute('aria-selected', 'true');
} else {
container.removeAttribute('aria-selected');
container.setAttribute('aria-selected', 'false');
}
}
}
......@@ -1198,8 +1198,8 @@ export class List<T> implements ISpliceable<T>, IDisposable {
renderers: IListRenderer<any /* TODO@joao */, any>[],
private _options: IListOptions<T> = DefaultOptions
) {
this.focus = new Trait('focused');
this.selection = new SelectionTrait();
this.selection = new Trait('selected');
this.focus = new FocusTrait(this.selection.contains);
mixin(_options, defaultStyles, false);
......
......@@ -219,12 +219,9 @@ export class ViewItem implements IViewItem {
if (this.model.hasTrait('focused')) {
const base64Id = strings.safeBtoa(this.model.id);
this.element.setAttribute('id', base64Id);
} else {
this.element.removeAttribute('id');
}
if (this.model.hasTrait('selected')) {
this.element.setAttribute('aria-selected', 'true');
} else {
this.element.removeAttribute('id');
this.element.setAttribute('aria-selected', 'false');
}
if (this.model.hasChildren()) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册