-
Notifications
You must be signed in to change notification settings - Fork 332
/
paper-select.js
69 lines (64 loc) · 2.07 KB
/
paper-select.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @module ember-paper
*/
import { alias, and } from '@ember/object/computed';
import { computed } from '@ember/object';
import layout from '../templates/components/paper-select';
import PowerSelect from 'ember-power-select/components/power-select';
import ValidationMixin from 'ember-paper/mixins/validation-mixin';
import ChildMixin from 'ember-paper/mixins/child-mixin';
import FocusableMixin from 'ember-paper/mixins/focusable-mixin';
function concatWithProperty(strings, property) {
if (property) {
strings.push(property);
}
return strings.join(' ');
}
/**
* @class PaperSelect
* @extends PaperInput
*/
export default PowerSelect.extend(ValidationMixin, ChildMixin, FocusableMixin, {
layout,
tagName: 'md-input-container',
onchange: alias('onChange'),
optionsComponent: 'paper-select-options',
triggerComponent: 'paper-select-trigger',
beforeOptionsComponent: 'paper-select-search',
classNameBindings: ['isInvalidAndTouched:md-input-invalid', 'selected:md-input-has-value', 'focusedAndSelected:md-input-focused'],
searchEnabled: false,
validationProperty: 'selected',
isTouched: false,
isInvalidAndTouched: and('isInvalid', 'isTouched'),
attributeBindings: ['parentTabindex:tabindex'],
shouldShowLabel: and('label', 'selected'),
focusedAndSelected: and('focused', 'selected'),
didReceiveAttrs() {
this._super(...arguments);
this.notifyValidityChange();
},
concatenatedTriggerClasses: computed('triggerClass', 'publicAPI.isActive', function() {
let classes = ['ember-power-select-trigger'];
if (this.get('isInvalid')) {
classes.push('ng-invalid');
}
if (this.get('isTouched')) {
classes.push('ng-dirty');
}
if (this.get('publicAPI.isActive')) {
classes.push('ember-power-select-trigger--active');
}
return concatWithProperty(classes, this.get('triggerClass'));
}),
actions: {
onClose() {
this._super(...arguments);
this.set('isTouched', true);
this.notifyValidityChange();
},
onOpen() {
this._super(...arguments);
this.notifyValidityChange();
}
}
});