@shoper/phoenix_design_system 1.18.23-9 → 1.18.24

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.
Files changed (83) hide show
  1. package/build/cjs/packages/phoenix/src/components/dropdown/dropdown.js +77 -14
  2. package/build/cjs/packages/phoenix/src/components/dropdown/dropdown.js.map +1 -1
  3. package/build/cjs/packages/phoenix/src/components/form/search/search.js +4 -28
  4. package/build/cjs/packages/phoenix/src/components/form/search/search.js.map +1 -1
  5. package/build/cjs/packages/phoenix/src/components/form/search/subcomponents/input/search_input.js +13 -3
  6. package/build/cjs/packages/phoenix/src/components/form/search/subcomponents/input/search_input.js.map +1 -1
  7. package/build/cjs/packages/phoenix/src/components/form/select/select.js +18 -37
  8. package/build/cjs/packages/phoenix/src/components/form/select/select.js.map +1 -1
  9. package/build/cjs/packages/phoenix/src/components/modal/modal.js +67 -13
  10. package/build/cjs/packages/phoenix/src/components/modal/modal.js.map +1 -1
  11. package/build/cjs/packages/phoenix/src/components/modal/modal_constants.js +3 -1
  12. package/build/cjs/packages/phoenix/src/components/modal/modal_constants.js.map +1 -1
  13. package/build/cjs/packages/phoenix/src/components/sheet/sheet.js +63 -9
  14. package/build/cjs/packages/phoenix/src/components/sheet/sheet.js.map +1 -1
  15. package/build/cjs/packages/phoenix/src/components/sheet/sheet_constants.js +3 -1
  16. package/build/cjs/packages/phoenix/src/components/sheet/sheet_constants.js.map +1 -1
  17. package/build/esm/packages/phoenix/src/components/dropdown/dropdown.d.ts +6 -1
  18. package/build/esm/packages/phoenix/src/components/dropdown/dropdown.js +77 -14
  19. package/build/esm/packages/phoenix/src/components/dropdown/dropdown.js.map +1 -1
  20. package/build/esm/packages/phoenix/src/components/form/search/search.d.ts +0 -5
  21. package/build/esm/packages/phoenix/src/components/form/search/search.js +4 -28
  22. package/build/esm/packages/phoenix/src/components/form/search/search.js.map +1 -1
  23. package/build/esm/packages/phoenix/src/components/form/search/subcomponents/input/search_input.js +13 -3
  24. package/build/esm/packages/phoenix/src/components/form/search/subcomponents/input/search_input.js.map +1 -1
  25. package/build/esm/packages/phoenix/src/components/form/select/select.d.ts +0 -1
  26. package/build/esm/packages/phoenix/src/components/form/select/select.js +18 -37
  27. package/build/esm/packages/phoenix/src/components/form/select/select.js.map +1 -1
  28. package/build/esm/packages/phoenix/src/components/modal/modal.d.ts +9 -1
  29. package/build/esm/packages/phoenix/src/components/modal/modal.js +69 -15
  30. package/build/esm/packages/phoenix/src/components/modal/modal.js.map +1 -1
  31. package/build/esm/packages/phoenix/src/components/modal/modal_constants.js +3 -2
  32. package/build/esm/packages/phoenix/src/components/modal/modal_constants.js.map +1 -1
  33. package/build/esm/packages/phoenix/src/components/sheet/sheet.d.ts +9 -1
  34. package/build/esm/packages/phoenix/src/components/sheet/sheet.js +65 -11
  35. package/build/esm/packages/phoenix/src/components/sheet/sheet.js.map +1 -1
  36. package/build/esm/packages/phoenix/src/components/sheet/sheet_constants.js +3 -2
  37. package/build/esm/packages/phoenix/src/components/sheet/sheet_constants.js.map +1 -1
  38. package/package.json +1 -1
  39. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller.js +0 -38
  40. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller.js.map +0 -1
  41. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy.js +0 -66
  42. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy.js.map +0 -1
  43. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy.js +0 -14
  44. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy.js.map +0 -1
  45. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/focus_trap_strategy_constants.js +0 -22
  46. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/focus_trap_strategy_constants.js.map +0 -1
  47. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy.js +0 -29
  48. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy.js.map +0 -1
  49. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy.js +0 -62
  50. package/build/cjs/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy.js.map +0 -1
  51. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller.d.ts +0 -13
  52. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller.js +0 -34
  53. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller.js.map +0 -1
  54. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller_types.d.ts +0 -15
  55. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller_types.js +0 -2
  56. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/focus_trap_controller_types.js.map +0 -1
  57. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy.d.ts +0 -14
  58. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy.js +0 -62
  59. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy.js.map +0 -1
  60. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy_types.d.ts +0 -8
  61. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy_types.js +0 -2
  62. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/base_focus_trap_strategy_types.js.map +0 -1
  63. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy.d.ts +0 -6
  64. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy.js +0 -10
  65. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy.js.map +0 -1
  66. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy_types.d.ts +0 -3
  67. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy_types.js +0 -2
  68. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/cyclic_focus_trap_strategy/cyclic_focus_trap_strategy_types.js.map +0 -1
  69. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/focus_trap_strategy_constants.d.ts +0 -13
  70. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/focus_trap_strategy_constants.js +0 -17
  71. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/focus_trap_strategy_constants.js.map +0 -1
  72. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy.d.ts +0 -7
  73. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy.js +0 -25
  74. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy.js.map +0 -1
  75. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy_types.d.ts +0 -4
  76. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy_types.js +0 -2
  77. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/sentinel_focus_trap_strategy/sentinel_focus_trap_strategy_types.js.map +0 -1
  78. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy.d.ts +0 -8
  79. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy.js +0 -58
  80. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy.js.map +0 -1
  81. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy_types.d.ts +0 -4
  82. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy_types.js +0 -2
  83. package/build/esm/packages/phoenix/src/controllers/focus_trap_controller/strategies/toggler_focus_trap_strategy/toggler_focus_trap_strategy_types.js.map +0 -1
