Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit f2dba6c

Browse files
authored
feat(list): Add new adapter methods for accessibility (#1586)
1 parent fc13f80 commit f2dba6c

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

packages/drawer/drawer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class MdcDrawer implements AfterViewInit, OnDestroy {
141141
get dismissible(): boolean { return this.drawer === 'dismissible'; }
142142
get permanent(): boolean { return this.drawer === 'permanent'; }
143143

144-
createAdapter() {
144+
private _createAdapter() {
145145
return {
146146
addClass: (className: string) => this._getHostElement().classList.add(className),
147147
removeClass: (className: string) => this._getHostElement().classList.remove(className),
@@ -186,7 +186,7 @@ export class MdcDrawer implements AfterViewInit, OnDestroy {
186186
isOpen(): boolean,
187187
handleKeydown(evt: KeyboardEvent): void,
188188
handleTransitionEnd(evt: TransitionEvent): void
189-
} = new MDCDismissibleDrawerFoundation(this.createAdapter());
189+
} = new MDCDismissibleDrawerFoundation(this._createAdapter());
190190

191191
constructor(
192192
private _platform: Platform,
@@ -263,9 +263,9 @@ export class MdcDrawer implements AfterViewInit, OnDestroy {
263263
this._removeDrawerModifiers();
264264

265265
if (this.modal) {
266-
this._foundation = new MDCModalDrawerFoundation(this.createAdapter());
266+
this._foundation = new MDCModalDrawerFoundation(this._createAdapter());
267267
} else {
268-
this._foundation = new MDCDismissibleDrawerFoundation(this.createAdapter());
268+
this._foundation = new MDCDismissibleDrawerFoundation(this._createAdapter());
269269
}
270270

271271
if (!this.permanent) {

packages/list/list.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ export class MdcListItemChange {
3838
moduleId: module.id,
3939
selector: '[mdcListGroup], mdc-list-group',
4040
exportAs: 'mdcListGroup',
41-
host: {
42-
'class': 'mdc-list-group'
43-
},
41+
host: { 'class': 'mdc-list-group' },
4442
template: `
4543
<h3 class="mdc-list-group__subheader" *ngIf="subheader">{{subheader}}</h3>
4644
<ng-content></ng-content>
@@ -57,9 +55,7 @@ export class MdcListGroup {
5755
@Directive({
5856
selector: '[mdcListGroupSubheader], mdc-list-group-subheader',
5957
exportAs: 'mdcListGroupSubheader',
60-
host: {
61-
'class': 'mdc-list-group__subheader'
62-
}
58+
host: { 'class': 'mdc-list-group__subheader' }
6359
})
6460
export class MdcListGroupSubheader {
6561
constructor(public elementRef: ElementRef) { }
@@ -211,22 +207,30 @@ export class MdcList implements AfterViewInit, OnDestroy {
211207
listItem.getListItemElement().click();
212208
}
213209
},
214-
toggleCheckbox: (index: number) => {
215-
let checkboxOrRadioExists = false;
216-
const listItem = this._listItems.toArray()[index];
217-
const elementsToToggle = [].slice.call(listItem.getListItemElement().querySelectorAll(strings.CHECKBOX_RADIO_SELECTOR));
218-
elementsToToggle.forEach((element: any) => {
210+
hasCheckboxAtIndex: (index: number) => {
211+
const listItem = this._listItems.toArray()[index].getListItemElement();
212+
return !!listItem.querySelector(strings.CHECKBOX_SELECTOR);
213+
},
214+
hasRadioAtIndex: (index: number) => {
215+
const listItem = this._listItems.toArray()[index].getListItemElement();
216+
return !!listItem.querySelector(strings.RADIO_SELECTOR);
217+
},
218+
isCheckboxCheckedAtIndex: (index: number) => {
219+
const listItem = this._listItems.toArray()[index].getListItemElement();
220+
const toggleEl = listItem.querySelector(strings.CHECKBOX_SELECTOR);
221+
return toggleEl.checked;
222+
},
223+
setCheckedCheckboxOrRadioAtIndex: (index: number, isChecked: boolean) => {
224+
const listItem = this._listItems.toArray()[index].getListItemElement();
225+
const toggleEl = listItem.querySelector(strings.CHECKBOX_RADIO_SELECTOR);
226+
toggleEl.checked = isChecked;
227+
228+
if (this._platform.isBrowser) {
219229
const event = document.createEvent('Event');
220230
event.initEvent('change', true, true);
221-
222-
if (!element.checked || element.type !== 'radio') {
223-
element.checked = !element.checked;
224-
element.dispatchEvent(event);
225-
}
226-
checkboxOrRadioExists = true;
227-
});
228-
return checkboxOrRadioExists;
229-
},
231+
toggleEl.dispatchEvent(event);
232+
}
233+
}
230234
};
231235
}
232236

0 commit comments

Comments
 (0)