-
Notifications
You must be signed in to change notification settings - Fork 332
/
paper-select-options.js
39 lines (38 loc) · 1.31 KB
/
paper-select-options.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
import PowerOptions from 'ember-power-select/components/power-select/options';
import layout from '../templates/components/paper-select-options';
export default PowerOptions.extend({
layout,
tagName: 'md-content',
init() {
if (this.get('role') === 'group') {
this.set('tagName', '');
this.set('attributeBindings', undefined);
}
this._super(...arguments);
},
didInsertElement() {
if (this.get('role') === 'group') {
return;
}
let findOptionAndPerform = (action, e) => {
let optionItem = e.target.closest('[data-option-index]');
if (!optionItem) {
return;
}
if (optionItem.closest('[aria-disabled=true]')) {
return;
} // Abort if the item or an ancestor is disabled
let optionIndex = optionItem.getAttribute('data-option-index');
action(this._optionFromIndex(optionIndex), e);
};
this.element.addEventListener('mouseup', (e) => findOptionAndPerform(this.get('select.actions.choose'), e));
this.element.addEventListener('mouseover', (e) => findOptionAndPerform(this.get('select.actions.highlight'), e));
if (this.get('isTouchDevice')) {
this._addTouchEvents();
}
if (this.get('role') !== 'group') {
let select = this.get('select');
select.actions.scrollTo(select.highlighted);
}
}
});