@shoper/phoenix_design_system 1.15.12 → 1.15.13
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/build/cjs/packages/phoenix/src/components/dropdown/dropdown.js +9 -2
- package/build/cjs/packages/phoenix/src/components/dropdown/dropdown.js.map +1 -1
- package/build/cjs/packages/phoenix/src/components/dropdown/dropdown_toggler.js +23 -5
- package/build/cjs/packages/phoenix/src/components/dropdown/dropdown_toggler.js.map +1 -1
- package/build/cjs/packages/phoenix/src/components/form/select/components/search/select_search.js +31 -0
- package/build/cjs/packages/phoenix/src/components/form/select/components/search/select_search.js.map +1 -1
- package/build/cjs/packages/phoenix/src/components/form/select/components/select_options.js +1 -2
- package/build/cjs/packages/phoenix/src/components/form/select/components/select_options.js.map +1 -1
- package/build/cjs/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.js +98 -0
- package/build/cjs/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.js.map +1 -0
- package/build/cjs/packages/phoenix/src/components/form/select/select.js +78 -19
- package/build/cjs/packages/phoenix/src/components/form/select/select.js.map +1 -1
- package/build/cjs/packages/phoenix/src/controllers/list_box_controller/list_box_keyboard_controller.js +76 -30
- package/build/cjs/packages/phoenix/src/controllers/list_box_controller/list_box_keyboard_controller.js.map +1 -1
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown.d.ts +1 -0
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown.js +9 -2
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown.js.map +1 -1
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown_toggler.d.ts +3 -0
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown_toggler.js +23 -5
- package/build/esm/packages/phoenix/src/components/dropdown/dropdown_toggler.js.map +1 -1
- package/build/esm/packages/phoenix/src/components/form/select/components/search/select_search.d.ts +4 -0
- package/build/esm/packages/phoenix/src/components/form/select/components/search/select_search.js +31 -0
- package/build/esm/packages/phoenix/src/components/form/select/components/search/select_search.js.map +1 -1
- package/build/esm/packages/phoenix/src/components/form/select/components/select_options.js +1 -2
- package/build/esm/packages/phoenix/src/components/form/select/components/select_options.js.map +1 -1
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.d.ts +15 -0
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.js +94 -0
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.js.map +1 -0
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller_types.d.ts +8 -0
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller_types.js +3 -0
- package/build/esm/packages/phoenix/src/components/form/select/controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller_types.js.map +1 -0
- package/build/esm/packages/phoenix/src/components/form/select/select.d.ts +14 -5
- package/build/esm/packages/phoenix/src/components/form/select/select.js +78 -19
- package/build/esm/packages/phoenix/src/components/form/select/select.js.map +1 -1
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_controller_types.d.ts +6 -2
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_controller_types.js +1 -0
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_controller_types.js.map +1 -1
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_keyboard_controller.d.ts +8 -3
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_keyboard_controller.js +76 -30
- package/build/esm/packages/phoenix/src/controllers/list_box_controller/list_box_keyboard_controller.js.map +1 -1
- package/package.json +2 -2
|
@@ -14,6 +14,7 @@ import { observe } from '../../../directives/observable_directive.js';
|
|
|
14
14
|
import { HSelectToggler } from './components/toggler/select_toggler.js';
|
|
15
15
|
import { createRef, ref } from 'lit-html/directives/ref.js';
|
|
16
16
|
import { ContextProviderController } from '../../../core/context/context_provider_controller.js';
|
|
17
|
+
import v4 from '../../../../../../external/uuid/dist/esm-browser/v4.js';
|
|
17
18
|
import { HDropdownContent } from '../../dropdown/dropdown_content.js';
|
|
18
19
|
import { HDropdownToggler } from '../../dropdown/dropdown_toggler.js';
|
|
19
20
|
import { HDropdown } from '../../dropdown/dropdown.js';
|
|
@@ -25,6 +26,7 @@ import { SelectControlUtils } from './select_utils.js';
|
|
|
25
26
|
import { SelectController } from './controllers/select_controller.js';
|
|
26
27
|
import { SelectOptionMapper } from './model/select_option_mapper.js';
|
|
27
28
|
import { repeat } from 'lit/directives/repeat';
|
|
29
|
+
import { SelectTogglerKeyboardController } from './controllers/select_toggler_keyboard_controller/select_toggler_keyboard_controller.js';
|
|
28
30
|
|
|
29
31
|
let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
30
32
|
constructor() {
|
|
@@ -36,14 +38,15 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
36
38
|
this.searchDisabled = false;
|
|
37
39
|
this.type = SELECT_TYPES.select;
|
|
38
40
|
this.noDeselect = false;
|
|
39
|
-
this.
|
|
41
|
+
this.assistiveTitleId = '';
|
|
42
|
+
this._selectOptionsId = v4();
|
|
40
43
|
this._searchValue = '';
|
|
41
44
|
this._$options = new Map();
|
|
42
|
-
this
|
|
43
|
-
this
|
|
45
|
+
this.$dropdown = createRef();
|
|
46
|
+
this.$search = createRef();
|
|
44
47
|
this._$optionsList = createRef();
|
|
45
48
|
this._$dropdownContent = createRef();
|
|
46
|
-
this
|
|
49
|
+
this.$dropdownToggler = createRef();
|
|
47
50
|
this._selectContext = new ContextProviderController(this);
|
|
48
51
|
this._updateOptions = () => {
|
|
49
52
|
const $options = this._getOptions();
|
|
@@ -101,6 +104,18 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
101
104
|
this.updateOptionAriaAttribute($option);
|
|
102
105
|
});
|
|
103
106
|
};
|
|
107
|
+
this._updateLabelAria = (options) => {
|
|
108
|
+
var _a, _b;
|
|
109
|
+
if (!this.$searchLabel)
|
|
110
|
+
return;
|
|
111
|
+
(_a = this.$searchLabel.querySelector(`[id="value-label"]`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
112
|
+
this.$searchLabel.innerHTML = `
|
|
113
|
+
${(_b = this.$searchLabel) === null || _b === void 0 ? void 0 : _b.innerHTML}
|
|
114
|
+
<span id="value-label" class="sr-only">
|
|
115
|
+
${options.reduce((totalSelectedContent, currentOption) => (totalSelectedContent += currentOption.content), '')}
|
|
116
|
+
</span>
|
|
117
|
+
`;
|
|
118
|
+
};
|
|
104
119
|
this._handleOptionClicked = ({ detail }) => {
|
|
105
120
|
if (!(detail === null || detail === void 0 ? void 0 : detail.$option))
|
|
106
121
|
return;
|
|
@@ -116,10 +131,15 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
116
131
|
});
|
|
117
132
|
};
|
|
118
133
|
this._handleDropdownHidden = () => {
|
|
119
|
-
var _a;
|
|
134
|
+
var _a, _b, _c;
|
|
120
135
|
this._searchValue = '';
|
|
121
136
|
this.opened = false;
|
|
122
|
-
(_a = this
|
|
137
|
+
(_a = this.$dropdownToggler.value) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-activedescendant', '');
|
|
138
|
+
const isBodyActive = document.activeElement === document.body;
|
|
139
|
+
const isInnerElementActive = (_b = this._$dropdownContent.value) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement);
|
|
140
|
+
if (isInnerElementActive || isBodyActive) {
|
|
141
|
+
(_c = this.$dropdownToggler.value) === null || _c === void 0 ? void 0 : _c.focus();
|
|
142
|
+
}
|
|
123
143
|
};
|
|
124
144
|
this._manageSelectFocusAria = (ev) => {
|
|
125
145
|
var _a;
|
|
@@ -128,14 +148,14 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
128
148
|
return;
|
|
129
149
|
const optionId = $target.id;
|
|
130
150
|
if (optionId) {
|
|
131
|
-
(_a = this
|
|
151
|
+
(_a = this.$dropdownToggler.value) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-activedescendant', optionId);
|
|
132
152
|
}
|
|
133
153
|
};
|
|
134
154
|
this._closeSelect = () => {
|
|
135
155
|
var _a;
|
|
136
156
|
if (!this.opened)
|
|
137
157
|
return;
|
|
138
|
-
(_a = this
|
|
158
|
+
(_a = this.$dropdown.value) === null || _a === void 0 ? void 0 : _a.hide();
|
|
139
159
|
};
|
|
140
160
|
this._clearOptions = () => {
|
|
141
161
|
this._selectController.deselectAll();
|
|
@@ -179,6 +199,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
179
199
|
return Array.from(this._$options.values());
|
|
180
200
|
}
|
|
181
201
|
updated(changedProperties) {
|
|
202
|
+
var _a, _b;
|
|
182
203
|
super.updated(changedProperties);
|
|
183
204
|
if (changedProperties.has('opened')) {
|
|
184
205
|
if (this.opened) {
|
|
@@ -192,28 +213,52 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
192
213
|
if (changedProperties.has('optionsList')) {
|
|
193
214
|
this._updateOptions();
|
|
194
215
|
}
|
|
195
|
-
if (this._$optionsList.value
|
|
196
|
-
this.
|
|
216
|
+
if (this._$optionsList.value) {
|
|
217
|
+
(_a = this.listBoxController) === null || _a === void 0 ? void 0 : _a.hostDisconnected();
|
|
218
|
+
this.listBoxController = new ListBoxKeyboardController({
|
|
197
219
|
host: this,
|
|
198
220
|
$list: this._$optionsList.value
|
|
199
221
|
});
|
|
222
|
+
}
|
|
223
|
+
if (this.listBoxController) {
|
|
224
|
+
this.listBoxController.calculateSelectedOptionIndex();
|
|
225
|
+
}
|
|
226
|
+
if (this._$optionsList.value && this.$dropdownToggler.value) {
|
|
227
|
+
(_b = this._selectTogglerKeyboardController) === null || _b === void 0 ? void 0 : _b.hostDisconnected();
|
|
228
|
+
this._selectTogglerKeyboardController = new SelectTogglerKeyboardController({
|
|
229
|
+
host: this,
|
|
230
|
+
$toggler: this.$dropdownToggler.value,
|
|
231
|
+
$list: this._$optionsList.value
|
|
232
|
+
});
|
|
233
|
+
}
|
|
200
234
|
}
|
|
201
235
|
_focusElementAfterSelectOpened() {
|
|
202
|
-
var _a
|
|
203
|
-
const $searchInput = (_a = this
|
|
204
|
-
$
|
|
236
|
+
var _a;
|
|
237
|
+
const $searchInput = (_a = this.$search.value) === null || _a === void 0 ? void 0 : _a.querySelector('[role="search"]');
|
|
238
|
+
const $options = this._$optionsList.value ? [...this._$optionsList.value.querySelectorAll('h-option')] : [];
|
|
239
|
+
const $firstOption = $options.find(($option) => {
|
|
240
|
+
return !$option.getAttribute('inactive') && !$option.getAttribute('disabled') && !$option.getAttribute('hidden');
|
|
241
|
+
});
|
|
242
|
+
const $selectedOption = this.selectedOptions[0];
|
|
243
|
+
const $optionToFocus = $selectedOption || $firstOption;
|
|
244
|
+
$searchInput ? $searchInput.focus() : $optionToFocus === null || $optionToFocus === void 0 ? void 0 : $optionToFocus.focus();
|
|
205
245
|
}
|
|
206
246
|
connectedCallback() {
|
|
247
|
+
var _a;
|
|
207
248
|
super.connectedCallback();
|
|
208
249
|
this.classList.add(SELECT_CSS_CLASSES.select);
|
|
209
250
|
if (!this.searchDisabled) {
|
|
210
251
|
this.classList.add(SELECT_CSS_CLASSES.selectWithSearch);
|
|
211
252
|
}
|
|
253
|
+
this.$searchLabel = document.querySelector(`[id="${this.assistiveTitleId}"]`);
|
|
254
|
+
(_a = this.$searchLabel) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-hidden', 'true');
|
|
212
255
|
this._selectController = this.multiple ? new MultiSelectController({ host: this }) : new SelectController({ host: this });
|
|
213
256
|
this._selectContext.provide(SELECT_CONTEXTS.selectedOptions$, this._selectController.selectedOptions$);
|
|
214
257
|
this._selectContext.provide(SELECT_CONTEXTS.isMultiselect, this.multiple);
|
|
215
258
|
this._optionsObserver = new Observer((selectedOptions) => this._updateOptionsView(selectedOptions));
|
|
216
259
|
this._selectController.options$.subscribe(this._optionsObserver);
|
|
260
|
+
this._selectedOptionsAriaObserver = new Observer((selectedOptions) => this._updateLabelAria(selectedOptions));
|
|
261
|
+
this._selectController.selectedOptions$.subscribe(this._selectedOptionsAriaObserver);
|
|
217
262
|
this._updateOptions();
|
|
218
263
|
this._setupEvents();
|
|
219
264
|
}
|
|
@@ -243,6 +288,10 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
243
288
|
SelectControlUtils.appendHTMLOption($option, $list, position);
|
|
244
289
|
}
|
|
245
290
|
updateOptionAriaAttribute($option) {
|
|
291
|
+
if (!this.multiple) {
|
|
292
|
+
const $options = this._$optionsList.value ? [...this._$optionsList.value.querySelectorAll('h-option')] : [];
|
|
293
|
+
$options.forEach(($option) => ($option.removeAttribute('aria-selected')));
|
|
294
|
+
}
|
|
246
295
|
$option.setAttribute(this.multiple ? 'aria-checked' : 'aria-selected', String($option.selected));
|
|
247
296
|
}
|
|
248
297
|
_removeHTMLOptions(optionsValues) {
|
|
@@ -252,6 +301,12 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
252
301
|
const option = this._selectController.getOption(value);
|
|
253
302
|
if (!option)
|
|
254
303
|
return;
|
|
304
|
+
const $selectedOption = this._$options.get(option.value);
|
|
305
|
+
const $selectedOptionLink = $selectedOption === null || $selectedOption === void 0 ? void 0 : $selectedOption.querySelector('a');
|
|
306
|
+
if ($selectedOptionLink) {
|
|
307
|
+
$selectedOptionLink.click();
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
255
310
|
this.noDeselect ? this._selectController.select(option) : this._selectController.toggle(option);
|
|
256
311
|
if (!this.multiple)
|
|
257
312
|
this._closeSelect();
|
|
@@ -302,23 +357,25 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
302
357
|
const isSearchEnabled = !this.searchDisabled && options.length > MIN_NUMBER_OF_OPTIONS_TO_SHOW_SEARCH;
|
|
303
358
|
return html `
|
|
304
359
|
<h-dropdown
|
|
305
|
-
${ref(this
|
|
360
|
+
${ref(this.$dropdown)}
|
|
306
361
|
@showed=${() => (this.opened = true)}
|
|
307
362
|
@hidden=${this._handleDropdownHidden}
|
|
308
363
|
name="${this.controlName}"
|
|
309
364
|
offset=${this.offset}
|
|
310
365
|
content-width="full"
|
|
311
366
|
prevent-focus-trap
|
|
367
|
+
no-autofocus
|
|
312
368
|
>
|
|
313
369
|
<h-dropdown-toggler
|
|
314
|
-
${ref(this
|
|
370
|
+
${ref(this.$dropdownToggler)}
|
|
315
371
|
name="${this.controlName}"
|
|
316
372
|
validation-container
|
|
317
373
|
aria-haspopup="listbox"
|
|
318
374
|
role="combobox"
|
|
319
375
|
aria-required="${this.required ? 'true' : 'false'}"
|
|
320
376
|
aria-activedescendant
|
|
321
|
-
|
|
377
|
+
role="combobox"
|
|
378
|
+
aria-controls="${this._selectOptionsId}"
|
|
322
379
|
>
|
|
323
380
|
${this.getSlot(SELECT_SLOT_NAMES.toggler)}
|
|
324
381
|
</h-dropdown-toggler>
|
|
@@ -336,7 +393,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
336
393
|
${isSearchEnabled
|
|
337
394
|
? html ` <h-select-search
|
|
338
395
|
class=${SELECT_CSS_CLASSES.selectSearch}
|
|
339
|
-
${ref(this
|
|
396
|
+
${ref(this.$search)}
|
|
340
397
|
.value=${this._searchValue}
|
|
341
398
|
@search=${this._handleSearch}
|
|
342
399
|
></h-select-search>`
|
|
@@ -344,6 +401,8 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
|
|
|
344
401
|
|
|
345
402
|
<h-options
|
|
346
403
|
class="${SELECT_CSS_CLASSES.selectOptions} ${this._searchNoResult() ? SELECT_CSS_CLASSES.selectOptionsEmpty : ''}"
|
|
404
|
+
aria-labelledby="${this.assistiveTitleId}"
|
|
405
|
+
id="${this._selectOptionsId}"
|
|
347
406
|
${ref(this._$optionsList)}
|
|
348
407
|
@optionClicked=${this._handleOptionClicked}
|
|
349
408
|
@optionUpdated=${this._handleOptionUpdated}
|
|
@@ -435,9 +494,9 @@ __decorate([
|
|
|
435
494
|
__metadata("design:type", Boolean)
|
|
436
495
|
], HSelect.prototype, "noDeselect", void 0);
|
|
437
496
|
__decorate([
|
|
438
|
-
property({ type: String, attribute: '
|
|
497
|
+
property({ type: String, attribute: 'assistive-title-id' }),
|
|
439
498
|
__metadata("design:type", String)
|
|
440
|
-
], HSelect.prototype, "
|
|
499
|
+
], HSelect.prototype, "assistiveTitleId", void 0);
|
|
441
500
|
__decorate([
|
|
442
501
|
state(),
|
|
443
502
|
__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,+CAAmD;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
1
|
+
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,+CAAmD;AAC1F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,wDAA4D;AAC3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Any } from 'ts-toolbelt';
|
|
2
|
-
import { ReactiveControllerHost } from 'lit';
|
|
2
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
3
3
|
import { LIST_BOX_KEYBOARD_NAVIGATION_DIRECTIONS } from "./list_box_controller_constants";
|
|
4
|
+
import { HSelect } from "../../components/form/select/select";
|
|
4
5
|
export declare type TListBoxKeyboardNavigationDirection = Any.Keys<typeof LIST_BOX_KEYBOARD_NAVIGATION_DIRECTIONS>;
|
|
5
6
|
export declare type TListBoxKeyboardControllerConstructorOptions = {
|
|
6
|
-
host: ReactiveControllerHost &
|
|
7
|
+
host: ReactiveControllerHost & HSelect;
|
|
7
8
|
$list: HTMLElement;
|
|
8
9
|
listItemSelector?: string;
|
|
9
10
|
orientation?: TListBoxKeyboardNavigationDirection;
|
|
10
11
|
};
|
|
12
|
+
export interface IListboxController extends ReactiveController {
|
|
13
|
+
calculateSelectedOptionIndex(): void;
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list_box_controller_types.js","sourceRoot":"","sources":["../../../../../../../src/controllers/list_box_controller/list_box_controller_types.ts"],"names":[],"mappings":"AAAA,OAAoB,aAAa,CAAC;AAClC,
|
|
1
|
+
{"version":3,"file":"list_box_controller_types.js","sourceRoot":"","sources":["../../../../../../../src/controllers/list_box_controller/list_box_controller_types.ts"],"names":[],"mappings":"AAAA,OAAoB,aAAa,CAAC;AAClC,OAA2D,KAAK,CAAC;AACjE,OAAwD,4EAA4E,CAAC;AACrI,OAAwB,4CAA4C,CAAC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare class ListBoxKeyboardController implements ReactiveController {
|
|
1
|
+
import { IListboxController, TListBoxKeyboardControllerConstructorOptions } from "./list_box_controller_types";
|
|
2
|
+
export declare class ListBoxKeyboardController implements IListboxController {
|
|
4
3
|
#private;
|
|
4
|
+
currentOptionIndex: number | undefined;
|
|
5
5
|
constructor({ host, $list, listItemSelector, orientation }: TListBoxKeyboardControllerConstructorOptions);
|
|
6
6
|
hostConnected(): void;
|
|
7
|
+
private _handleKeyboardNavigation;
|
|
7
8
|
private _handleArrowNavigation;
|
|
9
|
+
private _findCurrentIndex;
|
|
10
|
+
private _handleWriteableCharacter;
|
|
11
|
+
calculateSelectedOptionIndex: () => void;
|
|
8
12
|
private _getPrevOptionIndex;
|
|
9
13
|
private _getNextOptionIndex;
|
|
14
|
+
hostDisconnected(): void;
|
|
10
15
|
}
|
|
@@ -1,37 +1,64 @@
|
|
|
1
1
|
import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../../../external/tslib/tslib.es6.js';
|
|
2
2
|
import 'lit';
|
|
3
3
|
import { UiDomUtils } from '@dreamcommerce/utilities';
|
|
4
|
-
import { KeystrokesController } from '../keystrokes_controller/keystrokes_controller.js';
|
|
5
4
|
import { LIST_BOX_KEYBOARD_NAVIGATION_DIRECTIONS } from './list_box_controller_constants.js';
|
|
6
5
|
|
|
7
|
-
var _ListBoxKeyboardController_host, _ListBoxKeyboardController__$list,
|
|
6
|
+
var _ListBoxKeyboardController_host, _ListBoxKeyboardController__$list, _ListBoxKeyboardController__$options, _ListBoxKeyboardController_listItemSelector, _ListBoxKeyboardController_keys;
|
|
8
7
|
class ListBoxKeyboardController {
|
|
9
8
|
constructor({ host, $list, listItemSelector = '[role="option"]', orientation = LIST_BOX_KEYBOARD_NAVIGATION_DIRECTIONS.vertical }) {
|
|
10
9
|
_ListBoxKeyboardController_host.set(this, void 0);
|
|
11
10
|
_ListBoxKeyboardController__$list.set(this, void 0);
|
|
12
|
-
_ListBoxKeyboardController_currentOptionIndex.set(this, void 0);
|
|
13
11
|
_ListBoxKeyboardController__$options.set(this, void 0);
|
|
14
12
|
_ListBoxKeyboardController_listItemSelector.set(this, void 0);
|
|
15
13
|
_ListBoxKeyboardController_keys.set(this, void 0);
|
|
14
|
+
this._handleKeyboardNavigation = (ev) => {
|
|
15
|
+
if (__classPrivateFieldGet(this, _ListBoxKeyboardController_keys, "f").find((key) => key === ev.key)) {
|
|
16
|
+
this._handleArrowNavigation(ev);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this._handleWriteableCharacter(ev);
|
|
20
|
+
};
|
|
16
21
|
this._handleArrowNavigation = (event) => {
|
|
17
22
|
event.preventDefault();
|
|
18
23
|
const { key } = event;
|
|
19
|
-
const
|
|
24
|
+
const $availableOptions = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").filter(($option) => {
|
|
25
|
+
return !$option.getAttribute('inactive') && !$option.getAttribute('disabled') && !$option.hidden;
|
|
26
|
+
});
|
|
27
|
+
const prevOptionIndex = this._findCurrentIndex();
|
|
20
28
|
let newOptionIndex = key === 'ArrowDown' || key === 'ArrowRight' ? this._getNextOptionIndex() : this._getPrevOptionIndex();
|
|
21
29
|
if (newOptionIndex === undefined) {
|
|
22
|
-
|
|
23
|
-
newOptionIndex = selectedOptionIndex !== -1 ? selectedOptionIndex : 0;
|
|
30
|
+
newOptionIndex = this._findCurrentIndex();
|
|
24
31
|
}
|
|
25
|
-
if (newOptionIndex ===
|
|
32
|
+
if (newOptionIndex === this.currentOptionIndex)
|
|
26
33
|
return;
|
|
27
34
|
if (prevOptionIndex !== undefined) {
|
|
28
35
|
const $prevOption = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f")[prevOptionIndex];
|
|
29
|
-
UiDomUtils.makeUnnavigable($prevOption);
|
|
36
|
+
$prevOption && UiDomUtils.makeUnnavigable($prevOption);
|
|
30
37
|
}
|
|
31
|
-
|
|
32
|
-
const $focusedOption =
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
this.currentOptionIndex = newOptionIndex;
|
|
39
|
+
const $focusedOption = $availableOptions[newOptionIndex];
|
|
40
|
+
if ($focusedOption) {
|
|
41
|
+
UiDomUtils.makeNavigable($focusedOption);
|
|
42
|
+
$focusedOption.focus();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this._findCurrentIndex = () => {
|
|
46
|
+
const $availableOptions = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").filter(($option) => {
|
|
47
|
+
return !$option.getAttribute('inactive') && !$option.getAttribute('disabled') && !$option.hidden;
|
|
48
|
+
});
|
|
49
|
+
const selectedOptionIndex = $availableOptions.findIndex(($option) => $option.selected);
|
|
50
|
+
return selectedOptionIndex !== -1 ? selectedOptionIndex : 0;
|
|
51
|
+
};
|
|
52
|
+
this._handleWriteableCharacter = (ev) => {
|
|
53
|
+
var _a;
|
|
54
|
+
const $searchInput = (_a = __classPrivateFieldGet(this, _ListBoxKeyboardController_host, "f").$search.value) === null || _a === void 0 ? void 0 : _a.querySelector('[role="search"]');
|
|
55
|
+
if (!$searchInput)
|
|
56
|
+
return;
|
|
57
|
+
$searchInput === null || $searchInput === void 0 ? void 0 : $searchInput.focus();
|
|
58
|
+
};
|
|
59
|
+
this.calculateSelectedOptionIndex = () => {
|
|
60
|
+
const selectedOptionIndex = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").findIndex(($option) => $option.selected);
|
|
61
|
+
this.currentOptionIndex = selectedOptionIndex !== -1 ? selectedOptionIndex : 0;
|
|
35
62
|
};
|
|
36
63
|
__classPrivateFieldSet(this, _ListBoxKeyboardController_host, host, "f");
|
|
37
64
|
__classPrivateFieldSet(this, _ListBoxKeyboardController__$list, $list, "f");
|
|
@@ -41,40 +68,59 @@ class ListBoxKeyboardController {
|
|
|
41
68
|
__classPrivateFieldGet(this, _ListBoxKeyboardController_host, "f").addController(this);
|
|
42
69
|
}
|
|
43
70
|
hostConnected() {
|
|
44
|
-
|
|
45
|
-
host: __classPrivateFieldGet(this, _ListBoxKeyboardController_host, "f"),
|
|
46
|
-
keys: __classPrivateFieldGet(this, _ListBoxKeyboardController_keys, "f"),
|
|
47
|
-
callback: this._handleArrowNavigation,
|
|
48
|
-
target: __classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f")
|
|
49
|
-
});
|
|
71
|
+
__classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f").addEventListener('keydown', this._handleKeyboardNavigation);
|
|
50
72
|
UiDomUtils.makeNavigable(__classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f"));
|
|
51
73
|
__classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f").addEventListener('focusin', (event) => {
|
|
52
74
|
if (event.target !== __classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f"))
|
|
53
75
|
return;
|
|
54
|
-
if (
|
|
76
|
+
if (this.currentOptionIndex === undefined)
|
|
55
77
|
return;
|
|
56
|
-
const $prevOption = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f")[
|
|
78
|
+
const $prevOption = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f")[this.currentOptionIndex];
|
|
57
79
|
UiDomUtils.makeUnnavigable($prevOption);
|
|
58
|
-
|
|
80
|
+
this.currentOptionIndex = undefined;
|
|
59
81
|
});
|
|
60
82
|
__classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").forEach(($option) => UiDomUtils.makeUnnavigable($option));
|
|
61
83
|
}
|
|
62
84
|
_getPrevOptionIndex() {
|
|
63
|
-
if (
|
|
85
|
+
if (this.currentOptionIndex === undefined)
|
|
64
86
|
return undefined;
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
67
|
-
|
|
87
|
+
if (this.currentOptionIndex <= 0)
|
|
88
|
+
return this.currentOptionIndex;
|
|
89
|
+
if (this.currentOptionIndex <= 0)
|
|
90
|
+
return this.currentOptionIndex;
|
|
91
|
+
const $availableOptions = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").filter(($option) => {
|
|
92
|
+
return !$option.getAttribute('inactive') && !$option.getAttribute('disabled') && !$option.hidden;
|
|
93
|
+
});
|
|
94
|
+
if (!!$availableOptions[this.currentOptionIndex - 1])
|
|
95
|
+
return this.currentOptionIndex - 1;
|
|
96
|
+
// bo ktoś wpisał coś w searcha i index obecnie wybranej opcji jest inny
|
|
97
|
+
const newIndexOfCurrentlySelectedOption = $availableOptions.findIndex(($option) => $option.selected);
|
|
98
|
+
if (newIndexOfCurrentlySelectedOption)
|
|
99
|
+
return newIndexOfCurrentlySelectedOption - 1;
|
|
100
|
+
return this.currentOptionIndex - 1;
|
|
68
101
|
}
|
|
69
102
|
_getNextOptionIndex() {
|
|
70
|
-
if (
|
|
103
|
+
if (this.currentOptionIndex === undefined)
|
|
71
104
|
return undefined;
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
-
|
|
105
|
+
const $availableOptions = __classPrivateFieldGet(this, _ListBoxKeyboardController__$options, "f").filter(($option) => {
|
|
106
|
+
return !$option.getAttribute('inactive') && !$option.getAttribute('disabled') && !$option.hidden;
|
|
107
|
+
});
|
|
108
|
+
if (this.currentOptionIndex === $availableOptions.length - 1)
|
|
109
|
+
return this.currentOptionIndex;
|
|
110
|
+
if (this.currentOptionIndex > $availableOptions.length - 1) {
|
|
111
|
+
// bo ktoś wpisał coś w searcha i index obecnie wybranej opcji jest inny
|
|
112
|
+
const newIndexOfCurrentlySelectedOption = $availableOptions.findIndex(($option) => $option.selected);
|
|
113
|
+
if (newIndexOfCurrentlySelectedOption)
|
|
114
|
+
return newIndexOfCurrentlySelectedOption + 1;
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
return this.currentOptionIndex + 1;
|
|
118
|
+
}
|
|
119
|
+
hostDisconnected() {
|
|
120
|
+
__classPrivateFieldGet(this, _ListBoxKeyboardController__$list, "f").removeEventListener('keydown', this._handleKeyboardNavigation);
|
|
75
121
|
}
|
|
76
122
|
}
|
|
77
|
-
_ListBoxKeyboardController_host = new WeakMap(), _ListBoxKeyboardController__$list = new WeakMap(),
|
|
123
|
+
_ListBoxKeyboardController_host = new WeakMap(), _ListBoxKeyboardController__$list = new WeakMap(), _ListBoxKeyboardController__$options = new WeakMap(), _ListBoxKeyboardController_listItemSelector = new WeakMap(), _ListBoxKeyboardController_keys = new WeakMap();
|
|
78
124
|
|
|
79
125
|
export { ListBoxKeyboardController };
|
|
80
126
|
//# sourceMappingURL=list_box_keyboard_controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,+DAA+D,4CAAgD;AAC/G;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
1
|
+
{"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,+DAA+D,4CAAgD;AAC/G;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@shoper/phoenix_design_system",
|
|
3
3
|
"packageManager": "yarn@3.2.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "1.15.
|
|
5
|
+
"version": "1.15.13",
|
|
6
6
|
"description": "phoenix design system",
|
|
7
7
|
"author": "zefirek",
|
|
8
8
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@splidejs/splide": "^4.0.7"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@dreamcommerce/utilities": "^1.20.1",
|
|
33
|
+
"@dreamcommerce/utilities": "^1.20.1-0",
|
|
34
34
|
"@shoper/jest_config": "^0.0.0",
|
|
35
35
|
"@shoper/tsconfig": "^0.0.0",
|
|
36
36
|
"@splidejs/splide": "4.0.7",
|