@watermarkinsights/ripple 3.3.0-2 → 3.3.2-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.
Files changed (173) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{functions-653e695c.js → functions-8fb310fe.js} +442 -442
  3. package/dist/cjs/{global-45888f19.js → global-c3cf628f.js} +65 -65
  4. package/dist/cjs/{http-service-494d81de.js → http-service-9e8c4dd5.js} +49 -49
  5. package/dist/cjs/{interfaces-a3338581.js → interfaces-30a74c1f.js} +29 -29
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/priv-chart-popover.cjs.entry.js +78 -78
  8. package/dist/cjs/priv-datepicker.cjs.entry.js +661 -661
  9. package/dist/cjs/priv-navigator-button.cjs.entry.js +18 -18
  10. package/dist/cjs/priv-navigator-item.cjs.entry.js +23 -23
  11. package/dist/cjs/ripple.cjs.js +2 -2
  12. package/dist/cjs/wm-action-menu_2.cjs.entry.js +341 -340
  13. package/dist/cjs/wm-button.cjs.entry.js +218 -218
  14. package/dist/cjs/wm-chart-slice.cjs.entry.js +13 -13
  15. package/dist/cjs/wm-chart.cjs.entry.js +514 -514
  16. package/dist/cjs/wm-datepicker.cjs.entry.js +256 -256
  17. package/dist/cjs/wm-input.cjs.entry.js +125 -125
  18. package/dist/cjs/wm-modal-footer.cjs.entry.js +31 -31
  19. package/dist/cjs/wm-modal-header.cjs.entry.js +34 -34
  20. package/dist/cjs/wm-modal.cjs.entry.js +161 -161
  21. package/dist/cjs/wm-navigator.cjs.entry.js +268 -268
  22. package/dist/cjs/wm-network-uploader.cjs.entry.js +420 -420
  23. package/dist/cjs/wm-option_2.cjs.entry.js +491 -497
  24. package/dist/cjs/wm-pagination.cjs.entry.js +167 -167
  25. package/dist/cjs/wm-search.cjs.entry.js +231 -231
  26. package/dist/cjs/wm-snackbar.cjs.entry.js +170 -170
  27. package/dist/cjs/wm-tab-item_3.cjs.entry.js +300 -300
  28. package/dist/cjs/wm-tag-input.cjs.entry.js +556 -556
  29. package/dist/cjs/wm-timepicker.cjs.entry.js +383 -386
  30. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  31. package/dist/cjs/wm-uploader.cjs.entry.js +346 -346
  32. package/dist/cjs/wm-wrapper.cjs.entry.js +12 -12
  33. package/dist/collection/components/wm-action-menu/wm-action-menu.js +460 -465
  34. package/dist/collection/components/wm-button/wm-button.js +485 -485
  35. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.js +232 -232
  36. package/dist/collection/components/wm-chart/wm-chart-slice.js +64 -64
  37. package/dist/collection/components/wm-chart/wm-chart.css +1 -0
  38. package/dist/collection/components/wm-chart/wm-chart.js +761 -761
  39. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1003 -1003
  40. package/dist/collection/components/wm-datepicker/wm-datepicker.js +462 -462
  41. package/dist/collection/components/wm-input/wm-input.js +415 -415
  42. package/dist/collection/components/wm-menuitem/wm-menuitem.js +444 -444
  43. package/dist/collection/components/wm-modal/wm-modal-footer.js +141 -141
  44. package/dist/collection/components/wm-modal/wm-modal-header.js +92 -92
  45. package/dist/collection/components/wm-modal/wm-modal.js +459 -459
  46. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -97
  47. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -114
  48. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -468
  49. package/dist/collection/components/wm-option/wm-option.js +422 -422
  50. package/dist/collection/components/wm-pagination/wm-pagination.js +368 -368
  51. package/dist/collection/components/wm-search/wm-search.js +479 -479
  52. package/dist/collection/components/wm-select/wm-select.js +717 -728
  53. package/dist/collection/components/wm-snackbar/wm-snackbar.js +297 -297
  54. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +219 -219
  55. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.js +331 -331
  56. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -104
  57. package/dist/collection/components/wm-tag-input/wm-tag-input.js +787 -787
  58. package/dist/collection/components/wm-timepicker/wm-timepicker.js +589 -598
  59. package/dist/collection/components/wm-toggletip/wm-toggletip.js +241 -241
  60. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +753 -753
  61. package/dist/collection/components/wm-uploader/wm-uploader.js +748 -748
  62. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -27
  63. package/dist/collection/dev/scripts.js +20 -20
  64. package/dist/collection/global/__mocks__/functions.js +6 -6
  65. package/dist/collection/global/functions.js +445 -445
  66. package/dist/collection/global/global.js +72 -72
  67. package/dist/collection/global/interfaces.js +49 -49
  68. package/dist/collection/global/services/__mocks__/http-service.js +130 -130
  69. package/dist/collection/global/services/http-service.js +50 -50
  70. package/dist/collection/lang/lang.js +5 -5
  71. package/dist/collection/lang/piglatin.js +93 -93
  72. package/dist/esm/{functions-e528c934.js → functions-c315390d.js} +442 -442
  73. package/dist/esm/{global-1e13ed17.js → global-1c69b942.js} +65 -65
  74. package/dist/esm/{http-service-3dc3b3e7.js → http-service-5d037e16.js} +49 -49
  75. package/dist/esm/{interfaces-2b97fab2.js → interfaces-61c6305b.js} +29 -29
  76. package/dist/esm/loader.js +2 -2
  77. package/dist/esm/polyfills/core-js.js +0 -0
  78. package/dist/esm/polyfills/dom.js +0 -0
  79. package/dist/esm/polyfills/es5-html-element.js +0 -0
  80. package/dist/esm/polyfills/index.js +0 -0
  81. package/dist/esm/polyfills/system.js +0 -0
  82. package/dist/esm/priv-chart-popover.entry.js +78 -78
  83. package/dist/esm/priv-datepicker.entry.js +661 -661
  84. package/dist/esm/priv-navigator-button.entry.js +18 -18
  85. package/dist/esm/priv-navigator-item.entry.js +23 -23
  86. package/dist/esm/ripple.js +2 -2
  87. package/dist/esm/wm-action-menu_2.entry.js +341 -340
  88. package/dist/esm/wm-button.entry.js +218 -218
  89. package/dist/esm/wm-chart-slice.entry.js +13 -13
  90. package/dist/esm/wm-chart.entry.js +514 -514
  91. package/dist/esm/wm-datepicker.entry.js +256 -256
  92. package/dist/esm/wm-input.entry.js +125 -125
  93. package/dist/esm/wm-modal-footer.entry.js +31 -31
  94. package/dist/esm/wm-modal-header.entry.js +34 -34
  95. package/dist/esm/wm-modal.entry.js +161 -161
  96. package/dist/esm/wm-navigator.entry.js +268 -268
  97. package/dist/esm/wm-network-uploader.entry.js +420 -420
  98. package/dist/esm/wm-option_2.entry.js +491 -497
  99. package/dist/esm/wm-pagination.entry.js +167 -167
  100. package/dist/esm/wm-search.entry.js +231 -231
  101. package/dist/esm/wm-snackbar.entry.js +170 -170
  102. package/dist/esm/wm-tab-item_3.entry.js +300 -300
  103. package/dist/esm/wm-tag-input.entry.js +556 -556
  104. package/dist/esm/wm-timepicker.entry.js +383 -386
  105. package/dist/esm/wm-toggletip.entry.js +124 -124
  106. package/dist/esm/wm-uploader.entry.js +346 -346
  107. package/dist/esm/wm-wrapper.entry.js +12 -12
  108. package/dist/ripple/p-042d6449.entry.js +1 -0
  109. package/dist/ripple/p-053e8324.entry.js +1 -0
  110. package/dist/ripple/p-1a934627.entry.js +1 -0
  111. package/dist/ripple/{p-dc7ba72a.entry.js → p-2689c3ff.entry.js} +1 -1
  112. package/dist/ripple/{p-e9e8334e.entry.js → p-36da5d4a.entry.js} +1 -1
  113. package/dist/ripple/{p-33524565.entry.js → p-374b4fa6.entry.js} +1 -1
  114. package/dist/ripple/{p-dc9c9fda.entry.js → p-41f39509.entry.js} +1 -1
  115. package/dist/ripple/{p-d613130d.entry.js → p-589f8195.entry.js} +1 -1
  116. package/dist/ripple/{p-1e0c41a9.entry.js → p-5ffa983b.entry.js} +1 -1
  117. package/dist/ripple/{p-8923b7d0.entry.js → p-7bbd123c.entry.js} +1 -1
  118. package/dist/ripple/{p-40d42d65.js → p-7f6c08c4.js} +1 -1
  119. package/dist/ripple/{p-43f1298b.js → p-888bec42.js} +0 -0
  120. package/dist/ripple/{p-cd58a15c.entry.js → p-a50439f1.entry.js} +1 -1
  121. package/dist/ripple/{p-fd8070fb.js → p-a6d6eae7.js} +0 -0
  122. package/dist/ripple/{p-301b67a3.entry.js → p-af4b2ea9.entry.js} +1 -1
  123. package/dist/ripple/{p-65e3a656.entry.js → p-b03382ea.entry.js} +1 -1
  124. package/dist/ripple/{p-b3d5ea85.entry.js → p-b4a8c8d3.entry.js} +1 -1
  125. package/dist/ripple/{p-8cd1396e.entry.js → p-ba9d3069.entry.js} +1 -1
  126. package/dist/ripple/{p-092b01f3.entry.js → p-c5e44367.entry.js} +1 -1
  127. package/dist/ripple/{p-3003d26d.entry.js → p-d5fafa9c.entry.js} +1 -1
  128. package/dist/ripple/{p-4cc71463.entry.js → p-dea72d46.entry.js} +1 -1
  129. package/dist/ripple/{p-aa973691.entry.js → p-e574fb73.entry.js} +1 -1
  130. package/dist/ripple/{p-588b4475.js → p-e60fe2f5.js} +0 -0
  131. package/dist/ripple/{p-ec9697db.entry.js → p-ec5db255.entry.js} +1 -1
  132. package/dist/ripple/ripple.esm.js +1 -1
  133. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +48 -48
  134. package/dist/types/components/wm-button/wm-button.d.ts +44 -44
  135. package/dist/types/components/wm-chart/priv-chart-popover/priv-chart-popover.d.ts +23 -23
  136. package/dist/types/components/wm-chart/wm-chart-slice.d.ts +8 -8
  137. package/dist/types/components/wm-chart/wm-chart.d.ts +80 -80
  138. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +75 -75
  139. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +41 -41
  140. package/dist/types/components/wm-input/wm-input.d.ts +45 -45
  141. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +34 -34
  142. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +15 -15
  143. package/dist/types/components/wm-modal/wm-modal-header.d.ts +12 -12
  144. package/dist/types/components/wm-modal/wm-modal.d.ts +41 -41
  145. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -10
  146. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -13
  147. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -61
  148. package/dist/types/components/wm-option/wm-option.d.ts +32 -32
  149. package/dist/types/components/wm-pagination/wm-pagination.d.ts +32 -32
  150. package/dist/types/components/wm-search/wm-search.d.ts +86 -86
  151. package/dist/types/components/wm-select/wm-select.d.ts +66 -67
  152. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +35 -35
  153. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +38 -38
  154. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +53 -53
  155. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -20
  156. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts +91 -91
  157. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +62 -63
  158. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +27 -27
  159. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -85
  160. package/dist/types/components/wm-uploader/wm-uploader.d.ts +80 -80
  161. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  162. package/dist/types/components.d.ts +24 -24
  163. package/dist/types/global/__mocks__/functions.d.ts +6 -6
  164. package/dist/types/global/functions.d.ts +40 -40
  165. package/dist/types/global/global.d.ts +1 -1
  166. package/dist/types/global/interfaces.d.ts +34 -34
  167. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -6
  168. package/dist/types/global/services/http-service.d.ts +4 -4
  169. package/dist/types/lang/lang.d.ts +5 -5
  170. package/package.json +46 -46
  171. package/dist/ripple/p-0d138e91.entry.js +0 -1
  172. package/dist/ripple/p-6b96b3d4.entry.js +0 -1
  173. package/dist/ripple/p-df6da757.entry.js +0 -1
