-
Notifications
You must be signed in to change notification settings - Fork 6
/
d2l-date-picker.js
125 lines (106 loc) · 2.97 KB
/
d2l-date-picker.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
`d2l-date-picker`
A Date Picker for D2L Brightspace
@demo demo/index.html
*/
import '@brightspace-ui/core/components/colors/colors.js';
import '@brightspace-ui/inputs/d2l-input-shared-styles.js';
import '@polymer/polymer/polymer-legacy.js';
import '@polymer/iron-input/iron-input.js';
import '@polymer/iron-a11y-keys/iron-a11y-keys.js';
import '@polymer/iron-dropdown/iron-dropdown.js';
import '@vaadin/vaadin-date-picker/vaadin-date-picker-light.js';
import 'fastdom/fastdom.js';
import './d2l-date-picker-behavior.js';
import './d2l-date-picker-style-modules.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js';
Polymer({
_template: html`
<style is="custom-style" include="d2l-input-styles">
:host {
display: block;
}
:host([hide-label]) > label,
.d2l-date-picker-description {
position: absolute !important;
overflow: hidden;
width: 1px;
height: 1px;
white-space: nowrap;
left: -10000px;
}
:host(:dir(rtl)) :host([hide-label]) > label,
:host(:dir(rtl)) .d2l-date-picker-description {
left: 0;
right: -10000px;
}
:host-context([dir="rtl"]) :host([hide-label]) > label,
:host-context([dir="rtl"]) .d2l-date-picker-description {
left: 0;
right: -10000px;
}
vaadin-date-picker-light,
iron-input {
width: 100%;
}
label {
@apply --d2l-date-picker-label;
}
:host([dir="rtl"]) label {
@apply --d2l-date-picker-label-rtl;
}
.d2l-input {
/* Needed because: https://github.com/webcomponents/shadycss/issues/91 */
font-family: inherit !important;
}
</style>
<label>[[label]]</label>
<vaadin-date-picker-light min="[[min]]" max="[[max]]" value="{{value}}" on-value-changed="_handleValueChanged" initial-position="[[initialPosition]]">
<iron-a11y-keys target="[[_target]]" keys="enter" on-keys-pressed="onEnter"></iron-a11y-keys>
<iron-a11y-keys target="[[_target]]" keys="up down" on-keys-pressed="onUpDown"></iron-a11y-keys>
<iron-input>
<slot>
<input
on-tap="_handleTap"
placeholder="{{placeholder}}"
class="d2l-input"
type="text"
on-focus="_handleFocus"
aria-describedby$="[[_descriptionId]]"
aria-label$="[[label]]"
aria-invalid$="[[_computedAriaInvalid(invalid)]]">
<div id="[[_descriptionId]]" class="d2l-date-picker-description">{{description}}</div>
</slot>
</iron-input>
</vaadin-date-picker-light>
`,
is: 'd2l-date-picker',
behaviors: [
D2L.PolymerBehaviors.DatePicker.DatePickerBehavior
],
properties: {
invalid: {
type: Boolean,
value: false,
reflectToAttribute: true
}
},
ready: function() {
const input = this.$$('input');
if (input) {
this._target = this.$$('input');
}
},
focus: function() {
const input = this.$$('input');
if (input) {
fastdom.mutate(() => {
input.focus();
});
}
},
_computedAriaInvalid: function(invalid) {
return invalid ? 'true' : 'false';
}
});