kmaterialize 2.0.0 → 2.3.3-1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +55 -91
- package/components/appbar/_navbar.old.scss +223 -0
- package/components/appbar/appbar.css +235 -0
- package/components/appbar/appbar.mjs +54 -0
- package/components/appbar/appbar.test.mjs +9 -0
- package/components/atomic/atomic.mjs +19 -0
- package/components/atomic/component.mjs +67 -0
- package/components/badge/_badges.scss +75 -0
- package/components/badge/badge.mjs +11 -0
- package/components/breadcrumb/_breadcrumb.scss +27 -0
- package/components/button/_buttons.scss +352 -0
- package/components/button/button.mjs +11 -0
- package/components/button/buttons.stories.ts +150 -0
- package/components/button/buttons.ts +282 -0
- package/components/button/examples.iso.js +18 -0
- package/components/button/fabSpec.js +65 -0
- package/components/button/test-button.mjs +16 -0
- package/components/card/_cards.scss +229 -0
- package/components/card/card.mjs +10 -0
- package/components/card/cards.ts +185 -0
- package/components/card/cardsSpec.js +269 -0
- package/components/carousel/_carousel.scss +93 -0
- package/components/carousel/_slider.scss +119 -0
- package/components/carousel/carousel.ts +693 -0
- package/components/carousel/carouselSpec.js +61 -0
- package/components/carousel/slider.ts +431 -0
- package/components/carousel/sliderSpec.js +99 -0
- package/components/checkbox/_checkboxes.scss +281 -0
- package/components/checkbox/checkbox.mdx +24 -0
- package/components/checkbox/checkbox.stories.ts +120 -0
- package/components/chip/chip.mjs +37 -0
- package/components/chip/chip.test.mjs +10 -0
- package/components/chip/chips.css +126 -0
- package/components/chip/chips.mdx +33 -0
- package/components/chip/chips.ts +440 -0
- package/components/chip/chipsSpec.js +165 -0
- package/components/chip/readme.md +323 -0
- package/components/collapsible/_collapsible.scss +82 -0
- package/components/collapsible/collapsible.ts +230 -0
- package/components/collapsible/collapsibleSpec.js +240 -0
- package/components/datepicker/_datepicker.scss +268 -0
- package/components/datepicker/datepicker.ts +1450 -0
- package/components/datepicker/datepickerSpec.js +162 -0
- package/components/dialog/_materialbox.scss +42 -0
- package/components/dialog/_modal.scss +79 -0
- package/components/dialog/materialbox.ts +446 -0
- package/components/dialog/materialboxSpec.js +37 -0
- package/components/dialog/modal.ts +111 -0
- package/components/dialog/modalSpec.js +83 -0
- package/components/dialog/readme.md +5 -0
- package/components/divider/readme.md +15 -0
- package/components/dropdown/_dropdown.scss +83 -0
- package/components/dropdown/dropdown.ts +653 -0
- package/components/dropdown/dropdownSpec.js +108 -0
- package/components/list/_collection.scss +114 -0
- package/components/list/_list.scss +6 -0
- package/components/list/list.mjs +58 -0
- package/components/list/list.test.mjs +16 -0
- package/components/loading/loading.mjs +26 -0
- package/components/loading/loading.test.mjs +10 -0
- package/components/navigation-bar/_old +582 -0
- package/components/navigation-bar/navigation-bar.mdx +20 -0
- package/components/navigation-bar/navigation-bar.stories.ts +39 -0
- package/components/navigation-drawer/_sidenav.scss +247 -0
- package/components/navigation-drawer/sidenav.ts +546 -0
- package/components/navigation-drawer/sidenavSpec.js +124 -0
- package/components/pagination/_pagination.scss +47 -0
- package/components/progress/_preloader.scss +416 -0
- package/components/radio-button/_radio-buttons.scss +112 -0
- package/components/radio-button/radio-buttons.mdx +28 -0
- package/components/radio-button/radio-buttons.stories.ts +51 -0
- package/components/search/autocomplete.ts +620 -0
- package/components/search/autocompleteSpec.js +321 -0
- package/components/slider/_range.scss +157 -0
- package/components/slider/range.ts +216 -0
- package/components/snackbar/_toast.scss +68 -0
- package/components/snackbar/toastSpec.js +132 -0
- package/components/snackbar/toasts.ts +312 -0
- package/components/switch/_switches.scss +121 -0
- package/components/tabs/_tabs.scss +171 -0
- package/components/tabs/tabs.mjs +31 -0
- package/components/tabs/tabs.ts +358 -0
- package/components/tabs/tabsSpec.js +180 -0
- package/components/textfield/_file-input.scss +41 -0
- package/components/textfield/_input-fields.scss +368 -0
- package/components/textfield/_select.scss +104 -0
- package/components/textfield/formfields.css +311 -0
- package/components/textfield/forms.ts +182 -0
- package/components/textfield/formsSpec.js +142 -0
- package/components/textfield/select.ts +472 -0
- package/components/textfield/selectSpec.js +390 -0
- package/components/textfield/textfield.mjs +29 -0
- package/components/textfield/textfield.test.mjs +10 -0
- package/components/timepicker/_timepicker.scss +362 -0
- package/components/timepicker/timepicker.ts +905 -0
- package/components/tooltip/_tooltip.scss +40 -0
- package/components/tooltip/tooltip.ts +380 -0
- package/components/tooltip/tooltipSpec.js +145 -0
- package/dist/css/materialize.colors.min.css +6 -0
- package/dist/css/materialize.css +7578 -6326
- package/dist/css/materialize.min.css +6 -13
- package/dist/css/materialize.min.css.map +1 -0
- package/dist/js/materialize.cjs.js +8410 -0
- package/dist/js/materialize.d.ts +2625 -0
- package/dist/js/materialize.js +8415 -12374
- package/dist/js/materialize.min.js +6 -6
- package/dist/js/materialize.mjs +8382 -0
- package/package.json +82 -47
- package/sass/_colors.scss +417 -0
- package/sass/_global.scss +490 -0
- package/sass/_grid.scss +172 -0
- package/sass/_table_of_contents.scss +28 -0
- package/sass/_tapTarget.scss +102 -0
- package/sass/_typography.scss +58 -0
- package/sass/_variables.scss +56 -0
- package/sass/materialize.scss +51 -0
- package/sass/mixins.module.scss +168 -0
- package/extras/noUiSlider/nouislider.css +0 -406
- package/extras/noUiSlider/nouislider.js +0 -2147
- package/extras/noUiSlider/nouislider.min.js +0 -1
- package/js/anime.min.js +0 -34
- package/js/autocomplete.js +0 -448
- package/js/buttons.js +0 -354
- package/js/cards.js +0 -40
- package/js/carousel.js +0 -717
- package/js/cash.js +0 -960
- package/js/characterCounter.js +0 -136
- package/js/chips.js +0 -481
- package/js/collapsible.js +0 -275
- package/js/component.js +0 -44
- package/js/datepicker.js +0 -975
- package/js/dropdown.js +0 -635
- package/js/forms.js +0 -275
- package/js/global.js +0 -444
- package/js/materialbox.js +0 -453
- package/js/modal.js +0 -382
- package/js/parallax.js +0 -138
- package/js/pushpin.js +0 -148
- package/js/range.js +0 -263
- package/js/scrollspy.js +0 -295
- package/js/select.js +0 -450
- package/js/sidenav.js +0 -580
- package/js/slider.js +0 -359
- package/js/tabs.js +0 -402
- package/js/tapTarget.js +0 -314
- package/js/timepicker.js +0 -647
- package/js/toasts.js +0 -310
- package/js/tooltip.js +0 -303
- package/js/waves.js +0 -335
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
describe('Select Plugin:', () => {
|
|
2
|
+
const fixture = `<div class="row">
|
|
3
|
+
<div class="input-field col s12">
|
|
4
|
+
<select class="normal">
|
|
5
|
+
<option value="" disabled>Choose your option</option>
|
|
6
|
+
<option value="1">Option 1</option>
|
|
7
|
+
<option value="2">Option 2</option>
|
|
8
|
+
<option value="3" selected>Option 3</option>
|
|
9
|
+
</select>
|
|
10
|
+
<label>Materialize Select</label>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="row">
|
|
15
|
+
<div class="input-field col s12">
|
|
16
|
+
<select multiple class="multiple">
|
|
17
|
+
<option value="" disabled>Choose your option</option>
|
|
18
|
+
<option value="1">Option 1</option>
|
|
19
|
+
<option value="2" selected>Option 2</option>
|
|
20
|
+
<option value="3" selected>Option 3</option>
|
|
21
|
+
</select>
|
|
22
|
+
<label>Materialize Select</label>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div class="row">
|
|
27
|
+
<div class="input-field col s12">
|
|
28
|
+
<select class="optgroup">
|
|
29
|
+
<optgroup label="team 1">
|
|
30
|
+
<option value="1">Option 1</option>
|
|
31
|
+
<option value="2">Option 2</option>
|
|
32
|
+
</optgroup>
|
|
33
|
+
<optgroup label="team 2">
|
|
34
|
+
<option value="3">Option 3</option>
|
|
35
|
+
<option value="4">Option 4</option>
|
|
36
|
+
</optgroup>
|
|
37
|
+
<option>After optgroup</option>
|
|
38
|
+
</select>
|
|
39
|
+
<label>Materialize Select</label>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<div class="row">
|
|
44
|
+
<div class="input-field col s12">
|
|
45
|
+
<select class="browser-default">
|
|
46
|
+
<option value="" disabled selected>Choose your option</option>
|
|
47
|
+
<option value="1">Option 1</option>
|
|
48
|
+
<option value="2">Option 2</option>
|
|
49
|
+
<option value="3">Option 3</option>
|
|
50
|
+
</select>
|
|
51
|
+
<label>Materialize Select</label>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
XloadHtml(fixture);
|
|
58
|
+
M.FormSelect.init(document.querySelectorAll('select'), {
|
|
59
|
+
dropdownOptions: { inDuration: 0, outDuration: 0 }
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
afterEach(() => XunloadFixtures());
|
|
63
|
+
|
|
64
|
+
describe('Select:', () => {
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
const fixture1 = `<div class="row">
|
|
67
|
+
<div class="input-field col s12">
|
|
68
|
+
<select class="normal">
|
|
69
|
+
<option value="" disabled>Choose your option</option>
|
|
70
|
+
<option value="1">Option 1</option>
|
|
71
|
+
<option value="2">Option 2</option>
|
|
72
|
+
<option value="3" selected>Option 3</option>
|
|
73
|
+
</select>
|
|
74
|
+
<label>Materialize Select</label>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="input-field col s12">
|
|
77
|
+
<select class="browser-default">
|
|
78
|
+
<option value="" disabled selected>Choose your option</option>
|
|
79
|
+
<option value="1">Option 1</option>
|
|
80
|
+
<option value="2">Option 2</option>
|
|
81
|
+
<option value="3">Option 3</option>
|
|
82
|
+
</select>
|
|
83
|
+
<label>Materialize Select</label>
|
|
84
|
+
</div>
|
|
85
|
+
</div>`;
|
|
86
|
+
XloadHtml(fixture1);
|
|
87
|
+
});
|
|
88
|
+
afterEach(() => XunloadFixtures());
|
|
89
|
+
|
|
90
|
+
it('should open dropdown and select option', (done) => {
|
|
91
|
+
const browserSelect = document.querySelector('select.normal');
|
|
92
|
+
const selectInstance = M.FormSelect.getInstance(browserSelect);
|
|
93
|
+
const normalInput = selectInstance.wrapper.querySelector('input.select-dropdown');
|
|
94
|
+
const normalDropdown = selectInstance.wrapper.querySelector('ul.select-dropdown');
|
|
95
|
+
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
expect(normalInput).toExist('Should dynamically generate select dropdown structure.');
|
|
98
|
+
expect(normalDropdown).toExist('Should dynamically generate select dropdown structure.');
|
|
99
|
+
expect(normalInput).toBeVisible('Should be visible before dropdown is opened.');
|
|
100
|
+
expect(normalDropdown).toBeHidden('Should be hidden before dropdown is opened.');
|
|
101
|
+
|
|
102
|
+
click(normalInput);
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
expect(normalDropdown).toBeVisible('Should be visible after opening.');
|
|
105
|
+
const firstOption = normalDropdown.querySelector('li:not(.disabled)');
|
|
106
|
+
click(firstOption);
|
|
107
|
+
blur(normalInput);
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
expect(normalDropdown).toBeHidden('Should be hidden after choosing item.');
|
|
110
|
+
expect(normalInput.value).toEqual(
|
|
111
|
+
firstOption.innerText,
|
|
112
|
+
'Value should equal chosen option.'
|
|
113
|
+
);
|
|
114
|
+
expect(firstOption.getAttribute('aria-selected')).toBe(
|
|
115
|
+
'true',
|
|
116
|
+
'Item be selected to assistive technologies.'
|
|
117
|
+
);
|
|
118
|
+
done();
|
|
119
|
+
}, 10);
|
|
120
|
+
}, 10);
|
|
121
|
+
}, 10);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should have pre-selected value', (done) => {
|
|
125
|
+
const elem = document.querySelector('select.normal');
|
|
126
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
127
|
+
const input = instance.wrapper.querySelector('input.select-dropdown');
|
|
128
|
+
const firstOption = elem.querySelector('option[selected]');
|
|
129
|
+
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
expect(input.value).toEqual(
|
|
132
|
+
firstOption.innerText,
|
|
133
|
+
'Value should be equal to preselected option.'
|
|
134
|
+
);
|
|
135
|
+
expect(
|
|
136
|
+
firstOption.getAttribute('aria-selected'),
|
|
137
|
+
'First item should be selected to assistive technologies.'
|
|
138
|
+
);
|
|
139
|
+
done();
|
|
140
|
+
}, 10);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should not initialize if browser default', () => {
|
|
144
|
+
const browserDefault = document.querySelector('select.browser-default');
|
|
145
|
+
expect(browserDefault.parentNode.classList.contains('select-wrapper')).toBeFalse(
|
|
146
|
+
'Wrapper should not be made'
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should getSelectedValues correctly', (done) => {
|
|
151
|
+
const elem = document.querySelector('select.normal');
|
|
152
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
153
|
+
const normalInput = instance.wrapper.querySelector('input.select-dropdown');
|
|
154
|
+
const normalDropdown = instance.wrapper.querySelector('ul.select-dropdown');
|
|
155
|
+
|
|
156
|
+
expect(instance.getSelectedValues()).toEqual(
|
|
157
|
+
[elem.value],
|
|
158
|
+
'Should equal initial selected value'
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
click(normalInput);
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
const firstOption = normalDropdown.querySelector('li:not(.disabled)');
|
|
164
|
+
click(firstOption);
|
|
165
|
+
blur(normalInput);
|
|
166
|
+
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
expect(instance.getSelectedValues()).toEqual(
|
|
169
|
+
[elem.value],
|
|
170
|
+
'Should equal value of first option'
|
|
171
|
+
);
|
|
172
|
+
done();
|
|
173
|
+
}, 10);
|
|
174
|
+
}, 10);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('Multiselect:', () => {
|
|
179
|
+
it('Dropdown should allow multiple selections to assistive technologies', () => {
|
|
180
|
+
const elem = document.querySelector('select.multiple');
|
|
181
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
182
|
+
expect(instance.dropdownOptions.getAttribute('aria-multiselectable')).toBe('true');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should open dropdown and select multiple options', (done) => {
|
|
186
|
+
const elem = document.querySelector('select.multiple');
|
|
187
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
188
|
+
const input = instance.wrapper.querySelector('input.select-dropdown');
|
|
189
|
+
const dropdown = instance.wrapper.querySelector('ul.select-dropdown');
|
|
190
|
+
|
|
191
|
+
expect(input).toExist('Should dynamically generate select dropdown structure.');
|
|
192
|
+
expect(dropdown).toExist('Should dynamically generate select dropdown structure.');
|
|
193
|
+
expect(input).toBeVisible('Should be visible before dropdown is opened.');
|
|
194
|
+
expect(dropdown).toBeHidden('Should be hidden before dropdown is opened.');
|
|
195
|
+
|
|
196
|
+
click(input);
|
|
197
|
+
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
expect(dropdown).toBeVisible('Should be visible after opening.');
|
|
200
|
+
|
|
201
|
+
let firstOption = dropdown.querySelector('li:not(.disabled)');
|
|
202
|
+
click(firstOption);
|
|
203
|
+
click(document.body);
|
|
204
|
+
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
firstOption = dropdown.querySelector('li:not(.disabled)');
|
|
207
|
+
const secondOption = dropdown.querySelectorAll('li:not(.disabled)')[1];
|
|
208
|
+
const thirdOption = dropdown.querySelectorAll('li:not(.disabled)')[2];
|
|
209
|
+
|
|
210
|
+
const selectedVals = Array.prototype.slice
|
|
211
|
+
.call(elem.querySelectorAll('option:checked'), 0)
|
|
212
|
+
.map((v) => v.value);
|
|
213
|
+
|
|
214
|
+
const selectedAria = Array.prototype.slice
|
|
215
|
+
.call(dropdown.querySelectorAll('li.selected'), 0)
|
|
216
|
+
.map((v) => v.getAttribute('aria-selected'));
|
|
217
|
+
|
|
218
|
+
const unselectedAria = Array.prototype.slice
|
|
219
|
+
.call(dropdown.querySelectorAll('li:not(.selected)'), 0)
|
|
220
|
+
.map((v) => v.getAttribute('aria-selected'));
|
|
221
|
+
|
|
222
|
+
expect(dropdown).toBeHidden('Should be hidden after choosing item.');
|
|
223
|
+
expect(selectedVals).toEqual(
|
|
224
|
+
['1', '2', '3'],
|
|
225
|
+
'Actual select should have correct selected values.'
|
|
226
|
+
);
|
|
227
|
+
expect(selectedAria).toEqual(
|
|
228
|
+
['true', 'true', 'true'],
|
|
229
|
+
'Selected values should be checked to assistive technologies.'
|
|
230
|
+
);
|
|
231
|
+
expect(unselectedAria).toEqual(
|
|
232
|
+
['false'],
|
|
233
|
+
'Unselected values should be checked to assistive technologies.'
|
|
234
|
+
);
|
|
235
|
+
expect(input.value).toEqual(
|
|
236
|
+
firstOption.innerText + ', ' + secondOption.innerText + ', ' + thirdOption.innerText,
|
|
237
|
+
'Value should equal chosen multiple options.'
|
|
238
|
+
);
|
|
239
|
+
done();
|
|
240
|
+
}, 10);
|
|
241
|
+
}, 10);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should open dropdown and deselect multiple options', (done) => {
|
|
245
|
+
const elem = document.querySelector('select.multiple');
|
|
246
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
247
|
+
const input = instance.wrapper.querySelector('input.select-dropdown');
|
|
248
|
+
const dropdown = instance.wrapper.querySelector('ul.select-dropdown');
|
|
249
|
+
|
|
250
|
+
expect(input).toExist('Should dynamically generate select dropdown structure.');
|
|
251
|
+
expect(dropdown).toExist('Should dynamically generate select dropdown structure.');
|
|
252
|
+
expect(input).toBeVisible('Should be hidden before dropdown is opened.');
|
|
253
|
+
expect(dropdown).toBeHidden('Should be hidden before dropdown is opened.');
|
|
254
|
+
|
|
255
|
+
click(input);
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
expect(dropdown).toBeVisible('Should be visible after opening.');
|
|
258
|
+
const disabledOption = dropdown.querySelector('li.disabled');
|
|
259
|
+
const secondOption = dropdown.querySelectorAll('li:not(.disabled)')[1];
|
|
260
|
+
const thirdOption = dropdown.querySelectorAll('li:not(.disabled)')[2];
|
|
261
|
+
click(secondOption);
|
|
262
|
+
click(thirdOption);
|
|
263
|
+
click(document.body);
|
|
264
|
+
|
|
265
|
+
setTimeout(() => {
|
|
266
|
+
expect(dropdown).toBeHidden('Should be hidden after choosing item.');
|
|
267
|
+
expect(elem.value).toEqual(
|
|
268
|
+
'',
|
|
269
|
+
'Actual select element should be empty because none chosen.'
|
|
270
|
+
);
|
|
271
|
+
expect(input.value).toEqual(
|
|
272
|
+
disabledOption.innerText,
|
|
273
|
+
'Value should equal default because none chosen.'
|
|
274
|
+
);
|
|
275
|
+
done();
|
|
276
|
+
}, 10);
|
|
277
|
+
}, 10);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('should have multiple pre-selected values', (done) => {
|
|
281
|
+
const elem = document.querySelector('select.multiple');
|
|
282
|
+
const instance = M.FormSelect.getInstance(elem);
|
|
283
|
+
const input = instance.wrapper.querySelector('input.select-dropdown');
|
|
284
|
+
const text = Array.from(elem.querySelectorAll('option[selected]'))
|
|
285
|
+
.map((o) => o.textContent)
|
|
286
|
+
.join(', ');
|
|
287
|
+
setTimeout(() => {
|
|
288
|
+
expect(input.value).toEqual(text, 'Value should equal preselected options.');
|
|
289
|
+
done();
|
|
290
|
+
}, 10);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe('Optgroup Select', () => {
|
|
295
|
+
let browserSelect, optInput, optDropdown, optionInOptgroup, optionAfterOptGroup, selectInstance;
|
|
296
|
+
|
|
297
|
+
beforeEach(() => {
|
|
298
|
+
browserSelect = document.querySelector('select.optgroup');
|
|
299
|
+
selectInstance = M.FormSelect.getInstance(browserSelect);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('Option groups should behave as such for assistive technologies', () => {
|
|
303
|
+
optInput = selectInstance.wrapper.querySelector('input.select-dropdown');
|
|
304
|
+
optDropdown = selectInstance.wrapper.querySelector('ul.select-dropdown');
|
|
305
|
+
const optgroups = optDropdown.querySelectorAll('li.optgroup');
|
|
306
|
+
const browerSelectOptgroups = browserSelect.querySelectorAll('optgroup');
|
|
307
|
+
for (let i = 0; i < optgroups.length; i++) {
|
|
308
|
+
expect(optgroups[i].getAttribute('role')).toBe('group', 'Should behave as group.');
|
|
309
|
+
}
|
|
310
|
+
for (let i = 0; i < browerSelectOptgroups.length; i++) {
|
|
311
|
+
expect(browerSelectOptgroups[i].children.length).toBe(
|
|
312
|
+
optgroups[i].getAttribute('aria-owns').split(' ').length,
|
|
313
|
+
'Browser option groups and custom groups must have the same ammount of children for assistive technologies'
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should open dropdown and select options', (done) => {
|
|
319
|
+
optInput = selectInstance.wrapper.querySelector('input.select-dropdown');
|
|
320
|
+
optDropdown = selectInstance.wrapper.querySelector('ul.select-dropdown');
|
|
321
|
+
const optgroups = optDropdown.querySelectorAll('li.optgroup');
|
|
322
|
+
const browerSelectOptgroups = browserSelect.querySelectorAll('optgroup');
|
|
323
|
+
for (let i = 0; i < browerSelectOptgroups.length; i++) {
|
|
324
|
+
expect(browerSelectOptgroups[i].label).toEqual(
|
|
325
|
+
optgroups[i].innerText,
|
|
326
|
+
'should generate optgroup structure.'
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
expect(optInput).toExist('Should dynamically generate select dropdown structure.');
|
|
330
|
+
expect(optDropdown).toExist('Should dynamically generate select dropdown structure.');
|
|
331
|
+
expect(optInput).toBeVisible('Should be hidden before dropdown is opened.');
|
|
332
|
+
expect(optDropdown).toBeHidden('Should be hidden before dropdown is opened.');
|
|
333
|
+
click(optInput);
|
|
334
|
+
setTimeout(() => {
|
|
335
|
+
expect(optDropdown).toBeVisible('Should be visible after opening.');
|
|
336
|
+
const secondOption = optDropdown.querySelectorAll('li:not(.disabled):not(.optgroup)')[1];
|
|
337
|
+
click(secondOption);
|
|
338
|
+
blur(optInput);
|
|
339
|
+
setTimeout(() => {
|
|
340
|
+
expect(optDropdown).toBeHidden('Should be hidden after choosing item.');
|
|
341
|
+
expect(optInput.value).toEqual(
|
|
342
|
+
secondOption.innerText,
|
|
343
|
+
'Value should be equal to selected option.'
|
|
344
|
+
);
|
|
345
|
+
done();
|
|
346
|
+
}, 10);
|
|
347
|
+
}, 10);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('should have options inside optgroup indented', () => {
|
|
351
|
+
optionInOptgroup = selectInstance.wrapper.querySelector('li.optgroup + li');
|
|
352
|
+
optionAfterOptGroup = selectInstance.wrapper.querySelector('ul li:last-child');
|
|
353
|
+
expect(optionInOptgroup).toHaveClass('optgroup-option', 'Should have optgroup-option class');
|
|
354
|
+
expect(optionAfterOptGroup).toNotHaveClass(
|
|
355
|
+
'optgroup-option',
|
|
356
|
+
'Should not have optgroup-option class'
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('should not do anything when optgroup li clicked', function (done) {
|
|
361
|
+
optInput = selectInstance.wrapper.querySelector('input.select-dropdown');
|
|
362
|
+
optDropdown = selectInstance.wrapper.querySelector('ul.select-dropdown');
|
|
363
|
+
const originalVal = optInput.value;
|
|
364
|
+
const optgroups = optDropdown.querySelectorAll('li.optgroup');
|
|
365
|
+
const browerSelectOptgroups = browserSelect.querySelectorAll('optgroup');
|
|
366
|
+
for (let i = 0; i < browerSelectOptgroups.length; i++) {
|
|
367
|
+
expect(browerSelectOptgroups[i].label).toEqual(
|
|
368
|
+
optgroups[i].innerText,
|
|
369
|
+
'should generate optgroup structure.'
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
expect(optInput).toExist('Should dynamically generate select dropdown structure.');
|
|
373
|
+
expect(optDropdown).toExist('Should dynamically generate select dropdown structure.');
|
|
374
|
+
expect(optInput).toBeVisible('Should be hidden before dropdown is opened.');
|
|
375
|
+
expect(optDropdown).toBeHidden('Should be hidden before dropdown is opened.');
|
|
376
|
+
click(optInput);
|
|
377
|
+
setTimeout(() => {
|
|
378
|
+
expect(optDropdown).toBeVisible('Should be visible after opening.');
|
|
379
|
+
const optgroup = optDropdown.querySelector('li.optgroup');
|
|
380
|
+
click(optgroup);
|
|
381
|
+
blur(optInput);
|
|
382
|
+
setTimeout(() => {
|
|
383
|
+
expect(optDropdown).toBeVisible('Should not be hidden after choosing invalid item.');
|
|
384
|
+
expect(optInput.value).toEqual(originalVal, 'Value should be equal to original option.');
|
|
385
|
+
done();
|
|
386
|
+
}, 10);
|
|
387
|
+
}, 10);
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component } from '../atomic/component.mjs';
|
|
2
|
+
|
|
3
|
+
class TextField extends Component {
|
|
4
|
+
#labelText;
|
|
5
|
+
#isReadOnly = false;
|
|
6
|
+
#isRequired = false;
|
|
7
|
+
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
this.setTagName('fieldset');
|
|
11
|
+
this.addClassname('form-field animated');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setLabel(label) {
|
|
15
|
+
this.#labelText = label;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toHTML() {
|
|
20
|
+
const elemId = 'elem-' + 100000 * Math.random();
|
|
21
|
+
const html = `<legend>${this.#labelText}</legend>
|
|
22
|
+
<input type="text" id="${elemId}" name="" placeholder="${this.#labelText}"/>
|
|
23
|
+
<label for="${elemId}">${this.#labelText}</label>`;
|
|
24
|
+
this.setChildren(html);
|
|
25
|
+
return super.toHTML();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { TextField };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { TextField } from './textfield.mjs';
|
|
3
|
+
|
|
4
|
+
describe('textfields', () => {
|
|
5
|
+
test('create html', () => {
|
|
6
|
+
const textfield = new TextField().setLabel('Name');
|
|
7
|
+
//console.log(list.toHTML());
|
|
8
|
+
expect(textfield.toHTML()).toContain('<input');
|
|
9
|
+
});
|
|
10
|
+
});
|