@@ -30,7 +30,6 @@ import { SelectTogglerKeyboardController } from './controllers/select_toggler_ke
30
30
 
31
31
  let HSelect = class HSelect extends PhoenixLightLitElement {
32
32
  constructor() {
33
- var _a;
34
33
  super();
35
34
  this.multiple = false;
36
35
  this.opened = false;
@@ -39,7 +38,6 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
39
38
  this.type = SELECT_TYPES.select;
40
39
  this.noDeselect = false;
41
40
  this.assistiveTitleId = '';
42
- this.isDevSelectPlaceholderFlagEnabled = false;
43
41
  this.isReactiveSelectionFlagEnabled = false;
44
42
  this.translations = {};
45
43
  this._selectOptionsId = v4();
@@ -51,6 +49,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
51
49
  this._$dropdownContent = createRef();
52
50
  this.$dropdownToggler = createRef();
53
51
  this._selectContext = new ContextProviderController(this);
52
+ this.$placeholder = 'Select';
54
53
  this._updateOptions = () => {
55
54
  const $options = this._getOptions();
56
55
  this._$options = $options.reduce((acc, $option) => {
@@ -108,28 +107,18 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
108
107
  });
109
108
  };
110
109
  this._updateLabelAria = (options) => {
111
- var _a, _b;
110
+ var _a;
112
111
  if (!this.$searchLabel)
113
112
  return;
114
113
  (_a = this.$searchLabel.querySelector(`[id="value-label"]`)) === null || _a === void 0 ? void 0 : _a.remove();
115
- if (this.isDevSelectPlaceholderFlagEnabled) {
116
- const hasValidOptions = options.some((option) => !option.isPlaceholder);
117
- if (!hasValidOptions)
118
- return;
119
- const valueLabelSpan = document.createElement('span');
120
- valueLabelSpan.id = 'value-label';
121
- valueLabelSpan.className = 'sr-only';
122
- valueLabelSpan.textContent = options.reduce((totalSelectedContent, currentOption) => totalSelectedContent + currentOption.content, '');
123
- this.$searchLabel.appendChild(valueLabelSpan);
124
- }
125
- else {
126
- this.$searchLabel.innerHTML = `
127
- ${(_b = this.$searchLabel) === null || _b === void 0 ? void 0 : _b.innerHTML}
128
- <span id="value-label" class="sr-only">
129
- ${options.reduce((totalSelectedContent, currentOption) => (totalSelectedContent += currentOption.content), '')}
130
- </span>
131
- `;
132
- }
114
+ const hasValidOptions = options.some((option) => !option.isPlaceholder);
115
+ if (!hasValidOptions)
116
+ return;
117
+ const valueLabelSpan = document.createElement('span');
118
+ valueLabelSpan.id = 'value-label';
119
+ valueLabelSpan.className = 'sr-only';
120
+ valueLabelSpan.textContent = options.reduce((totalSelectedContent, currentOption) => totalSelectedContent + currentOption.content, '');
121
+ this.$searchLabel.appendChild(valueLabelSpan);
133
122
  };
134
123
  this._handleOptionClicked = ({ detail }) => {
135
124
  if (!(detail === null || detail === void 0 ? void 0 : detail.$option))
@@ -181,8 +170,6 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
181
170
  };
182
171
  const $options = Array.from(this.querySelectorAll(SELECT_RELATED_COMPONENTS_NAMES.option));
183
172
  $options.forEach(($option) => $option.setAttribute('slot', SELECT_SLOT_NAMES.content));
184
- const $placeholderEl = this.querySelector(`[slot="${SELECT_INPUT_PLACEHOLDER_SLOT_NAME}"]`);
185
- this.$placeholder = $placeholderEl && ((_a = $placeholderEl.textContent) === null || _a === void 0 ? void 0 : _a.trim()) ? $placeholderEl : 'Select';
186
173
  if (this.multiple)
187
174
  this.type = SELECT_TYPES.multiple;
188
175
  }
@@ -228,9 +215,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
228
215
  }
