-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmenu-item-selectable-mixin.js
54 lines (46 loc) · 1.16 KB
/
menu-item-selectable-mixin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { MenuItemMixin } from './menu-item-mixin.js';
export const MenuItemSelectableMixin = superclass => class extends MenuItemMixin(superclass) {
static get properties() {
return {
/**
* This will set the item to be selected by default
* @type {boolean}
*/
selected: { type: Boolean, reflect: true },
/**
* REQUIRED: The selectable item's value
* @type {string}
*/
value: { type: String }
};
}
constructor() {
super();
this.selected = false;
}
updated(changedProperties) {
super.updated(changedProperties);
changedProperties.forEach((oldValue, propName) => {
if (propName === 'selected') {
this.__onSelectedChanged(this.selected);
}
});
}
__onSelect(e) {
e.preventDefault();
e.stopPropagation();
const eventDetails = {
bubbles: true,
composed: true,
detail: {
value: this.value,
selected: this.selected
}
};
/** Dispatched when the selected menu item changes */
this.dispatchEvent(new CustomEvent('d2l-menu-item-change', eventDetails));
}
__onSelectedChanged(selected) {
selected ? this.setAttribute('aria-checked', 'true') : this.setAttribute('aria-checked', 'false');
}
};