@@ -1,728 +1,717 @@
1
- import { h, Component, Element, Event, Listen, Prop, State, Watch } from "@stencil/core";
2
- import { forceUpdate } from "@stencil/core";
3
- import { generateId, getTextDir, shouldOpenUp, intl } from "../../global/functions";
4
- export class Select {
5
- constructor() {
6
- this.disabled = false;
7
- this.invalid = false;
8
- this.labelPosition = "top";
9
- this.requiredField = false;
10
- this.errorMessage = "";
11
- this.multiple = false;
12
- this.placeholder = intl.formatMessage({
13
- id: "select.multiPlaceholder",
14
- defaultMessage: "Make a selection",
15
- });
16
- this.allSelectedMessage = intl.formatMessage({
17
- id: "select.allSelected",
18
- defaultMessage: "All selected",
19
- });
20
- this.requiredMessage = intl.formatMessage({
21
- id: "global.requiredField",
22
- defaultMessage: "required field",
23
- });
24
- this.isTabbing = false;
25
- this.isExpanded = false;
26
- this.keysSoFar = "";
27
- this.searchIndex = 0;
28
- this.keyClear = null;
29
- this.openUp = false;
30
- // for multiselect button text
31
- this.overflowCount = 0;
32
- this.displayedItems = [];
33
- this.allSelected = false;
34
- }
35
- get childItems() {
36
- return Array.from(this.el.querySelectorAll("wm-option"));
37
- }
38
- get selectedItems() {
39
- return Array.from(this.el.querySelectorAll("wm-option")).filter((x) => x.selected);
40
- }
41
- toggleTabbingOn() {
42
- this.isTabbing = true;
43
- }
44
- toggleTabbingOff() {
45
- this.isTabbing = false;
46
- }
47
- handleOptionSelection(ev) {
48
- if (!this.multiple) {
49
- // ensure only one option is selected at a time
50
- this.childItems
51
- // remove selected on any other option
52
- .filter((option) => option != ev.target && !!option.selected)
53
- .map((option) => (option.selected = false));
54
- }
55
- this.focusItem(ev.target);
56
- this.selectItem(ev.target);
57
- if (!this.multiple) {
58
- this.close();
59
- }
60
- }
61
- handeChildEnter() {
62
- // only occurs for multiselects. handle the click, then close
63
- this.close();
64
- }
65
- handleChildUp(ev) {
66
- this.moveUp(ev.target);
67
- }
68
- handleChildDown(ev) {
69
- this.moveDown(ev.target);
70
- }
71
- moveToFirstItem() {
72
- this.focusItem(this.childItems[0]);
73
- }
74
- moveToLastItem() {
75
- this.focusItem(this.childItems[this.childItems.length - 1]);
76
- }
77
- handleTabKey() {
78
- this.close(false);
79
- }
80
- closePopupOnEscape() {
81
- this.close();
82
- }
83
- handleOptionBlur(ev) {
84
- const toElOrChild = ev.detail.relatedTarget === this.el || this.el.contains(ev.detail.relatedTarget);
85
- // if the Option is blurred to something other than the component emit a blur event with the appropriate relatedTarget
86
- // keeps our component's blur events accurate, and closes when focusing browser address bar
87
- if (!toElOrChild) {
88
- const event = new CustomEvent("blur");
89
- // @ts-ignore
90
- event.relatedTarget = ev.detail.relatedTarget;
91
- this.el.dispatchEvent(event);
92
- }
93
- }
94
- handleClick(ev) {
95
- const isElOrChild = ev.target === this.el || this.el.contains(ev.target);
96
- if (!isElOrChild && this.isExpanded) {
97
- this.close();
98
- }
99
- }
100
- handleBlur(ev) {
101
- const toElOrChild = ev.relatedTarget === this.el || this.el.contains(ev.relatedTarget);
102
- if (!toElOrChild) {
103
- this.close(false);
104
- }
105
- }
106
- handleButtonBlur(ev) {
107
- const toElOrChild = ev.relatedTarget === this.el || this.el.contains(ev.relatedTarget);
108
- if (toElOrChild) {
109
- // do not emit a blur event when opening the dropdown and focusing the Options
110
- ev.stopPropagation();
111
- }
112
- }
113
- handleKey(ev) {
114
- switch (ev.keyCode) {
115
- // Arrow down
116
- case 40:
117
- if (this.isExpanded === false) {
118
- ev.preventDefault();
119
- this.open("next");
120
- }
121
- break;
122
- // Arrow up
123
- case 38:
124
- if (this.isExpanded === false) {
125
- ev.preventDefault();
126
- this.open("previous");
127
- }
128
- break;
129
- }
130
- }
131
- componentWillLoad() {
132
- if (!this.label) {
133
- console.error("For accessibility purposes, this component requires a label (even if `label-position` is set to `none`).");
134
- }
135
- this.el.focus = function () {
136
- if (!this.disabled) {
137
- this.shadowRoot.querySelector("button").focus();
138
- }
139
- };
140
- this.uid = this.el.id ? this.el.id : generateId();
141
- if (document.body.classList.contains("wmcl-user-is-tabbing")) {
142
- this.toggleTabbingOn();
143
- }
144
- }
145
- componentDidLoad() {
146
- this.wmSelectDidLoad.emit();
147
- if (!this.childItems.length) {
148
- throw new Error("wm-select should have wm-option elements as children.");
149
- }
150
- if (this.multiple && this.childItems.filter((x) => x.subinfo).length > 0) {
151
- throw new Error("wm-select with the multiple prop cannot have subinfo options");
152
- }
153
- if (this.multiple && !this.placeholder) {
154
- throw new Error("wm-select with the multiple prop needs to also use the placeholder prop.");
155
- }
156
- // set initial selections / button text
157
- if (this.selectedItems.length > 0) {
158
- this.selectedItems.forEach((x) => this.displayedItems.push(x));
159
- this.setButtonText();
160
- // single Select only, pre-select if no default option from dev
161
- }
162
- else if (!this.multiple) {
163
- this.selectItem(this.childItems[0]);
164
- }
165
- this.optionsEl.classList.add("hidden");
166
- forceUpdate(this.el);
167
- // Dev can overwrite the max-height rule set in the Sass file
168
- if (this.maxHeight) {
169
- this.optionsEl.style.maxHeight = this.maxHeight;
170
- }
171
- }
172
- moveUp(el) {
173
- const prevEl = el.previousElementSibling;
174
- if (prevEl) {
175
- // scroll option to top of dropdown if partially obscured / out of view
176
- if (prevEl.getBoundingClientRect().top < this.optionsEl.getBoundingClientRect().top) {
177
- this.optionsEl.scrollTop =
178
- prevEl.getBoundingClientRect().top - this.optionsEl.getBoundingClientRect().top + this.optionsEl.scrollTop;
179
- }
180
- this.focusItem(prevEl);
181
- }
182
- else {
183
- this.focusItem(this.childItems[this.childItems.length - 1]);
184
- }
185
- }
186
- moveDown(el) {
187
- const nextEl = el.nextElementSibling;
188
- if (nextEl && nextEl.tagName !== "INPUT") {
189
- // scroll option to bottom of dropdown if partially obscured / out of view
190
- if (nextEl.getBoundingClientRect().bottom > this.optionsEl.getBoundingClientRect().bottom) {
191
- this.optionsEl.scrollTop =
192
- nextEl.getBoundingClientRect().bottom -
193
- this.optionsEl.getBoundingClientRect().top +
194
- this.optionsEl.scrollTop -
195
- this.optionsEl.offsetHeight;
196
- }
197
- this.focusItem(nextEl);
198
- }
199
- else {
200
- this.focusItem(this.childItems[0]);
201
- }
202
- }
203
- open(itemToSelect) {
204
- if (!this.disabled) {
205
- const elHeight = this.el.clientHeight;
206
- const buttonHeight = this.buttonEl.clientHeight;
207
- this.openUp = shouldOpenUp(this.el, this.optionsEl,
208
- // when opening up, dropdown covers both label and button
209
- elHeight,
210
- // when opening down, dropdown covers only the button
211
- buttonHeight);
212
- this.isExpanded = true;
213
- this.optionsEl.classList.remove("hidden");
214
- window.requestAnimationFrame(() => {
215
- if (this.selectedItems.length > 0) {
216
- if (itemToSelect === "next") {
217
- this.moveDown(this.selectedItems[this.selectedItems.length - 1]);
218
- }
219
- else if (itemToSelect === "previous") {
220
- this.moveUp(this.selectedItems[0]);
221
- }
222
- else {
223
- this.focusItem(this.selectedItems[0]);
224
- }
225
- }
226
- else {
227
- this.focusItem(this.childItems[0]);
228
- }
229
- });
230
- }
231
- }
232
- close(returnFocus = true) {
233
- this.isExpanded = false;
234
- this.childItems.map((i) => (i.focused = false));
235
- window.setTimeout(() => {
236
- this.optionsEl.classList.add("hidden");
237
- // Returns focus to button after popup closes (no need if user is tabbing)
238
- // Delay is necessary for screenreader to get new expanded state before focus
239
- // window.requestAnimationFrame is probably enough, but since we are already using setTimeout it may as well be here
240
- // also UX wise, it makes sense for the button to only be focused after the animation is complete
241
- if (returnFocus) {
242
- this.el.focus();
243
- }
244
- }, 150);
245
- }
246
- focusItem(item) {
247
- this.childItems.forEach((i) => (i.focused = i === item));
248
- }
249
- selectItem(item) {
250
- if (this.multiple) {
251
- item.selected = !item.selected;
252
- }
253
- else {
254
- this.childItems.forEach((i) => (i.selected = i === item));
255
- }
256
- this.setButtonText();
257
- }
258
- findAndFocusItem(ev) {
259
- const character = ev.detail.toUpperCase();
260
- if (!this.keysSoFar) {
261
- for (var i = 0; i < this.childItems.length; i++) {
262
- if (this.childItems[i].focused) {
263
- this.searchIndex = i;
264
- }
265
- }
266
- }
267
- this.keysSoFar += character;
268
- this.clearKeysSoFarAfterDelay();
269
- var nextMatch = this.findMatchInRange(this.childItems, this.searchIndex + 1, this.childItems.length);
270
- if (!nextMatch) {
271
- nextMatch = this.findMatchInRange(this.childItems, 0, this.searchIndex);
272
- }
273
- if (nextMatch) {
274
- this.focusItem(nextMatch);
275
- }
276
- }
277
- clearKeysSoFarAfterDelay() {
278
- if (this.keyClear) {
279
- window.clearTimeout(this.keyClear);
280
- this.keyClear = null;
281
- }
282
- this.keyClear = window.setTimeout(function () {
283
- this.keysSoFar = "";
284
- this.keyClear = null;
285
- }.bind(this), 500);
286
- }
287
- findMatchInRange(list, startIndex, endIndex) {
288
- // Find the first item starting with the keysSoFar substring, searching in
289
- // the specified range of items
290
- for (var n = startIndex; n < endIndex; n++) {
291
- var label = list[n].textContent;
292
- if (label && label.toUpperCase().indexOf(this.keysSoFar) === 0) {
293
- return list[n];
294
- }
295
- }
296
- return null;
297
- }
298
- exposeErrors() {
299
- // When the error changes, a new id is set for the error container and the button's aria-describedby attribute is updated accordingly. This is to make sure the screen reader announces teh updated errors in Firefox. See this longstanding bug: https://bugzilla.mozilla.org/show_bug.cgi?id=493683
300
- const newId = generateId();
301
- this.errorContainer.id = `wm-errors-${newId}`;
302
- this.buttonEl.setAttribute("aria-describedby", `wm-errors-${newId}`);
303
- }
304
- renderErrorContainer() {
305
- return (h("div", { id: "wm-errors", class: this.errorMessage ? "error-message" : "", ref: (el) => (this.errorContainer = el), "aria-live": "assertive", "aria-atomic": "true" }, this.errorMessage));
306
- }
307
- handleComponentBlur() {
308
- if (!this.isExpanded) {
309
- this.wmSelectBlurred.emit();
310
- this.wmComponentBlurred.emit(); // deprecated
311
- }
312
- }
313
- setButtonText() {
314
- this.displayedItems = this.childItems.filter((x) => x.selected);
315
- this.allSelected = this.displayedItems.length === this.childItems.length;
316
- // handle overflow + counter for multiselect
317
- if (this.multiple) {
318
- // this is a fixed measurement accounting for the max width of a 3 character overflow counter
319
- const overflowCounterWidth = 38;
320
- const computedStyle = window.getComputedStyle(this.buttonEl);
321
- // there seems to be no quick way to get an elements width without padding, except for subtracting padding manually
322
- const paddingLeft = parseInt(computedStyle.getPropertyValue("padding-left").slice(0, -2));
323
- const paddingRight = parseInt(computedStyle.getPropertyValue("padding-right").slice(0, -2));
324
- const availableSpace = this.buttonEl.clientWidth - paddingLeft - paddingRight - overflowCounterWidth;
325
- let optionsWidths = this.displayedItems.map((x) => x.shadowRoot.querySelector(".option-wrapper").clientWidth);
326
- let optionsTotalWidth = optionsWidths.reduce((acc, x) => acc + x, 0);
327
- this.overflowCount = 0;
328
- while (optionsTotalWidth > availableSpace && this.displayedItems.length > 1) {
329
- this.overflowCount++;
330
- optionsTotalWidth -= optionsWidths[optionsWidths.length - 1];
331
- optionsWidths.pop();
332
- this.displayedItems.pop();
333
- }
334
- }
335
- }
336
- renderButtonText() {
337
- if (this.multiple && this.displayedItems.length < 1) {
338
- return h("span", null, this.placeholder);
339
- }
340
- else if (this.multiple && this.allSelected && this.overflowCount > 0) {
341
- return this.allSelectedMessage;
342
- }
343
- else {
344
- return this.displayedItems.map((x, idx) => (h("span", null,
345
- idx > 0 ? ", " : "",
346
- x.textContent)));
347
- }
348
- }
349
- renderSubinfo() {
350
- // multiselects cannot have subinfo for options
351
- if (!this.multiple && this.selectedItems.length > 0 && this.selectedItems[0].subinfo) {
352
- return h("span", { class: "subinfo" }, this.selectedItems[0].subinfo);
353
- }
354
- }
355
- renderOverflowCount() {
356
- if (this.overflowCount > 0 && !this.allSelected) {
357
- return (h("span", null,
358
- h("span", { class: "overflow-counter" },
359
- "+",
360
- this.overflowCount)));
361
- }
362
- }
363
- render() {
364
- const buttonProps = {
365
- id: `selectbtn-${this.uid}`,
366
- ["disabled"]: this.disabled,
367
- ["aria-controls"]: `list-${this.uid}`,
368
- ["aria-labelledby"]: `label-${this.uid} selectbtn-${this.uid}`,
369
- ["aria-describedby"]: "wm-errors",
370
- ["aria-expanded"]: this.isExpanded ? "true" : "false",
371
- onClick: () => (this.isExpanded ? this.close() : this.open()),
372
- onBlur: () => this.handleComponentBlur(),
373
- };
374
- return (h("div", { class: `wrapper ${getTextDir()} label-${this.labelPosition} ${this.invalid || this.errorMessage ? "invalid" : ""}` },
375
- h("div", { class: "label-wrapper" },
376
- h("label", { class: "label", id: `label-${this.uid}`, htmlFor: `selectbtn-${this.uid}` },
377
- this.label,
378
- // we can't use aria-required or required attributes because it's invalid on the elements we're using (button controlling a listbox)
379
- this.requiredField ? (h("span", { class: "required" },
380
- h("span", { class: "sr-only" }, this.requiredMessage),
381
- h("span", { "aria-hidden": "true" }, "*"))) : (""))),
382
- h("div", { class: "dropdown" },
383
- h("button", Object.assign({}, buttonProps, { class: `displayedoption ${this.isTabbing ? "user-is-tabbing" : ""}`, ref: (el) => (this.buttonEl = el), onBlur: (ev) => this.handleButtonBlur(ev) }),
384
- h("span", { class: this.selectedItems.length > 0 && this.selectedItems.filter((x) => x.subinfo).length > 0
385
- ? "overflowcontrol hassubinfo"
386
- : "overflowcontrol" },
387
- h("span", { class: "button-text" }, this.renderButtonText()),
388
- this.renderSubinfo()),
389
- this.renderOverflowCount()),
390
- h("div", { class: `options ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, id: `list-${this.uid}`, tabindex: -1, role: "listbox", "aria-multiselectable": this.multiple ? "true" : null, "aria-labelledby": `label-${this.uid}`, ref: (el) => (this.optionsEl = el) },
391
- h("slot", null)),
392
- this.renderErrorContainer())));
393
- }
394
- static get is() { return "wm-select"; }
395
- static get encapsulation() { return "shadow"; }
396
- static get originalStyleUrls() { return {
397
- "$": ["wm-select.scss"]
398
- }; }
399
- static get styleUrls() { return {
400
- "$": ["wm-select.css"]
401
- }; }
402
- static get properties() { return {
403
- "disabled": {
404
- "type": "boolean",
405
- "mutable": false,
406
- "complexType": {
407
- "original": "boolean",
408
- "resolved": "boolean",
409
- "references": {}
410
- },
411
- "required": false,
412
- "optional": false,
413
- "docs": {
414
- "tags": [],
415
- "text": ""
416
- },
417
- "attribute": "disabled",
418
- "reflect": true,
419
- "defaultValue": "false"
420
- },
421
- "invalid": {
422
- "type": "boolean",
423
- "mutable": true,
424
- "complexType": {
425
- "original": "boolean",
426
- "resolved": "boolean",
427
- "references": {}
428
- },
429
- "required": false,
430
- "optional": false,
431
- "docs": {
432
- "tags": [],
433
- "text": ""
434
- },
435
- "attribute": "invalid",
436
- "reflect": false,
437
- "defaultValue": "false"
438
- },
439
- "maxHeight": {
440
- "type": "string",
441
- "mutable": false,
442
- "complexType": {
443
- "original": "string",
444
- "resolved": "string | undefined",
445
- "references": {}
446
- },
447
- "required": false,
448
- "optional": true,
449
- "docs": {
450
- "tags": [],
451
- "text": ""
452
- },
453
- "attribute": "max-height",
454
- "reflect": false
455
- },
456
- "label": {
457
- "type": "string",
458
- "mutable": true,
459
- "complexType": {
460
- "original": "string",
461
- "resolved": "string | undefined",
462
- "references": {}
463
- },
464
- "required": false,
465
- "optional": true,
466
- "docs": {
467
- "tags": [],
468
- "text": ""
469
- },
470
- "attribute": "label",
471
- "reflect": false
472
- },
473
- "labelPosition": {
474
- "type": "string",
475
- "mutable": false,
476
- "complexType": {
477
- "original": "\"top\" | \"left\" | \"none\"",
478
- "resolved": "\"left\" | \"none\" | \"top\"",
479
- "references": {}
480
- },
481
- "required": false,
482
- "optional": false,
483
- "docs": {
484
- "tags": [],
485
- "text": ""
486
- },
487
- "attribute": "label-position",
488
- "reflect": false,
489
- "defaultValue": "\"top\""
490
- },
491
- "requiredField": {
492
- "type": "boolean",
493
- "mutable": false,
494
- "complexType": {
495
- "original": "boolean",
496
- "resolved": "boolean",
497
- "references": {}
498
- },
499
- "required": false,
500
- "optional": false,
501
- "docs": {
502
- "tags": [],
503
- "text": ""
504
- },
505
- "attribute": "required-field",
506
- "reflect": false,
507
- "defaultValue": "false"
508
- },
509
- "errorMessage": {
510
- "type": "string",
511
- "mutable": true,
512
- "complexType": {
513
- "original": "string",
514
- "resolved": "string",
515
- "references": {}
516
- },
517
- "required": false,
518
- "optional": false,
519
- "docs": {
520
- "tags": [],
521
- "text": ""
522
- },
523
- "attribute": "error-message",
524
- "reflect": false,
525
- "defaultValue": "\"\""
526
- },
527
- "multiple": {
528
- "type": "boolean",
529
- "mutable": false,
530
- "complexType": {
531
- "original": "boolean",
532
- "resolved": "boolean",
533
- "references": {}
534
- },
535
- "required": false,
536
- "optional": false,
537
- "docs": {
538
- "tags": [],
539
- "text": ""
540
- },
541
- "attribute": "multiple",
542
- "reflect": false,
543
- "defaultValue": "false"
544
- },
545
- "placeholder": {
546
- "type": "string",
547
- "mutable": false,
548
- "complexType": {
549
- "original": "string",
550
- "resolved": "string",
551
- "references": {}
552
- },
553
- "required": false,
554
- "optional": false,
555
- "docs": {
556
- "tags": [],
557
- "text": ""
558
- },
559
- "attribute": "placeholder",
560
- "reflect": false,
561
- "defaultValue": "intl.formatMessage({\r\n id: \"select.multiPlaceholder\",\r\n defaultMessage: \"Make a selection\",\r\n })"
562
- },
563
- "allSelectedMessage": {
564
- "type": "string",
565
- "mutable": false,
566
- "complexType": {
567
- "original": "string",
568
- "resolved": "string",
569
- "references": {}
570
- },
571
- "required": false,
572
- "optional": false,
573
- "docs": {
574
- "tags": [],
575
- "text": ""
576
- },
577
- "attribute": "all-selected-message",
578
- "reflect": false,
579
- "defaultValue": "intl.formatMessage({\r\n id: \"select.allSelected\",\r\n defaultMessage: \"All selected\",\r\n })"
580
- }
581
- }; }
582
- static get states() { return {
583
- "isTabbing": {},
584
- "isExpanded": {}
585
- }; }
586
- static get events() { return [{
587
- "method": "wmSelectDidLoad",
588
- "name": "wmSelectDidLoad",
589
- "bubbles": true,
590
- "cancelable": true,
591
- "composed": true,
592
- "docs": {
593
- "tags": [],
594
- "text": ""
595
- },
596
- "complexType": {
597
- "original": "void",
598
- "resolved": "void",
599
- "references": {}
600
- }
601
- }, {
602
- "method": "wmSelectBlurred",
603
- "name": "wmSelectBlurred",
604
- "bubbles": true,
605
- "cancelable": true,
606
- "composed": true,
607
- "docs": {
608
- "tags": [],
609
- "text": ""
610
- },
611
- "complexType": {
612
- "original": "void",
613
- "resolved": "void",
614
- "references": {}
615
- }
616
- }, {
617
- "method": "wmComponentBlurred",
618
- "name": "wmComponentBlurred",
619
- "bubbles": true,
620
- "cancelable": true,
621
- "composed": true,
622
- "docs": {
623
- "tags": [],
624
- "text": ""
625
- },
626
- "complexType": {
627
- "original": "void",
628
- "resolved": "void",
629
- "references": {}
630
- }
631
- }]; }
632
- static get elementRef() { return "el"; }
633
- static get watchers() { return [{
634
- "propName": "errorMessage",
635
- "methodName": "exposeErrors"
636
- }]; }
637
- static get listeners() { return [{
638
- "name": "wmUserIsTabbing",
639
- "method": "toggleTabbingOn",
640
- "target": "window",
641
- "capture": false,
642
- "passive": false
643
- }, {
644
- "name": "wmUserIsNotTabbing",
645
- "method": "toggleTabbingOff",
646
- "target": "window",
647
- "capture": false,
648
- "passive": false
649
- }, {
650
- "name": "wmOptionSelected",
651
- "method": "handleOptionSelection",
652
- "target": undefined,
653
- "capture": false,
654
- "passive": false
655
- }, {
656
- "name": "wmEnterKeyPressed",
657
- "method": "handeChildEnter",
658
- "target": undefined,
659
- "capture": false,
660
- "passive": false
661
- }, {
662
- "name": "wmKeyUpPressed",
663
- "method": "handleChildUp",
664
- "target": undefined,
665
- "capture": false,
666
- "passive": false
667
- }, {
668
- "name": "wmKeyDownPressed",
669
- "method": "handleChildDown",
670
- "target": undefined,
671
- "capture": false,
672
- "passive": false
673
- }, {
674
- "name": "wmHomeKeyPressed",
675
- "method": "moveToFirstItem",
676
- "target": undefined,
677
- "capture": false,
678
- "passive": false
679
- }, {
680
- "name": "wmEndKeyPressed",
681
- "method": "moveToLastItem",
682
- "target": undefined,
683
- "capture": false,
684
- "passive": false
685
- }, {
686
- "name": "wmTabKeyPressed",
687
- "method": "handleTabKey",
688
- "target": undefined,
689
- "capture": false,
690
- "passive": false
691
- }, {
692
- "name": "wmEscKeyPressed",
693
- "method": "closePopupOnEscape",
694
- "target": undefined,
695
- "capture": false,
696
- "passive": false
697
- }, {
698
- "name": "wmOptionBlurred",
699
- "method": "handleOptionBlur",
700
- "target": undefined,
701
- "capture": false,
702
- "passive": false
703
- }, {
704
- "name": "click",
705
- "method": "handleClick",
706
- "target": "document",
707
- "capture": true,
708
- "passive": false
709
- }, {
710
- "name": "blur",
711
- "method": "handleBlur",
712
- "target": undefined,
713
- "capture": false,
714
- "passive": false
715
- }, {
716
- "name": "keydown",
717
- "method": "handleKey",
718
- "target": undefined,
719
- "capture": false,
720
- "passive": false
721
- }, {
722
- "name": "wmLetterPressed",
723
- "method": "findAndFocusItem",
724
- "target": undefined,
725
- "capture": false,
726
- "passive": false
727
- }]; }
728
- }
1
+ import { h, Component, Element, Event, Listen, Prop, State, Watch, Host } from "@stencil/core";
2
+ import { forceUpdate } from "@stencil/core";
3
+ import { generateId, getTextDir, shouldOpenUp, intl } from "../../global/functions";
4
+ export class Select {
5
+ constructor() {
6
+ this.disabled = false;
7
+ this.invalid = false;
8
+ this.labelPosition = "top";
9
+ this.requiredField = false;
10
+ this.errorMessage = "";
11
+ this.multiple = false;
12
+ this.placeholder = intl.formatMessage({
13
+ id: "select.multiPlaceholder",
14
+ defaultMessage: "Make a selection",
15
+ });
16
+ this.allSelectedMessage = intl.formatMessage({
17
+ id: "select.allSelected",
18
+ defaultMessage: "All selected",
19
+ });
20
+ this.requiredMessage = intl.formatMessage({
21
+ id: "global.requiredField",
22
+ defaultMessage: "required field",
23
+ });
24
+ this.isTabbing = false;
25
+ this.isExpanded = false;
26
+ this.keysSoFar = "";
27
+ this.searchIndex = 0;
28
+ this.keyClear = null;
29
+ this.openUp = false;
30
+ // for multiselect button text
31
+ this.overflowCount = 0;
32
+ this.displayedItems = [];
33
+ this.allSelected = false;
34
+ }
35
+ get childItems() {
36
+ return Array.from(this.el.querySelectorAll("wm-option"));
37
+ }
38
+ get selectedItems() {
39
+ return Array.from(this.el.querySelectorAll("wm-option")).filter((x) => x.selected);
40
+ }
41
+ toggleTabbingOn() {
42
+ this.isTabbing = true;
43
+ }
44
+ toggleTabbingOff() {
45
+ this.isTabbing = false;
46
+ }
47
+ handleOptionSelection(ev) {
48
+ if (!this.multiple) {
49
+ // ensure only one option is selected at a time
50
+ this.childItems
51
+ // remove selected on any other option
52
+ .filter((option) => option != ev.target && !!option.selected)
53
+ .map((option) => (option.selected = false));
54
+ }
55
+ this.focusItem(ev.target);
56
+ this.selectItem(ev.target);
57
+ if (!this.multiple) {
58
+ this.close();
59
+ }
60
+ }
61
+ handeChildEnter() {
62
+ // only occurs for multiselects. handle the click, then close
63
+ this.close();
64
+ }
65
+ handleChildUp(ev) {
66
+ this.moveUp(ev.target);
67
+ }
68
+ handleChildDown(ev) {
69
+ this.moveDown(ev.target);
70
+ }
71
+ moveToFirstItem() {
72
+ this.focusItem(this.childItems[0]);
73
+ }
74
+ moveToLastItem() {
75
+ this.focusItem(this.childItems[this.childItems.length - 1]);
76
+ }
77
+ handleTabKey() {
78
+ this.close(false);
79
+ }
80
+ closePopupOnEscape() {
81
+ this.close();
82
+ }
83
+ handleOptionBlur(ev) {
84
+ const toElOrChild = ev.detail.relatedTarget === this.el || this.el.contains(ev.detail.relatedTarget);
85
+ // if the Option is blurred to something other than the component emit a blur event with the appropriate relatedTarget
86
+ // keeps our component's blur events accurate, and closes when focusing browser address bar
87
+ if (!toElOrChild) {
88
+ const event = new CustomEvent("blur");
89
+ // @ts-ignore
90
+ event.relatedTarget = ev.detail.relatedTarget;
91
+ this.el.dispatchEvent(event);
92
+ }
93
+ }
94
+ handleClick(ev) {
95
+ const isElOrChild = ev.target === this.el || this.el.contains(ev.target);
96
+ if (!isElOrChild && this.isExpanded) {
97
+ this.close();
98
+ }
99
+ }
100
+ handleButtonBlur(ev) {
101
+ const toElOrChild = ev.relatedTarget === this.el || this.el.contains(ev.relatedTarget);
102
+ if (toElOrChild) {
103
+ // do not emit a blur event when opening the dropdown and focusing the Options
104
+ ev.stopPropagation();
105
+ }
106
+ }
107
+ handleKey(ev) {
108
+ switch (ev.keyCode) {
109
+ // Arrow down
110
+ case 40:
111
+ if (this.isExpanded === false) {
112
+ ev.preventDefault();
113
+ this.open("next");
114
+ }
115
+ break;
116
+ // Arrow up
117
+ case 38:
118
+ if (this.isExpanded === false) {
119
+ ev.preventDefault();
120
+ this.open("previous");
121
+ }
122
+ break;
123
+ }
124
+ }
125
+ componentWillLoad() {
126
+ if (!this.label) {
127
+ console.error("For accessibility purposes, this component requires a label (even if `label-position` is set to `none`).");
128
+ }
129
+ this.el.focus = function () {
130
+ if (!this.disabled) {
131
+ this.shadowRoot.querySelector("button").focus();
132
+ }
133
+ };
134
+ this.uid = this.el.id ? this.el.id : generateId();
135
+ if (document.body.classList.contains("wmcl-user-is-tabbing")) {
136
+ this.toggleTabbingOn();
137
+ }
138
+ }
139
+ componentDidLoad() {
140
+ this.wmSelectDidLoad.emit();
141
+ if (!this.childItems.length) {
142
+ throw new Error("wm-select should have wm-option elements as children.");
143
+ }
144
+ if (this.multiple && this.childItems.filter((x) => x.subinfo).length > 0) {
145
+ throw new Error("wm-select with the multiple prop cannot have subinfo options");
146
+ }
147
+ if (this.multiple && !this.placeholder) {
148
+ throw new Error("wm-select with the multiple prop needs to also use the placeholder prop.");
149
+ }
150
+ // set initial selections / button text
151
+ if (this.selectedItems.length > 0) {
152
+ this.selectedItems.forEach((x) => this.displayedItems.push(x));
153
+ this.setButtonText();
154
+ // single Select only, pre-select if no default option from dev
155
+ }
156
+ else if (!this.multiple) {
157
+ this.selectItem(this.childItems[0]);
158
+ }
159
+ this.optionsEl.classList.add("hidden");
160
+ forceUpdate(this.el);
161
+ // Dev can overwrite the max-height rule set in the Sass file
162
+ if (this.maxHeight) {
163
+ this.optionsEl.style.maxHeight = this.maxHeight;
164
+ }
165
+ }
166
+ moveUp(el) {
167
+ const prevEl = el.previousElementSibling;
168
+ if (prevEl) {
169
+ // scroll option to top of dropdown if partially obscured / out of view
170
+ if (prevEl.getBoundingClientRect().top < this.optionsEl.getBoundingClientRect().top) {
171
+ this.optionsEl.scrollTop =
172
+ prevEl.getBoundingClientRect().top - this.optionsEl.getBoundingClientRect().top + this.optionsEl.scrollTop;
173
+ }
174
+ this.focusItem(prevEl);
175
+ }
176
+ else {
177
+ this.focusItem(this.childItems[this.childItems.length - 1]);
178
+ }
179
+ }
180
+ moveDown(el) {
181
+ const nextEl = el.nextElementSibling;
182
+ if (nextEl && nextEl.tagName !== "INPUT") {
183
+ // scroll option to bottom of dropdown if partially obscured / out of view
184
+ if (nextEl.getBoundingClientRect().bottom > this.optionsEl.getBoundingClientRect().bottom) {
185
+ this.optionsEl.scrollTop =
186
+ nextEl.getBoundingClientRect().bottom -
187
+ this.optionsEl.getBoundingClientRect().top +
188
+ this.optionsEl.scrollTop -
189
+ this.optionsEl.offsetHeight;
190
+ }
191
+ this.focusItem(nextEl);
192
+ }
193
+ else {
194
+ this.focusItem(this.childItems[0]);
195
+ }
196
+ }
197
+ open(itemToSelect) {
198
+ if (!this.disabled) {
199
+ const elHeight = this.el.clientHeight;
200
+ const buttonHeight = this.buttonEl.clientHeight;
201
+ this.openUp = shouldOpenUp(this.el, this.optionsEl,
202
+ // when opening up, dropdown covers both label and button
203
+ elHeight,
204
+ // when opening down, dropdown covers only the button
205
+ buttonHeight);
206
+ this.isExpanded = true;
207
+ this.optionsEl.classList.remove("hidden");
208
+ window.requestAnimationFrame(() => {
209
+ if (this.selectedItems.length > 0) {
210
+ if (itemToSelect === "next") {
211
+ this.moveDown(this.selectedItems[this.selectedItems.length - 1]);
212
+ }
213
+ else if (itemToSelect === "previous") {
214
+ this.moveUp(this.selectedItems[0]);
215
+ }
216
+ else {
217
+ this.focusItem(this.selectedItems[0]);
218
+ }
219
+ }
220
+ else {
221
+ this.focusItem(this.childItems[0]);
222
+ }
223
+ });
224
+ }
225
+ }
226
+ close(returnFocus = true) {
227
+ this.isExpanded = false;
228
+ this.childItems.map((i) => (i.focused = false));
229
+ window.setTimeout(() => {
230
+ this.optionsEl.classList.add("hidden");
231
+ // Returns focus to button after popup closes (no need if user is tabbing)
232
+ // Delay is necessary for screenreader to get new expanded state before focus
233
+ // window.requestAnimationFrame is probably enough, but since we are already using setTimeout it may as well be here
234
+ // also UX wise, it makes sense for the button to only be focused after the animation is complete
235
+ if (returnFocus) {
236
+ this.el.focus();
237
+ }
238
+ }, 150);
239
+ }
240
+ focusItem(item) {
241
+ this.childItems.forEach((i) => (i.focused = i === item));
242
+ }
243
+ selectItem(item) {
244
+ if (this.multiple) {
245
+ item.selected = !item.selected;
246
+ }
247
+ else {
248
+ this.childItems.forEach((i) => (i.selected = i === item));
249
+ }
250
+ this.setButtonText();
251
+ }
252
+ findAndFocusItem(ev) {
253
+ const character = ev.detail.toUpperCase();
254
+ if (!this.keysSoFar) {
255
+ for (var i = 0; i < this.childItems.length; i++) {
256
+ if (this.childItems[i].focused) {
257
+ this.searchIndex = i;
258
+ }
259
+ }
260
+ }
261
+ this.keysSoFar += character;
262
+ this.clearKeysSoFarAfterDelay();
263
+ var nextMatch = this.findMatchInRange(this.childItems, this.searchIndex + 1, this.childItems.length);
264
+ if (!nextMatch) {
265
+ nextMatch = this.findMatchInRange(this.childItems, 0, this.searchIndex);
266
+ }
267
+ if (nextMatch) {
268
+ this.focusItem(nextMatch);
269
+ }
270
+ }
271
+ clearKeysSoFarAfterDelay() {
272
+ if (this.keyClear) {
273
+ window.clearTimeout(this.keyClear);
274
+ this.keyClear = null;
275
+ }
276
+ this.keyClear = window.setTimeout(function () {
277
+ this.keysSoFar = "";
278
+ this.keyClear = null;
279
+ }.bind(this), 500);
280
+ }
281
+ findMatchInRange(list, startIndex, endIndex) {
282
+ // Find the first item starting with the keysSoFar substring, searching in
283
+ // the specified range of items
284
+ for (var n = startIndex; n < endIndex; n++) {
285
+ var label = list[n].textContent;
286
+ if (label && label.toUpperCase().indexOf(this.keysSoFar) === 0) {
287
+ return list[n];
288
+ }
289
+ }
290
+ return null;
291
+ }
292
+ exposeErrors() {
293
+ // When the error changes, a new id is set for the error container and the button's aria-describedby attribute is updated accordingly. This is to make sure the screen reader announces teh updated errors in Firefox. See this longstanding bug: https://bugzilla.mozilla.org/show_bug.cgi?id=493683
294
+ const newId = generateId();
295
+ this.errorContainer.id = `wm-errors-${newId}`;
296
+ this.buttonEl.setAttribute("aria-describedby", `wm-errors-${newId}`);
297
+ }
298
+ renderErrorContainer() {
299
+ return (h("div", { id: "wm-errors", class: this.errorMessage ? "error-message" : "", ref: (el) => (this.errorContainer = el), "aria-live": "assertive", "aria-atomic": "true" }, this.errorMessage));
300
+ }
301
+ handleComponentBlur() {
302
+ if (!this.isExpanded) {
303
+ this.wmSelectBlurred.emit();
304
+ this.wmComponentBlurred.emit(); // deprecated
305
+ }
306
+ }
307
+ setButtonText() {
308
+ this.displayedItems = this.childItems.filter((x) => x.selected);
309
+ this.allSelected = this.displayedItems.length === this.childItems.length;
310
+ // handle overflow + counter for multiselect
311
+ if (this.multiple) {
312
+ // this is a fixed measurement accounting for the max width of a 3 character overflow counter
313
+ const overflowCounterWidth = 38;
314
+ const computedStyle = window.getComputedStyle(this.buttonEl);
315
+ // there seems to be no quick way to get an elements width without padding, except for subtracting padding manually
316
+ const paddingLeft = parseInt(computedStyle.getPropertyValue("padding-left").slice(0, -2));
317
+ const paddingRight = parseInt(computedStyle.getPropertyValue("padding-right").slice(0, -2));
318
+ const availableSpace = this.buttonEl.clientWidth - paddingLeft - paddingRight - overflowCounterWidth;
319
+ let optionsWidths = this.displayedItems.map((x) => x.shadowRoot.querySelector(".option-wrapper").clientWidth);
320
+ let optionsTotalWidth = optionsWidths.reduce((acc, x) => acc + x, 0);
321
+ this.overflowCount = 0;
322
+ while (optionsTotalWidth > availableSpace && this.displayedItems.length > 1) {
323
+ this.overflowCount++;
324
+ optionsTotalWidth -= optionsWidths[optionsWidths.length - 1];
325
+ optionsWidths.pop();
326
+ this.displayedItems.pop();
327
+ }
328
+ }
329
+ }
330
+ renderButtonText() {
331
+ if (this.multiple && this.displayedItems.length < 1) {
332
+ return h("span", null, this.placeholder);
333
+ }
334
+ else if (this.multiple && this.allSelected && this.overflowCount > 0) {
335
+ return this.allSelectedMessage;
336
+ }
337
+ else {
338
+ return this.displayedItems.map((x, idx) => (h("span", null,
339
+ idx > 0 ? ", " : "",
340
+ x.textContent)));
341
+ }
342
+ }
343
+ renderSubinfo() {
344
+ // multiselects cannot have subinfo for options
345
+ if (!this.multiple && this.selectedItems.length > 0 && this.selectedItems[0].subinfo) {
346
+ return h("span", { class: "subinfo" }, this.selectedItems[0].subinfo);
347
+ }
348
+ }
349
+ renderOverflowCount() {
350
+ if (this.overflowCount > 0 && !this.allSelected) {
351
+ return (h("span", null,
352
+ h("span", { class: "overflow-counter" },
353
+ "+",
354
+ this.overflowCount)));
355
+ }
356
+ }
357
+ render() {
358
+ const buttonProps = {
359
+ id: `selectbtn-${this.uid}`,
360
+ ["disabled"]: this.disabled,
361
+ ["aria-controls"]: `list-${this.uid}`,
362
+ ["aria-labelledby"]: `label-${this.uid} selectbtn-${this.uid}`,
363
+ ["aria-describedby"]: "wm-errors",
364
+ ["aria-expanded"]: this.isExpanded ? "true" : "false",
365
+ onClick: () => (this.isExpanded ? this.close() : this.open()),
366
+ onBlur: () => this.handleComponentBlur(),
367
+ };
368
+ return (h(Host, { onBlur: () => this.close(false) },
369
+ h("div", { class: `wrapper ${getTextDir()} label-${this.labelPosition} ${this.invalid || this.errorMessage ? "invalid" : ""}` },
370
+ h("div", { class: "label-wrapper" },
371
+ h("label", { class: "label", id: `label-${this.uid}`, htmlFor: `selectbtn-${this.uid}` },
372
+ this.label,
373
+ // we can't use aria-required or required attributes because it's invalid on the elements we're using (button controlling a listbox)
374
+ this.requiredField ? (h("span", { class: "required" },
375
+ h("span", { class: "sr-only" }, this.requiredMessage),
376
+ h("span", { "aria-hidden": "true" }, "*"))) : (""))),
377
+ h("div", { class: "dropdown" },
378
+ h("button", Object.assign({}, buttonProps, { class: `displayedoption ${this.isTabbing ? "user-is-tabbing" : ""}`, ref: (el) => (this.buttonEl = el), onBlur: (ev) => this.handleButtonBlur(ev) }),
379
+ h("span", { class: this.selectedItems.length > 0 && this.selectedItems.filter((x) => x.subinfo).length > 0
380
+ ? "overflowcontrol hassubinfo"
381
+ : "overflowcontrol" },
382
+ h("span", { class: "button-text" }, this.renderButtonText()),
383
+ this.renderSubinfo()),
384
+ this.renderOverflowCount()),
385
+ h("div", { class: `options ${this.isExpanded ? "open" : ""} ${this.openUp ? "upwards" : ""}`, id: `list-${this.uid}`, tabindex: -1, role: "listbox", "aria-multiselectable": this.multiple ? "true" : null, "aria-labelledby": `label-${this.uid}`, ref: (el) => (this.optionsEl = el) },
386
+ h("slot", null)),
387
+ this.renderErrorContainer()))));
388
+ }
389
+ static get is() { return "wm-select"; }
390
+ static get encapsulation() { return "shadow"; }
391
+ static get originalStyleUrls() { return {
392
+ "$": ["wm-select.scss"]
393
+ }; }
394
+ static get styleUrls() { return {
395
+ "$": ["wm-select.css"]
396
+ }; }
397
+ static get properties() { return {
398
+ "disabled": {
399
+ "type": "boolean",
400
+ "mutable": false,
401
+ "complexType": {
402
+ "original": "boolean",
403
+ "resolved": "boolean",
404
+ "references": {}
405
+ },
406
+ "required": false,
407
+ "optional": false,
408
+ "docs": {
409
+ "tags": [],
410
+ "text": ""
411
+ },
412
+ "attribute": "disabled",
413
+ "reflect": true,
414
+ "defaultValue": "false"
415
+ },
416
+ "invalid": {
417
+ "type": "boolean",
418
+ "mutable": true,
419
+ "complexType": {
420
+ "original": "boolean",
421
+ "resolved": "boolean",
422
+ "references": {}
423
+ },
424
+ "required": false,
425
+ "optional": false,
426
+ "docs": {
427
+ "tags": [],
428
+ "text": ""
429
+ },
430
+ "attribute": "invalid",
431
+ "reflect": false,
432
+ "defaultValue": "false"
433
+ },
434
+ "maxHeight": {
435
+ "type": "string",
436
+ "mutable": false,
437
+ "complexType": {
438
+ "original": "string",
439
+ "resolved": "string | undefined",
440
+ "references": {}
441
+ },
442
+ "required": false,
443
+ "optional": true,
444
+ "docs": {
445
+ "tags": [],
446
+ "text": ""
447
+ },
448
+ "attribute": "max-height",
449
+ "reflect": false
450
+ },
451
+ "label": {
452
+ "type": "string",
453
+ "mutable": true,
454
+ "complexType": {
455
+ "original": "string",
456
+ "resolved": "string | undefined",
457
+ "references": {}
458
+ },
459
+ "required": false,
460
+ "optional": true,
461
+ "docs": {
462
+ "tags": [],
463
+ "text": ""
464
+ },
465
+ "attribute": "label",
466
+ "reflect": false
467
+ },
468
+ "labelPosition": {
469
+ "type": "string",
470
+ "mutable": false,
471
+ "complexType": {
472
+ "original": "\"top\" | \"left\" | \"none\"",
473
+ "resolved": "\"left\" | \"none\" | \"top\"",
474
+ "references": {}
475
+ },
476
+ "required": false,
477
+ "optional": false,
478
+ "docs": {
479
+ "tags": [],
480
+ "text": ""
481
+ },
482
+ "attribute": "label-position",
483
+ "reflect": false,
484
+ "defaultValue": "\"top\""
485
+ },
486
+ "requiredField": {
487
+ "type": "boolean",
488
+ "mutable": false,
489
+ "complexType": {
490
+ "original": "boolean",
491
+ "resolved": "boolean",
492
+ "references": {}
493
+ },
494
+ "required": false,
495
+ "optional": false,
496
+ "docs": {
497
+ "tags": [],
498
+ "text": ""
499
+ },
500
+ "attribute": "required-field",
501
+ "reflect": false,
502
+ "defaultValue": "false"
503
+ },
504
+ "errorMessage": {
505
+ "type": "string",
506
+ "mutable": true,
507
+ "complexType": {
508
+ "original": "string",
509
+ "resolved": "string",
510
+ "references": {}
511
+ },
512
+ "required": false,
513
+ "optional": false,
514
+ "docs": {
515
+ "tags": [],
516
+ "text": ""
517
+ },
518
+ "attribute": "error-message",
519
+ "reflect": false,
520
+ "defaultValue": "\"\""
521
+ },
522
+ "multiple": {
523
+ "type": "boolean",
524
+ "mutable": false,
525
+ "complexType": {
526
+ "original": "boolean",
527
+ "resolved": "boolean",
528
+ "references": {}
529
+ },
530
+ "required": false,
531
+ "optional": false,
532
+ "docs": {
533
+ "tags": [],
534
+ "text": ""
535
+ },
536
+ "attribute": "multiple",
537
+ "reflect": false,
538
+ "defaultValue": "false"
539
+ },
540
+ "placeholder": {
541
+ "type": "string",
542
+ "mutable": false,
543
+ "complexType": {
544
+ "original": "string",
545
+ "resolved": "string",
546
+ "references": {}
547
+ },
548
+ "required": false,
549
+ "optional": false,
550
+ "docs": {
551
+ "tags": [],
552
+ "text": ""
553
+ },
554
+ "attribute": "placeholder",
555
+ "reflect": false,
556
+ "defaultValue": "intl.formatMessage({\n id: \"select.multiPlaceholder\",\n defaultMessage: \"Make a selection\",\n })"
557
+ },
558
+ "allSelectedMessage": {
559
+ "type": "string",
560
+ "mutable": false,
561
+ "complexType": {
562
+ "original": "string",
563
+ "resolved": "string",
564
+ "references": {}
565
+ },
566
+ "required": false,
567
+ "optional": false,
568
+ "docs": {
569
+ "tags": [],
570
+ "text": ""
571
+ },
572
+ "attribute": "all-selected-message",
573
+ "reflect": false,
574
+ "defaultValue": "intl.formatMessage({\n id: \"select.allSelected\",\n defaultMessage: \"All selected\",\n })"
575
+ }
576
+ }; }
577
+ static get states() { return {
578
+ "isTabbing": {},
579
+ "isExpanded": {}
580
+ }; }
581
+ static get events() { return [{
582
+ "method": "wmSelectDidLoad",
583
+ "name": "wmSelectDidLoad",
584
+ "bubbles": true,
585
+ "cancelable": true,
586
+ "composed": true,
587
+ "docs": {
588
+ "tags": [],
589
+ "text": ""
590
+ },
591
+ "complexType": {
592
+ "original": "void",
593
+ "resolved": "void",
594
+ "references": {}
595
+ }
596
+ }, {
597
+ "method": "wmSelectBlurred",
598
+ "name": "wmSelectBlurred",
599
+ "bubbles": true,
600
+ "cancelable": true,
601
+ "composed": true,
602
+ "docs": {
603
+ "tags": [],
604
+ "text": ""
605
+ },
606
+ "complexType": {
607
+ "original": "void",
608
+ "resolved": "void",
609
+ "references": {}
610
+ }
611
+ }, {
612
+ "method": "wmComponentBlurred",
613
+ "name": "wmComponentBlurred",
614
+ "bubbles": true,
615
+ "cancelable": true,
616
+ "composed": true,
617
+ "docs": {
618
+ "tags": [],
619
+ "text": ""
620
+ },
621
+ "complexType": {
622
+ "original": "void",
623
+ "resolved": "void",
624
+ "references": {}
625
+ }
626
+ }]; }
627
+ static get elementRef() { return "el"; }
628
+ static get watchers() { return [{
629
+ "propName": "errorMessage",
630
+ "methodName": "exposeErrors"
631
+ }]; }
632
+ static get listeners() { return [{
633
+ "name": "wmUserIsTabbing",
634
+ "method": "toggleTabbingOn",
635
+ "target": "window",
636
+ "capture": false,
637
+ "passive": false
638
+ }, {
639
+ "name": "wmUserIsNotTabbing",
640
+ "method": "toggleTabbingOff",
641
+ "target": "window",
642
+ "capture": false,
643
+ "passive": false
644
+ }, {
645
+ "name": "wmOptionSelected",
646
+ "method": "handleOptionSelection",
647
+ "target": undefined,
648
+ "capture": false,
649
+ "passive": false
650
+ }, {
651
+ "name": "wmEnterKeyPressed",
652
+ "method": "handeChildEnter",
653
+ "target": undefined,
654
+ "capture": false,
655
+ "passive": false
656
+ }, {
657
+ "name": "wmKeyUpPressed",
658
+ "method": "handleChildUp",
659
+ "target": undefined,
660
+ "capture": false,
661
+ "passive": false
662
+ }, {
663
+ "name": "wmKeyDownPressed",
664
+ "method": "handleChildDown",
665
+ "target": undefined,
666
+ "capture": false,
667
+ "passive": false
668
+ }, {
669
+ "name": "wmHomeKeyPressed",
670
+ "method": "moveToFirstItem",
671
+ "target": undefined,
672
+ "capture": false,
673
+ "passive": false
674
+ }, {
675
+ "name": "wmEndKeyPressed",
676
+ "method": "moveToLastItem",
677
+ "target": undefined,
678
+ "capture": false,
679
+ "passive": false
680
+ }, {
681
+ "name": "wmTabKeyPressed",
682
+ "method": "handleTabKey",
683
+ "target": undefined,
684
+ "capture": false,
685
+ "passive": false
686
+ }, {
687
+ "name": "wmEscKeyPressed",
688
+ "method": "closePopupOnEscape",
689
+ "target": undefined,
690
+ "capture": false,
691
+ "passive": false
692
+ }, {
693
+ "name": "wmOptionBlurred",
694
+ "method": "handleOptionBlur",
695
+ "target": undefined,
696
+ "capture": false,
697
+ "passive": false
698
+ }, {
699
+ "name": "click",
700
+ "method": "handleClick",
701
+ "target": "document",
702
+ "capture": true,
703
+ "passive": false
704
+ }, {
705
+ "name": "keydown",
706
+ "method": "handleKey",
707
+ "target": undefined,
708
+ "capture": false,
709
+ "passive": false
710
+ }, {
711
+ "name": "wmLetterPressed",
712
+ "method": "findAndFocusItem",
713
+ "target": undefined,
714
+ "capture": false,
715
+ "passive": false
716
+ }]; }
717
+ }