229
216
  if (changedProperties.has('optionsList')) {
230
217
  this._updateOptions();
231
- if (this.isDevSelectPlaceholderFlagEnabled) {
232
- this._addPlaceholderOptionIfNeeded();
233
- }
218
+ this._addPlaceholderOptionIfNeeded();
234
219
  }
235
220
  if (this._$optionsList.value) {
236
221
  (_a = this.listBoxController) === null || _a === void 0 ? void 0 : _a.hostDisconnected();
@@ -263,7 +248,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
263
248
  $searchInput ? $searchInput.focus() : $optionToFocus === null || $optionToFocus === void 0 ? void 0 : $optionToFocus.focus();
264
249
  }
265
250
  connectedCallback() {
266
- var _a;
251
+ var _a, _b;
267
252
  super.connectedCallback();
268
253
  this.classList.add(SELECT_CSS_CLASSES.select);
269
254
  if (!this.searchDisabled) {
@@ -278,10 +263,12 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
278
263
  this._selectController.options$.subscribe(this._optionsObserver);
279
264
  this._selectedOptionsAriaObserver = new Observer((selectedOptions) => this._updateLabelAria(selectedOptions));
280
265
  this._selectController.selectedOptions$.subscribe(this._selectedOptionsAriaObserver);
281
- this._updateOptions();
282
- if (this.isDevSelectPlaceholderFlagEnabled) {
283
- this._addPlaceholderOptionIfNeeded();
266
+ const $placeholderEl = this.querySelector(`[slot="${SELECT_INPUT_PLACEHOLDER_SLOT_NAME}"]`);
267
+ if ($placeholderEl && ((_b = $placeholderEl.textContent) === null || _b === void 0 ? void 0 : _b.trim())) {
268
+ this.$placeholder = $placeholderEl;
284
269
  }
270
+ this._updateOptions();
271
+ this._addPlaceholderOptionIfNeeded();
285
272
  this._setupEvents();
286
273
  }
287
274
  firstUpdated(changedProperties) {
@@ -511,9 +498,7 @@ let HSelect = class HSelect extends PhoenixLightLitElement {
511
498
  <h-select-close-btn class="${SELECT_CSS_CLASSES.selectCloseMobileButton}" @close=${this._closeSelect}></h-select-close-btn>
512
499
 
513
500
  <div class=${SELECT_CSS_CLASSES.selectLabel}>
514
- ${this.isDevSelectPlaceholderFlagEnabled
515
- ? (_b = this.$searchLabel) === null || _b === void 0 ? void 0 : _b.cloneNode(true)
516
- : html `${this._getClonedPlaceholderElement()}`}
501
+ ${(_b = this.$searchLabel) === null || _b === void 0 ? void 0 : _b.cloneNode(true)}
517
502
  </div>
518
503
 
519
504
  ${isSearchEnabled
@@ -629,10 +614,6 @@ __decorate([
629
614
  property({ type: String, attribute: 'assistive-title-id' }),
630
615
  __metadata("design:type", String)
631
616
  ], HSelect.prototype, "assistiveTitleId", void 0);
632
- __decorate([
633
- property({ type: Boolean, attribute: 'is-dev-select-placeholder-flag-enabled' }),
634
- __metadata("design:type", Boolean)
635
- ], HSelect.prototype, "isDevSelectPlaceholderFlagEnabled", void 0);
636
617
  __decorate([
637
618
  property({ type: Boolean, attribute: 'is-reactive-selection-flag-enabled' }),
638
619
  __metadata("design:type", Boolean)
@@ -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,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,23 +1,31 @@
1
1
  import { TemplateResult } from 'lit-html';
2
2
  import { PhoenixLightLitElement } from "../../core/phoenix_light_lit_element/phoenix_light_lit_element";
3
+ import { PropertyValues } from '@lit/reactive-element';
3
4
  export declare class HModal extends PhoenixLightLitElement {
4
5
  opened: boolean;
5
6
  class: string;
6
7
  transition: string;
7
8
  modalLabel: string;
8
9
  noAutofocus: boolean;
10
+ _firstFocusableElement: HTMLElement | undefined;
11
+ _focusableElements: HTMLElement[] | null;
12
+ _lastFocusableElement: HTMLElement | undefined;
9
13
  private _focusedToggler;
10
14
  private _contentRef;
15
+ private _focusSentinelStart;
16
+ private _focusSentinelEnd;
11
17
  private _propsChangeStrategies;
12
18
  private static openModals;
13
19
  private _backdropController;
14
- private _focusTrapController;
15
20
  private static _appendModalsPortal;
16
21
  static isSomeModalOpen(): boolean;
17
22
  constructor();
18
23
  connectedCallback(): void;
19
24
  disconnectedCallback(): void;
25
+ firstUpdated(props: PropertyValues): void;
20
26
  updated(changedProps: Map<string, any>): void;
27
+ private _setFocusToFirstFocusableElementInModalOrCloseBtn;
28
+ private _keepFocusWithinModal;
21
29
  private _handleCloseFromCloseComponent;
22
30
  private _bindCloseOnEsc;
23
31
  open(): Promise<void>;
@@ -1,14 +1,15 @@
1
1
  import { __decorate, __metadata } from '../../../../../external/tslib/tslib.es6.js';
2
+ import { UiDomUtils } from '@dreamcommerce/utilities';
2
3
  import { PhoenixLightLitElement } from '../../core/phoenix_light_lit_element/phoenix_light_lit_element.js';
3
4
  import { phoenixCustomElement } from '../../core/decorators/phoenix_custom_element.js';
4
- import { property } from '@lit/reactive-element/decorators.js';
5
+ import { property, state } from '@lit/reactive-element/decorators.js';
6
+ import '@lit/reactive-element';
5
7
  import { html } from 'lit-html';
6
8
  import { createRef, ref } from 'lit-html/directives/ref.js';
7
9
  import { PORTAL_TARGET_COMPONENT_NAME, PORTAL_TARGET_NAME_PROP } from '../portal/portal_constants.js';
8
10
  import { BACKDROP_EVENTS } from '../backdrop/backdrop_constants.js';
9
11
  import { BackdropController } from '../backdrop/controller/backdrop_controller.js';
10
- import { FocusTrapController } from '../../controllers/focus_trap_controller/focus_trap_controller.js';
11
- import { MODAL_OPENED_PROP, MODALS_PORTAL_NAME, MODAL_EVENTS } from './modal_constants.js';
12
+ import { MODAL_OPENED_PROP, FOCUSABLE_ELEMENTS_WITHIN_MODAL, MODALS_PORTAL_NAME, MODAL_EVENTS } from './modal_constants.js';
12
13
  import { HModalClose } from './modal_close.js';
13
14
 
14
15
  var HModal_1;
@@ -20,31 +21,54 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
20
21
  this.transition = 'scale';
21
22
  this.modalLabel = '';
22
23
  this.noAutofocus = false;
24
+ this._firstFocusableElement = undefined;
25
+ this._focusableElements = null;
26
+ this._lastFocusableElement = undefined;
23
27
  this._focusedToggler = null;
24
28
  this._contentRef = createRef();
29
+ this._focusSentinelStart = createRef();
30
+ this._focusSentinelEnd = createRef();
25
31
  this._propsChangeStrategies = {
26
32
  [MODAL_OPENED_PROP]: {
27
33
  true: () => {
34
+ const scrollY = window.scrollY;
28
35
  HModal_1.openModals = [...HModal_1.openModals, this];
29
36
  document.addEventListener('keydown', this._bindCloseOnEsc);
30
37
  document.addEventListener(BACKDROP_EVENTS.clicked, this.close);
31
38
  this._dispatchModalOpenedEvent();
32
- this._focusTrapController.activate();
39
+ if (!this.noAutofocus) {
40
+ setTimeout(() => {
41
+ var _a;
42
+ (_a = this._firstFocusableElement) === null || _a === void 0 ? void 0 : _a.focus();
43
+ window.scrollTo(0, scrollY);
44
+ }, 0);
45
+ }
33
46
  },
34
47
  false: () => {
35
48
  HModal_1.openModals = HModal_1.openModals.filter((modal) => modal !== this);
36
49
  document.removeEventListener('keydown', this._bindCloseOnEsc);
37
50
  document.removeEventListener(BACKDROP_EVENTS.clicked, this.close);
38
- this._focusTrapController.deactivate();
39
51
  }
40
52
  }
41
53
  };
42
54
  this._backdropController = new BackdropController();
43
- this._focusTrapController = new FocusTrapController(this, {
44
- mode: 'sentinel',
45
- getContainer: () => this._contentRef.value,
46
- noAutofocus: this.noAutofocus
47
- });
55
+ this._keepFocusWithinModal = (ev) => {
56
+ var _a;
57
+ const isTabPressed = ev.code === 'Tab';
58
+ if (isTabPressed && this._contentRef.value) {
59
+ if (ev.shiftKey) {
60
+ if (document.activeElement === this._firstFocusableElement) {
61
+ const focusableElements = UiDomUtils.getFocusableElements(this._contentRef.value);
62
+ (_a = focusableElements[focusableElements.length - 1]) === null || _a === void 0 ? void 0 : _a.focus();
63
+ ev.preventDefault();
64
+ }
65
+ }
66
+ else if (document.activeElement === this._lastFocusableElement) {
67
+ UiDomUtils.setFocusToFirstFocusableElementInContainer(this._contentRef.value);
68
+ ev.preventDefault();
69
+ }
70
+ }
71
+ };
48
72
  this._handleCloseFromCloseComponent = async (ev) => {
49
73
  var _a;
50
74
  ev.stopPropagation();
@@ -105,6 +129,7 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
105
129
  });
106
130
  };
107
131
  this.hidden = true;
132
+ this._focusableElements = [...this.querySelectorAll(FOCUSABLE_ELEMENTS_WITHIN_MODAL)];
108
133
  }
109
134
  static _appendModalsPortal() {
110
135
  const $modalsPortalTarget = document.querySelector(`h-portal-target[name="${MODALS_PORTAL_NAME}"]`);
@@ -120,6 +145,7 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
120
145
  connectedCallback() {
121
146
  super.connectedCallback();
122
147
  HModal_1._appendModalsPortal();
148
+ document.addEventListener('keyup', this._keepFocusWithinModal);
123
149
  document.addEventListener(MODAL_EVENTS.close, this._handleCloseFromCloseComponent);
124
150
  }
125
151
  disconnectedCallback() {
@@ -128,14 +154,29 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
128
154
  this.close();
129
155
  document.removeEventListener(MODAL_EVENTS.close, this._handleCloseFromCloseComponent);
130
156
  document.removeEventListener('keydown', this._bindCloseOnEsc);
157
+ document.removeEventListener('keyup', this._keepFocusWithinModal);
158
+ }
159
+ firstUpdated(props) {
160
+ super.firstUpdated(props);
161
+ this._firstFocusableElement = this._focusSentinelStart.value;
162
+ this._lastFocusableElement = this._focusSentinelEnd.value;
131
163
  }
132
164
  updated(changedProps) {
133
165
  if (changedProps.has(MODAL_OPENED_PROP)) {
134
166
  this._propsChangeStrategies[MODAL_OPENED_PROP][String(this[MODAL_OPENED_PROP])]();
135
167
  }
136
- if (changedProps.has('noAutofocus')) {
137
- this._focusTrapController.strategy.noAutofocus = this.noAutofocus;
138
- }
168
+ }
169
+ _setFocusToFirstFocusableElementInModalOrCloseBtn() {
170
+ if (this.noAutofocus)
171
+ return;
172
+ requestAnimationFrame(() => {
173
+ if (this._contentRef.value) {
174
+ const focusableElements = UiDomUtils.getFocusableElements(this._contentRef.value);
175
+ if (focusableElements.length > 0) {
176
+ focusableElements.length > 1 ? focusableElements[1].focus() : focusableElements[0].focus();
177
+ }
178
+ }
179
+ });
139
180
  }
140
181
  async open() {
141
182
  this._focusedToggler = document.activeElement;
@@ -152,6 +193,7 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
152
193
  setTimeout(() => {
153
194
  var _a;
154
195
  (_a = this._contentRef.value) === null || _a === void 0 ? void 0 : _a.classList.remove(`modal_show-${this.transition}-start`, `modal_show-${this.transition}-end`);
196
+ this._setFocusToFirstFocusableElementInModalOrCloseBtn();
155
197
  resolve();
156
198
  }, transitionDuration);
157
199
  });
@@ -179,11 +221,11 @@ let HModal = HModal_1 = class HModal extends PhoenixLightLitElement {
179
221
  return html `
180
222
  <h-portal ?disabled="${!this.opened}" to="${MODALS_PORTAL_NAME}" hidden>
181
223
  <div class="modal-wrapper ${this.class}">
182
- <div tabindex="0"></div>
224
+ <div tabindex="0" ${ref(this._focusSentinelStart)}></div>
183
225
  <div ${ref(this._contentRef)} class="modal" role="dialog" aria-label="${this.modalLabel}">
184
226
  <div class="modal__container">${this.getSlot('header')} ${this.getSlot('body')} ${this.getSlot('footer')}</div>
185
227
  </div>
186
- <div tabindex="0"></div>
228
+ <div tabindex="0" ${ref(this._focusSentinelEnd)}></div>
187
229
  </div>
188
230
  </h-portal>
189
231
  `;
@@ -210,6 +252,18 @@ __decorate([
210
252
  property({ type: Boolean, attribute: 'no-autofocus' }),
211
253
  __metadata("design:type", Object)
212
254
  ], HModal.prototype, "noAutofocus", void 0);
255
+ __decorate([
256
+ state(),
257
+ __metadata("design:type", Object)
258
+ ], HModal.prototype, "_firstFocusableElement", void 0);
259
+ __decorate([
260
+ state(),
261
+ __metadata("design:type", Object)
262
+ ], HModal.prototype, "_focusableElements", void 0);
263
+ __decorate([
264
+ state(),
265
+ __metadata("design:type", Object)
266
+ ], HModal.prototype, "_lastFocusableElement", void 0);
213
267
  HModal = HModal_1 = __decorate([
214
268
  phoenixCustomElement('h-modal'),
215
269
  __metadata("design:paramtypes", [])
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,4CAAgD;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,4CAAgD;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -5,7 +5,8 @@ const MODAL_EVENTS = {
5
5
  opened: 'opened',
6
6
  closed: 'closed'
7
7
  };
8
- const MODAL_OPENED_PROP = 'opened';
8
+ const MODAL_OPENED_PROP = 'opened';
9
+ const FOCUSABLE_ELEMENTS_WITHIN_MODAL = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
9
10
 
10
- export { MODALS_PORTAL_NAME, MODAL_EVENTS, MODAL_OPENED_PROP };
11
+ export { FOCUSABLE_ELEMENTS_WITHIN_MODAL, MODALS_PORTAL_NAME, MODAL_EVENTS, MODAL_OPENED_PROP };
11
12
  //# sourceMappingURL=modal_constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -1,22 +1,30 @@
1
1
  import { TemplateResult } from 'lit-html';
2
2
  import { PhoenixLightLitElement } from "../../core/phoenix_light_lit_element/phoenix_light_lit_element";
3
+ import { PropertyValues } from '@lit/reactive-element';
3
4
  export declare class HSheet extends PhoenixLightLitElement {
4
5
  opened: boolean;
5
6
  class: string;
6
7
  transition: string;
7
8
  sheetLabel: string;
9
+ _firstFocusableElement: HTMLElement | undefined;
10
+ _focusableElements: HTMLElement[] | null;
11
+ _lastFocusableElement: HTMLElement | undefined;
8
12
  private _focusedToggler;
9
13
  private _contentRef;
14
+ private _focusSentinelStart;
15
+ private _focusSentinelEnd;
10
16
  private _propsChangeStrategies;
11
17
  private static openSheets;
12
18
  private _backdropController;
13
- private _focusTrapController;
14
19
  private static _appendSheetPortal;
15
20
  static isSomeSheetOpen(): boolean;
16
21
  constructor();
17
22
  connectedCallback(): void;
18
23
  disconnectedCallback(): void;
24
+ firstUpdated(props: PropertyValues): void;
19
25
  updated(changedProps: Map<string, any>): void;
26
+ private _setFocusToFirstFocusableElementInSheetOrCloseBtn;
27
+ private _keepFocusWithinSheet;
20
28
  private _handleCloseFromCloseComponent;
21
29
  private _bindCloseOnEsc;
22
30
  open(): Promise<void>;
@@ -1,14 +1,15 @@
1
1
  import { __decorate, __metadata } from '../../../../../external/tslib/tslib.es6.js';
2
+ import { UiDomUtils } from '@dreamcommerce/utilities';
2
3
  import { PhoenixLightLitElement } from '../../core/phoenix_light_lit_element/phoenix_light_lit_element.js';
3
4
  import { phoenixCustomElement } from '../../core/decorators/phoenix_custom_element.js';
4
- import { property } from '@lit/reactive-element/decorators.js';
5
+ import { property, state } from '@lit/reactive-element/decorators.js';
6
+ import '@lit/reactive-element';
5
7
  import { html } from 'lit-html';
6
8
  import { createRef, ref } from 'lit-html/directives/ref.js';
7
9
  import { PORTAL_TARGET_COMPONENT_NAME, PORTAL_TARGET_NAME_PROP } from '../portal/portal_constants.js';
8
10
  import { BACKDROP_EVENTS } from '../backdrop/backdrop_constants.js';
9
11
  import { BackdropController } from '../backdrop/controller/backdrop_controller.js';
10
- import { FocusTrapController } from '../../controllers/focus_trap_controller/focus_trap_controller.js';
11
- import { SHEET_OPENED_PROP, SHEETS_PORTAL_NAME, SHEET_EVENTS } from './sheet_constants.js';
12
+ import { SHEET_OPENED_PROP, FOCUSABLE_ELEMENTS_WITHIN_SHEET, SHEETS_PORTAL_NAME, SHEET_EVENTS } from './sheet_constants.js';
12
13
  import { HSheetClose } from './sheet_close.js';
13
14
 
14
15
  var HSheet_1;
@@ -19,30 +20,52 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
19
20
  this.class = '';
20
21
  this.transition = 'scale';
21
22
  this.sheetLabel = '';
23
+ this._firstFocusableElement = undefined;
24
+ this._focusableElements = null;
25
+ this._lastFocusableElement = undefined;
22
26
  this._focusedToggler = null;
23
27
  this._contentRef = createRef();
28
+ this._focusSentinelStart = createRef();
29
+ this._focusSentinelEnd = createRef();
24
30
  this._propsChangeStrategies = {
25
31
  [SHEET_OPENED_PROP]: {
26
32
  true: () => {
33
+ const scrollY = window.scrollY;
27
34
  HSheet_1.openSheets = [...HSheet_1.openSheets, this];
28
35
  document.addEventListener('keydown', this._bindCloseOnEsc);
29
36
  document.addEventListener(BACKDROP_EVENTS.clicked, this.close);
30
37
  this._dispatchSheetOpenedEvent();
31
- this._focusTrapController.activate();
38
+ setTimeout(() => {
39
+ var _a;
40
+ (_a = this._firstFocusableElement) === null || _a === void 0 ? void 0 : _a.focus();
41
+ window.scrollTo(0, scrollY);
42
+ }, 0);
32
43
  },
33
44
  false: () => {
34
45
  HSheet_1.openSheets = HSheet_1.openSheets.filter((sheet) => sheet !== this);
35
46
  document.removeEventListener('keydown', this._bindCloseOnEsc);
36
47
  document.removeEventListener(BACKDROP_EVENTS.clicked, this.close);
37
- this._focusTrapController.deactivate();
38
48
  }
39
49
  }
40
50
  };
41
51
  this._backdropController = new BackdropController();
42
- this._focusTrapController = new FocusTrapController(this, {
43
- mode: 'sentinel',
44
- getContainer: () => this._contentRef.value
45
- });
52
+ this._keepFocusWithinSheet = (ev) => {
53
+ var _a;
54
+ const isTabPressed = ev.code === 'Tab';
55
+ if (isTabPressed && this._contentRef.value) {
56
+ if (ev.shiftKey) {
57
+ if (document.activeElement === this._firstFocusableElement) {
58
+ const focusableElements = UiDomUtils.getFocusableElements(this._contentRef.value);
59
+ (_a = focusableElements[focusableElements.length - 1]) === null || _a === void 0 ? void 0 : _a.focus();
60
+ ev.preventDefault();
61
+ }
62
+ }
63
+ else if (document.activeElement === this._lastFocusableElement) {
64
+ UiDomUtils.setFocusToFirstFocusableElementInContainer(this._contentRef.value);
65
+ ev.preventDefault();
66
+ }
67
+ }
68
+ };
46
69
  this._handleCloseFromCloseComponent = async (ev) => {
47
70
  var _a;
48
71
  ev.stopPropagation();
@@ -103,6 +126,7 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
103
126
  });
104
127
  };
105
128
  this.hidden = true;
129
+ this._focusableElements = [...this.querySelectorAll(FOCUSABLE_ELEMENTS_WITHIN_SHEET)];
106
130
  }
107
131
  static _appendSheetPortal() {
108
132
  const $modalsPortalTarget = document.querySelector(`h-portal-target[name="${SHEETS_PORTAL_NAME}"]`);
@@ -118,6 +142,7 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
118
142
  connectedCallback() {
119
143
  super.connectedCallback();
120
144
  HSheet_1._appendSheetPortal();
145
+ document.addEventListener('keyup', this._keepFocusWithinSheet);
121
146
  document.addEventListener(SHEET_EVENTS.close, this._handleCloseFromCloseComponent);
122
147
  }
123
148
  disconnectedCallback() {
@@ -126,12 +151,28 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
126
151
  this.close();
127
152
  document.removeEventListener(SHEET_EVENTS.close, this._handleCloseFromCloseComponent);
128
153
  document.removeEventListener('keydown', this._bindCloseOnEsc);
154
+ document.removeEventListener('keyup', this._keepFocusWithinSheet);
155
+ }
156
+ firstUpdated(props) {
157
+ super.firstUpdated(props);
158
+ this._firstFocusableElement = this._focusSentinelStart.value;
159
+ this._lastFocusableElement = this._focusSentinelEnd.value;
129
160
  }
130
161
  updated(changedProps) {
131
162
  if (changedProps.has(SHEET_OPENED_PROP)) {
132
163
  this._propsChangeStrategies[SHEET_OPENED_PROP][String(this[SHEET_OPENED_PROP])]();
133
164
  }
134
165
  }
166
+ _setFocusToFirstFocusableElementInSheetOrCloseBtn() {
167
+ requestAnimationFrame(() => {
168
+ if (this._contentRef.value) {
169
+ const focusableElements = UiDomUtils.getFocusableElements(this._contentRef.value);
170
+ if (focusableElements.length > 0) {
171
+ focusableElements.length > 1 ? focusableElements[1].focus() : focusableElements[0].focus();
172
+ }
173
+ }
174
+ });
175
+ }
135
176
  async open() {
136
177
  this._focusedToggler = document.activeElement;
137
178
  return new Promise((resolve) => {
@@ -147,6 +188,7 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
147
188
  setTimeout(() => {
148
189
  var _a;
149
190
  (_a = this._contentRef.value) === null || _a === void 0 ? void 0 : _a.classList.remove(`sheet_show-${this.transition}-start`, `sheet_show-${this.transition}-end`);
191
+ this._setFocusToFirstFocusableElementInSheetOrCloseBtn();
150
192
  resolve();
151
193
  }, transitionDuration);
152
194
  });
@@ -172,11 +214,11 @@ let HSheet = HSheet_1 = class HSheet extends PhoenixLightLitElement {
172
214
  return html `
173
215
  <h-portal ?disabled="${!this.opened}" to="${SHEETS_PORTAL_NAME}" hidden>
174
216
  <div class="sheet-wrapper ${this.class}">
175
- <div tabindex="0"></div>
217
+ <div tabindex="0" ${ref(this._focusSentinelStart)}></div>
176
218
  <div ${ref(this._contentRef)} class="sheet" role="dialog" aria-label="${this.sheetLabel}">
177
219
  <div class="sheet__container">${this.getSlot('header')} ${this.getSlot('body')} ${this.getSlot('footer')}</div>
178
220
  </div>
179
- <div tabindex="0"></div>
221
+ <div tabindex="0" ${ref(this._focusSentinelEnd)}></div>
180
222
  </div>
181
223
  </h-portal>
182
224
  `;
@@ -199,6 +241,18 @@ __decorate([
199
241
  property({ type: String, attribute: 'sheet-label' }),
200
242
  __metadata("design:type", Object)
201
243
  ], HSheet.prototype, "sheetLabel", void 0);
244
+ __decorate([
245
+ state(),
246
+ __metadata("design:type", Object)
247
+ ], HSheet.prototype, "_firstFocusableElement", void 0);
248
+ __decorate([
249
+ state(),
250
+ __metadata("design:type", Object)
251
+ ], HSheet.prototype, "_focusableElements", void 0);
252
+ __decorate([
253
+ state(),
254
+ __metadata("design:type", Object)
255
+ ], HSheet.prototype, "_lastFocusableElement", void 0);
202
256
  HSheet = HSheet_1 = __decorate([
203
257
  phoenixCustomElement('h-sheet'),
204
258
  __metadata("design:paramtypes", [])
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA,uCAAuC,4CAAgD;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,4CAAgD;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -5,7 +5,8 @@ const SHEET_EVENTS = {
5
5
  opened: 'opened',
6
6
  closed: 'closed'
7
7
  };
8
- const SHEET_OPENED_PROP = 'opened';
8
+ const SHEET_OPENED_PROP = 'opened';
9
+ const FOCUSABLE_ELEMENTS_WITHIN_SHEET = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
9
10
 
10
- export { SHEETS_PORTAL_NAME, SHEET_EVENTS, SHEET_OPENED_PROP };
11
+ export { FOCUSABLE_ELEMENTS_WITHIN_SHEET, SHEETS_PORTAL_NAME, SHEET_EVENTS, SHEET_OPENED_PROP };
11
12
  //# sourceMappingURL=sheet_constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;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.18.23-9",
5
+ "version": "1.18.24",
6
6
  "description": "phoenix design system",
7
7
  "author": "zefirek",
8
8
  "license": "MIT",
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var tslib_es6 = require('../../../../../external/tslib/tslib.es6.js');
6
- require('lit');
7
- var focus_trap_strategy_constants = require('./strategies/focus_trap_strategy_constants.js');
8
-
9
- var _FocusTrapController_strategy;
10
- class FocusTrapController {
11
- constructor(host, { mode, ...strategyProps }) {
12
- _FocusTrapController_strategy.set(this, void 0);
13
- tslib_es6.__classPrivateFieldSet(this, _FocusTrapController_strategy, new focus_trap_strategy_constants.FOCUS_TRAP_STRATEGY_STRATEGIES[mode](strategyProps), "f");
14
- host.addController(this);
15
- }
16
- get strategy() {
17
- return tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f");
18
- }
19
- hostConnected() {
20
- tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f").attach();
21
- }
22
- hostDisconnected() {
23
- tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f").detach();
24
- }
25
- activate() {
26
- tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f").activate();
27
- }
28
- deactivate() {
29
- tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f").deactivate();
30
- }
31
- getFocusableElements(container) {
32
- return tslib_es6.__classPrivateFieldGet(this, _FocusTrapController_strategy, "f").getFocusableElements(container);
33
- }
34
- }
35
- _FocusTrapController_strategy = new WeakMap();
36
-
37
- exports.FocusTrapController = FocusTrapController;
38
- //# sourceMappingURL=focus_trap_controller.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}