q2-tecton-elements 1.23.0 → 1.25.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 (212) hide show
  1. package/dist/cjs/action-sheet-4b366e9a.js +84 -0
  2. package/dist/cjs/{index-0648c2ec.js → index-dc92e71f.js} +32 -5
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/q2-action-sheet.cjs.entry.js +218 -0
  5. package/dist/cjs/q2-badge_2.cjs.entry.js +46 -17
  6. package/dist/cjs/q2-btn_2.cjs.entry.js +1 -1
  7. package/dist/cjs/q2-calendar.cjs.entry.js +2 -4
  8. package/dist/cjs/q2-card.cjs.entry.js +1 -1
  9. package/dist/cjs/q2-carousel-pane.cjs.entry.js +1 -1
  10. package/dist/cjs/q2-carousel.cjs.entry.js +1 -1
  11. package/dist/cjs/q2-chart-area.cjs.entry.js +1 -1
  12. package/dist/cjs/q2-chart-bar.cjs.entry.js +1 -1
  13. package/dist/cjs/q2-chart-donut.cjs.entry.js +1 -1
  14. package/dist/cjs/q2-checkbox-group.cjs.entry.js +1 -1
  15. package/dist/cjs/q2-checkbox.cjs.entry.js +1 -1
  16. package/dist/cjs/q2-dropdown-item.cjs.entry.js +1 -1
  17. package/dist/cjs/q2-dropdown.cjs.entry.js +1 -1
  18. package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
  19. package/dist/cjs/q2-icon.cjs.entry.js +1 -1
  20. package/dist/cjs/q2-loc.cjs.entry.js +1 -1
  21. package/dist/cjs/q2-message.cjs.entry.js +1 -1
  22. package/dist/cjs/q2-month-picker.cjs.entry.js +1 -1
  23. package/dist/cjs/q2-optgroup_2.cjs.entry.js +93 -0
  24. package/dist/cjs/q2-option-list_2.cjs.entry.js +226 -86
  25. package/dist/cjs/q2-pagination.cjs.entry.js +1 -1
  26. package/dist/cjs/q2-pill.cjs.entry.js +57 -18
  27. package/dist/cjs/q2-radio-group.cjs.entry.js +1 -1
  28. package/dist/cjs/q2-radio.cjs.entry.js +1 -1
  29. package/dist/cjs/q2-section.cjs.entry.js +1 -1
  30. package/dist/cjs/q2-select.cjs.entry.js +148 -409
  31. package/dist/cjs/q2-stepper-pane.cjs.entry.js +1 -1
  32. package/dist/cjs/q2-stepper-vertical.cjs.entry.js +1 -1
  33. package/dist/cjs/q2-stepper.cjs.entry.js +1 -1
  34. package/dist/cjs/q2-tab-container.cjs.entry.js +1 -1
  35. package/dist/cjs/q2-tag.cjs.entry.js +21 -7
  36. package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
  37. package/dist/cjs/q2-textarea.cjs.entry.js +1 -1
  38. package/dist/collection/collection-manifest.json +1 -0
  39. package/dist/collection/components/q2-action-sheet/index.js +345 -0
  40. package/dist/collection/components/q2-action-sheet/styles.css +215 -0
  41. package/dist/collection/components/q2-calendar/index.js +2 -4
  42. package/dist/collection/components/q2-checkbox/index.js +2 -2
  43. package/dist/collection/components/q2-dropdown/index.js +1 -1
  44. package/dist/collection/components/q2-input/index.js +46 -17
  45. package/dist/collection/components/q2-loading/index.js +1 -1
  46. package/dist/collection/components/q2-optgroup/styles.css +2 -2
  47. package/dist/collection/components/q2-option/index.js +3 -58
  48. package/dist/collection/components/q2-option/styles.css +7 -0
  49. package/dist/collection/components/q2-option-list/index.js +290 -102
  50. package/dist/collection/components/q2-pill/index.js +79 -18
  51. package/dist/collection/components/q2-pill/styles.css +1 -2
  52. package/dist/collection/components/q2-popover/index.js +17 -3
  53. package/dist/collection/components/q2-popover/styles.css +10 -67
  54. package/dist/collection/components/q2-radio/index.js +2 -2
  55. package/dist/collection/components/q2-select/index.js +179 -427
  56. package/dist/collection/components/q2-select/styles.css +5 -11
  57. package/dist/collection/components/q2-tag/index.js +33 -19
  58. package/dist/collection/utils/action-sheet.js +79 -0
  59. package/dist/collection/utils/index.js +29 -5
  60. package/dist/components/action-sheet.js +81 -0
  61. package/dist/components/index.d.ts +1 -0
  62. package/dist/components/index.js +1 -0
  63. package/dist/components/index10.js +1 -1
  64. package/dist/components/index11.js +42 -353
  65. package/dist/components/index12.js +44 -99
  66. package/dist/components/index13.js +495 -583
  67. package/dist/components/index14.js +137 -0
  68. package/dist/components/index15.js +629 -0
  69. package/dist/components/index5.js +1 -1
  70. package/dist/components/index6.js +1 -1
  71. package/dist/components/index7.js +1 -1
  72. package/dist/components/index8.js +46 -17
  73. package/dist/components/index9.js +2 -2
  74. package/dist/components/q2-action-sheet.d.ts +11 -0
  75. package/dist/components/q2-action-sheet.js +282 -0
  76. package/dist/components/q2-calendar.js +2 -4
  77. package/dist/components/q2-card.js +1 -1
  78. package/dist/components/q2-carousel-pane.js +1 -1
  79. package/dist/components/q2-carousel.js +1 -1
  80. package/dist/components/q2-chart-area.js +1 -1
  81. package/dist/components/q2-chart-bar.js +1 -1
  82. package/dist/components/q2-chart-donut.js +1 -1
  83. package/dist/components/q2-checkbox-group.js +1 -1
  84. package/dist/components/q2-checkbox.js +1 -1
  85. package/dist/components/q2-dropdown.js +2 -2
  86. package/dist/components/q2-editable-field.js +1 -1
  87. package/dist/components/q2-loc.js +1 -1
  88. package/dist/components/q2-month-picker.js +1 -1
  89. package/dist/components/q2-optgroup.js +1 -70
  90. package/dist/components/q2-option-list.js +1 -1
  91. package/dist/components/q2-option.js +1 -76
  92. package/dist/components/q2-pagination.js +1 -1
  93. package/dist/components/q2-pill.js +62 -21
  94. package/dist/components/q2-popover.js +1 -1
  95. package/dist/components/q2-radio-group.js +1 -1
  96. package/dist/components/q2-radio.js +3 -3
  97. package/dist/components/q2-section.js +1 -1
  98. package/dist/components/q2-select.js +179 -427
  99. package/dist/components/q2-stepper-pane.js +1 -1
  100. package/dist/components/q2-stepper-vertical.js +1 -1
  101. package/dist/components/q2-stepper.js +1 -1
  102. package/dist/components/q2-tab-container.js +1 -1
  103. package/dist/components/q2-tag.js +25 -11
  104. package/dist/components/q2-textarea.js +1 -1
  105. package/dist/docs.d.ts +148 -0
  106. package/dist/docs.json +8755 -0
  107. package/dist/esm/action-sheet-a9597b32.js +81 -0
  108. package/dist/esm/{index-501fd22e.js → index-d4a87058.js} +30 -6
  109. package/dist/esm/loader.js +1 -1
  110. package/dist/esm/q2-action-sheet.entry.js +214 -0
  111. package/dist/esm/q2-badge_2.entry.js +46 -17
  112. package/dist/esm/q2-btn_2.entry.js +1 -1
  113. package/dist/esm/q2-calendar.entry.js +2 -4
  114. package/dist/esm/q2-card.entry.js +1 -1
  115. package/dist/esm/q2-carousel-pane.entry.js +1 -1
  116. package/dist/esm/q2-carousel.entry.js +1 -1
  117. package/dist/esm/q2-chart-area.entry.js +1 -1
  118. package/dist/esm/q2-chart-bar.entry.js +1 -1
  119. package/dist/esm/q2-chart-donut.entry.js +1 -1
  120. package/dist/esm/q2-checkbox-group.entry.js +1 -1
  121. package/dist/esm/q2-checkbox.entry.js +1 -1
  122. package/dist/esm/q2-dropdown-item.entry.js +1 -1
  123. package/dist/esm/q2-dropdown.entry.js +1 -1
  124. package/dist/esm/q2-editable-field.entry.js +1 -1
  125. package/dist/esm/q2-icon.entry.js +1 -1
  126. package/dist/esm/q2-loc.entry.js +1 -1
  127. package/dist/esm/q2-message.entry.js +1 -1
  128. package/dist/esm/q2-month-picker.entry.js +1 -1
  129. package/dist/esm/q2-optgroup_2.entry.js +88 -0
  130. package/dist/esm/q2-option-list_2.entry.js +226 -86
  131. package/dist/esm/q2-pagination.entry.js +1 -1
  132. package/dist/esm/q2-pill.entry.js +57 -18
  133. package/dist/esm/q2-radio-group.entry.js +1 -1
  134. package/dist/esm/q2-radio.entry.js +1 -1
  135. package/dist/esm/q2-section.entry.js +1 -1
  136. package/dist/esm/q2-select.entry.js +148 -409
  137. package/dist/esm/q2-stepper-pane.entry.js +1 -1
  138. package/dist/esm/q2-stepper-vertical.entry.js +1 -1
  139. package/dist/esm/q2-stepper.entry.js +1 -1
  140. package/dist/esm/q2-tab-container.entry.js +1 -1
  141. package/dist/esm/q2-tag.entry.js +22 -8
  142. package/dist/esm/q2-tecton-elements.js +1 -1
  143. package/dist/esm/q2-textarea.entry.js +1 -1
  144. package/dist/q2-tecton-elements/p-059065e4.js +1 -0
  145. package/dist/q2-tecton-elements/{p-9b101e22.entry.js → p-1a744921.entry.js} +1 -1
  146. package/dist/q2-tecton-elements/{p-3fd5d010.entry.js → p-1b95e43f.entry.js} +1 -1
  147. package/dist/q2-tecton-elements/{p-3603fcdc.entry.js → p-1ea4b8bd.entry.js} +1 -1
  148. package/dist/q2-tecton-elements/{p-53be87c8.entry.js → p-1f3eb04c.entry.js} +1 -1
  149. package/dist/q2-tecton-elements/p-25839309.entry.js +1 -0
  150. package/dist/q2-tecton-elements/{p-38a33baa.entry.js → p-274ec152.entry.js} +1 -1
  151. package/dist/q2-tecton-elements/{p-6be86940.entry.js → p-2ba9e1a2.entry.js} +1 -1
  152. package/dist/q2-tecton-elements/{p-ebd7efa5.entry.js → p-2c309c54.entry.js} +1 -1
  153. package/dist/q2-tecton-elements/{p-3e9a30c4.entry.js → p-2cc70f49.entry.js} +1 -1
  154. package/dist/q2-tecton-elements/{p-604b22a8.entry.js → p-2ceb41c4.entry.js} +1 -1
  155. package/dist/q2-tecton-elements/p-2e938b20.entry.js +1 -0
  156. package/dist/q2-tecton-elements/{p-5b1aba1a.entry.js → p-306a4bc7.entry.js} +1 -1
  157. package/dist/q2-tecton-elements/p-32f44993.entry.js +1 -0
  158. package/dist/q2-tecton-elements/{p-d7b27803.entry.js → p-3a9aac19.entry.js} +1 -1
  159. package/dist/q2-tecton-elements/p-3c73ce3f.entry.js +1 -0
  160. package/dist/q2-tecton-elements/p-4a95f78e.entry.js +1 -0
  161. package/dist/q2-tecton-elements/{p-6b7e1ebd.entry.js → p-4b48a49d.entry.js} +1 -1
  162. package/dist/q2-tecton-elements/p-4b92e44e.entry.js +1 -0
  163. package/dist/q2-tecton-elements/p-5ecb9c27.entry.js +1 -0
  164. package/dist/q2-tecton-elements/p-6779270e.entry.js +1 -0
  165. package/dist/q2-tecton-elements/{p-70b01387.entry.js → p-72fc58e7.entry.js} +1 -1
  166. package/dist/q2-tecton-elements/p-7ac02ae5.entry.js +1 -0
  167. package/dist/q2-tecton-elements/{p-78fac0fa.entry.js → p-7c168977.entry.js} +1 -1
  168. package/dist/q2-tecton-elements/{p-d27b2caa.entry.js → p-7c9bf80a.entry.js} +1 -1
  169. package/dist/q2-tecton-elements/p-83d678c7.entry.js +1 -0
  170. package/dist/q2-tecton-elements/p-a1926e65.js +1 -0
  171. package/dist/q2-tecton-elements/{p-24f4571d.entry.js → p-a3a5b57b.entry.js} +1 -1
  172. package/dist/q2-tecton-elements/p-a6296870.entry.js +1 -0
  173. package/dist/q2-tecton-elements/{p-45d61789.entry.js → p-a64e7eb1.entry.js} +1 -1
  174. package/dist/q2-tecton-elements/{p-8dea9a0c.entry.js → p-ad83984e.entry.js} +1 -1
  175. package/dist/q2-tecton-elements/{p-bf41e71b.entry.js → p-bf0ed24a.entry.js} +1 -1
  176. package/dist/q2-tecton-elements/{p-a2add94e.entry.js → p-bff85959.entry.js} +1 -1
  177. package/dist/q2-tecton-elements/{p-7aa80653.entry.js → p-c4a9ab25.entry.js} +1 -1
  178. package/dist/q2-tecton-elements/p-ea5383ba.entry.js +1 -0
  179. package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
  180. package/dist/test/helpers.js +3 -2
  181. package/dist/types/components/q2-action-sheet/index.d.ts +52 -0
  182. package/dist/types/components/q2-checkbox/index.d.ts +4 -1
  183. package/dist/types/components/q2-input/index.d.ts +5 -0
  184. package/dist/types/components/q2-option/index.d.ts +1 -4
  185. package/dist/types/components/q2-option-list/index.d.ts +16 -8
  186. package/dist/types/components/q2-pill/index.d.ts +10 -1
  187. package/dist/types/components/q2-popover/index.d.ts +2 -0
  188. package/dist/types/components/q2-select/index.d.ts +45 -47
  189. package/dist/types/components/q2-tag/index.d.ts +3 -3
  190. package/dist/types/components.d.ts +44 -17
  191. package/dist/types/global.d.ts +9 -2
  192. package/dist/types/utils/action-sheet.d.ts +12 -0
  193. package/dist/types/utils/index.d.ts +4 -1
  194. package/dist/types/workspace/workspace/Tecton_tecton-production_master/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +1 -1
  195. package/package.json +4 -2
  196. package/dist/cjs/q2-optgroup.cjs.entry.js +0 -56
  197. package/dist/cjs/q2-option.cjs.entry.js +0 -46
  198. package/dist/esm/q2-optgroup.entry.js +0 -52
  199. package/dist/esm/q2-option.entry.js +0 -42
  200. package/dist/q2-tecton-elements/p-18629cbf.entry.js +0 -1
  201. package/dist/q2-tecton-elements/p-2c20fc43.entry.js +0 -1
  202. package/dist/q2-tecton-elements/p-3813f51d.entry.js +0 -1
  203. package/dist/q2-tecton-elements/p-68ef0786.entry.js +0 -1
  204. package/dist/q2-tecton-elements/p-a510290a.js +0 -1
  205. package/dist/q2-tecton-elements/p-acc77332.entry.js +0 -1
  206. package/dist/q2-tecton-elements/p-ba73ee1f.entry.js +0 -1
  207. package/dist/q2-tecton-elements/p-ba76ecfd.entry.js +0 -1
  208. package/dist/q2-tecton-elements/p-bbdae095.entry.js +0 -1
  209. package/dist/q2-tecton-elements/p-d68b5eb3.entry.js +0 -1
  210. package/dist/q2-tecton-elements/p-d88e4383.entry.js +0 -1
  211. package/dist/q2-tecton-elements/p-f1d06917.entry.js +0 -1
  212. package/dist/q2-tecton-elements/p-f6e868c1.entry.js +0 -1
@@ -1,58 +1,136 @@
1
1
  import { h, Host, } from '@stencil/core';
2
- import { isEventFromElement, overrideFocus } from 'src/utils';
2
+ import { isEventFromElement, nextPaint, overrideFocus } from 'src/utils';
3
3
  export class Q2OptionList {
4
4
  constructor() {
5
5
  this.scheduledAfterRender = [];
6
6
  /// Event Handlers ///
7
7
  /* tslint:disable:cyclomatic-complexity */
8
- this.keydownHandler = (event, ignoreSelectionEvents) => {
8
+ this.externalKeydownHandler = (event) => {
9
+ event.stopPropagation();
10
+ const { activeIndex, customSearch, allOptions } = this;
11
+ const { key } = event;
12
+ let nextIndex;
13
+ switch (key) {
14
+ case ' ':
15
+ if (this.searchString) {
16
+ if (customSearch)
17
+ break;
18
+ this.searchOptions(key, true);
19
+ break;
20
+ }
21
+ this.setDefaultActiveElement();
22
+ break;
23
+ case 'Enter':
24
+ this.setDefaultActiveElement();
25
+ break;
26
+ case 'ArrowUp':
27
+ event.preventDefault();
28
+ this.activeIndex = 0;
29
+ nextIndex = !!this.selectedOptions.length ? this.getDefaultActiveIndex() : this.getNextVisibleIndex(-1);
30
+ if (nextIndex === -1)
31
+ break;
32
+ this.openDropdownWithActiveElement(nextIndex);
33
+ break;
34
+ case 'ArrowDown':
35
+ event.preventDefault();
36
+ this.activeIndex = 0;
37
+ nextIndex = !!this.selectedOptions.length ? this.getDefaultActiveIndex() : this.getNextVisibleIndex(0);
38
+ if (nextIndex === -1)
39
+ break;
40
+ this.openDropdownWithActiveElement(nextIndex);
41
+ break;
42
+ case 'Home':
43
+ event.preventDefault();
44
+ this.openDropdownWithActiveElement(0);
45
+ break;
46
+ case 'End':
47
+ event.preventDefault();
48
+ this.openDropdownWithActiveElement(allOptions.length - 1);
49
+ break;
50
+ case 'PageUp':
51
+ event.preventDefault();
52
+ this.openDropdownWithActiveElement(Math.max((activeIndex || 0) - 10, 0));
53
+ break;
54
+ case 'PageDown':
55
+ event.preventDefault();
56
+ this.openDropdownWithActiveElement(Math.min((activeIndex || 0) + 10, allOptions.length - 1));
57
+ break;
58
+ case 'Tab':
59
+ this.popoverState.emit({ open: false, action: 'close' });
60
+ break;
61
+ case 'Esc':
62
+ case 'Escape':
63
+ if (this.noSelect)
64
+ this.setActiveElement(null);
65
+ this.popoverState.emit({ open: false, action: 'close' });
66
+ break;
67
+ default:
68
+ if (customSearch)
69
+ break;
70
+ if (!key.match(/^[\w]$/))
71
+ break;
72
+ this.searchOptions(key, true);
73
+ break;
74
+ }
75
+ };
76
+ this.internalKeydownHandler = (event) => {
9
77
  event.stopPropagation();
10
78
  const { activeIndex, customSearch, allOptions } = this;
11
79
  const { key, shiftKey } = event;
12
80
  let newOption;
13
81
  switch (key) {
14
82
  case ' ':
15
- case 'Enter':
16
- if (ignoreSelectionEvents) {
17
- this.setDefaultActiveElement();
83
+ if (this.searchString) {
84
+ if (customSearch)
85
+ break;
86
+ this.searchOptions(key, false);
18
87
  break;
19
88
  }
20
89
  event.preventDefault();
21
90
  newOption = allOptions.find(element => element.active);
22
91
  if (!newOption || newOption.disabled)
23
92
  break;
24
- this.selectOption(newOption.value);
93
+ this.selectOption(newOption);
94
+ break;
95
+ case 'Enter':
96
+ event.preventDefault();
97
+ newOption = allOptions.find(element => element.active);
98
+ if (!newOption || newOption.disabled)
99
+ break;
100
+ this.selectOption(newOption);
25
101
  break;
26
102
  case 'ArrowUp':
27
103
  event.preventDefault();
28
- const isFirstOption = activeIndex === 0;
29
- if (isFirstOption)
104
+ const isFirstOptionActive = activeIndex === 0;
105
+ if (isFirstOptionActive)
30
106
  break;
31
107
  if (activeIndex === undefined) {
32
108
  this.setDefaultActiveElement();
109
+ break;
33
110
  }
34
111
  else {
35
112
  const nextIndex = this.getNextVisibleIndex(-1);
36
113
  if (nextIndex === -1)
37
114
  break;
38
115
  this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
116
+ break;
39
117
  }
40
- break;
41
118
  case 'ArrowDown':
42
119
  event.preventDefault();
43
- const isLastOption = activeIndex === allOptions.length - 1;
44
- if (isLastOption)
120
+ const isLastOptionActive = activeIndex === allOptions.length - 1;
121
+ if (isLastOptionActive)
45
122
  break;
46
123
  if (activeIndex === undefined) {
47
124
  this.setDefaultActiveElement();
125
+ break;
48
126
  }
49
127
  else {
50
128
  const nextIndex = this.getNextVisibleIndex(1);
51
129
  if (nextIndex === -1)
52
130
  break;
53
131
  this.adjustActiveOptionAndScroll(nextIndex - activeIndex);
132
+ break;
54
133
  }
55
- break;
56
134
  case 'Home':
57
135
  event.preventDefault();
58
136
  this.openDropdownWithActiveElement(0);
@@ -70,28 +148,25 @@ export class Q2OptionList {
70
148
  this.openDropdownWithActiveElement(Math.min(activeIndex + 10, allOptions.length - 1));
71
149
  break;
72
150
  case 'Tab':
73
- if (ignoreSelectionEvents)
74
- break;
75
151
  if (shiftKey)
76
152
  break;
77
153
  newOption = allOptions.find(element => element.active);
78
154
  if (!newOption || newOption.disabled)
79
155
  return;
80
- this.selectOption(newOption.value);
156
+ this.selectOption(newOption);
81
157
  break;
82
158
  case 'Esc':
83
159
  case 'Escape':
84
160
  if (this.noSelect)
85
161
  this.setActiveElement(null);
86
- this.popoverState.emit({ open: false });
162
+ this.popoverState.emit({ open: false, action: 'close' });
87
163
  break;
88
164
  default:
89
165
  if (customSearch)
90
166
  break;
91
- if (!key.match(/^[A-Za-z0-9]$/))
167
+ if (!key.match(/^[\w]$/))
92
168
  break;
93
- // search in non-searchable select: alpha-numeric only
94
- this.searchAndFocus(key);
169
+ this.searchOptions(key, false);
95
170
  break;
96
171
  }
97
172
  };
@@ -106,19 +181,17 @@ export class Q2OptionList {
106
181
  };
107
182
  this.clickHandler = (event) => {
108
183
  const target = event.target;
109
- if (target.localName !== 'q2-option' || target.disabled) {
110
- return;
111
- }
112
- this.selectOption(target.value);
184
+ const option = target.closest('q2-option');
185
+ this.selectOption(option);
113
186
  };
114
187
  this.role = 'listbox';
115
- this.direction = 'down';
116
188
  this.customSearch = undefined;
117
189
  this.noSelect = undefined;
118
190
  this.align = undefined;
119
191
  this.selectedOptions = [];
120
192
  this.multiple = undefined;
121
193
  this.disabled = undefined;
194
+ this.showSelected = undefined;
122
195
  this.type = undefined;
123
196
  this.hasOptions = undefined;
124
197
  }
@@ -130,26 +203,47 @@ export class Q2OptionList {
130
203
  overrideFocus(this.hostElement);
131
204
  this.checkOptions();
132
205
  this.selectedOptionsUpdated();
206
+ this.ready.emit();
133
207
  }
134
208
  componentDidRender() {
135
209
  this.scheduledAfterRender.forEach(fn => fn());
136
210
  this.scheduledAfterRender = [];
137
211
  }
138
212
  /// Getters ///
213
+ get allContents() {
214
+ const rootSlot = this.getRootSlot(this.hostElement);
215
+ const acceptedTags = ['Q2-OPTGROUP', 'Q2-OPTION'];
216
+ return rootSlot.filter(element => acceptedTags.includes(element.tagName));
217
+ }
139
218
  get allOptions() {
140
- return this.getRootSlot(this.hostElement);
219
+ const contents = this.allContents;
220
+ const extractOptions = (elements) => {
221
+ return elements.reduce((acc, element) => {
222
+ if (element.tagName === 'Q2-OPTGROUP') {
223
+ return [...acc, ...extractOptions(Array.from(element.children))];
224
+ }
225
+ else if (element.tagName === 'Q2-OPTION') {
226
+ return [...acc, element];
227
+ }
228
+ else {
229
+ return acc;
230
+ }
231
+ }, []);
232
+ };
233
+ return extractOptions(contents);
234
+ }
235
+ get allVisibleOptions() {
236
+ return this.allOptions.filter(option => !option.hidden && !option._multiSelectHidden && !option.disabled && !option.disabledGroup);
141
237
  }
142
238
  /// Helpers ///
143
- checkOptions() {
144
- const { noSelect, type, allOptions } = this;
145
- if (!noSelect && !type)
239
+ async checkOptions() {
240
+ const { type } = this;
241
+ const options = await this.getOptions();
242
+ if (!type)
146
243
  return;
147
244
  const optionRole = type === 'menu' ? 'menuitem' : 'option';
148
- allOptions.forEach(option => {
149
- if (noSelect)
150
- option.noSelect = true;
151
- if (type)
152
- option.role = optionRole;
245
+ options.forEach(option => {
246
+ option.role = optionRole;
153
247
  });
154
248
  }
155
249
  getRootSlot(element) {
@@ -168,20 +262,15 @@ export class Q2OptionList {
168
262
  const activeOption = this.allOptions[this.activeIndex];
169
263
  activeOption === null || activeOption === void 0 ? void 0 : activeOption.scrollIntoView({ block: 'nearest' });
170
264
  }
171
- resizeIframe() {
172
- var _a, _b;
173
- return (_b = (_a = window.TectonElements) === null || _a === void 0 ? void 0 : _a.resizeIframe) === null || _b === void 0 ? void 0 : _b.call(_a);
174
- }
175
265
  openDropdownWithActiveElement(activeIndex) {
176
266
  if (this.disabled)
177
267
  return;
178
268
  this.activeIndex = activeIndex;
179
- this.popoverState.emit({ open: true });
269
+ this.popoverState.emit({ open: true, action: 'open' });
180
270
  this.setActiveOption();
181
271
  this.setFocusedOption();
182
- this.scheduledAfterRender.push(() => {
272
+ nextPaint(() => {
183
273
  this.scrollToActiveOption();
184
- this.resizeIframe();
185
274
  });
186
275
  }
187
276
  getDefaultActiveIndex() {
@@ -195,16 +284,16 @@ export class Q2OptionList {
195
284
  return 0;
196
285
  }
197
286
  updateSingleOptionAttrs() {
198
- var _a, _b;
287
+ var _a;
199
288
  const { allOptions, selectedOptions } = this;
200
- const singleValue = (_b = (_a = selectedOptions[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : undefined;
289
+ const selectedValue = ((_a = selectedOptions[0]) === null || _a === void 0 ? void 0 : _a.value) || undefined;
201
290
  allOptions.forEach(element => {
202
- element.selected = element.value === singleValue;
291
+ element.selected = element.value === selectedValue;
203
292
  });
204
293
  }
205
294
  updateMultipleOptionAttrs() {
206
295
  const { allOptions, selectedOptions } = this;
207
- const selectedValues = selectedOptions.map(option => option.value);
296
+ const selectedValues = selectedOptions.map(({ value }) => value);
208
297
  allOptions.forEach(element => {
209
298
  element.selected = selectedValues.includes(element.value);
210
299
  });
@@ -219,38 +308,66 @@ export class Q2OptionList {
219
308
  const option = this.allOptions[this.activeIndex];
220
309
  if (!option)
221
310
  return;
222
- setTimeout(() => {
311
+ const isHostElementVisible = !!this.hostElement.offsetParent;
312
+ if (isHostElementVisible)
223
313
  option.focus();
224
- }, 25);
314
+ else
315
+ nextPaint(() => option.focus());
225
316
  }
226
317
  getNextVisibleIndex(direction) {
227
- let index = this.activeIndex + direction;
228
- while (index >= 0 && index <= this.allOptions.length - 1) {
229
- const { display, visibility } = window.getComputedStyle(this.allOptions[index]);
230
- if (display !== 'none' && visibility !== 'hidden') {
231
- return index;
232
- }
233
- index = index + direction;
318
+ const { allVisibleOptions, allOptions, activeIndex } = this;
319
+ const activeOption = allOptions[activeIndex];
320
+ const visibleActiveOptionIndex = allVisibleOptions.indexOf(activeOption);
321
+ let nextVisibleOptionIndex = visibleActiveOptionIndex + direction;
322
+ if (nextVisibleOptionIndex < 0) {
323
+ nextVisibleOptionIndex = allVisibleOptions.length - 1;
234
324
  }
235
- return -1;
325
+ else if (nextVisibleOptionIndex > allVisibleOptions.length - 1) {
326
+ nextVisibleOptionIndex = 0;
327
+ }
328
+ const nextVisibleOption = allVisibleOptions[nextVisibleOptionIndex];
329
+ return allOptions.indexOf(nextVisibleOption);
330
+ }
331
+ focusSelectedSibling(option) {
332
+ const { allVisibleOptions, allOptions } = this;
333
+ const hasNoSiblings = allVisibleOptions.length < 2;
334
+ if (hasNoSiblings) {
335
+ this.showSelected = false;
336
+ return;
337
+ }
338
+ const selectedOptionVisibleIndex = allVisibleOptions.indexOf(option);
339
+ const nextVisibleSiblingIndex = selectedOptionVisibleIndex
340
+ ? selectedOptionVisibleIndex - 1
341
+ : selectedOptionVisibleIndex + 1;
342
+ const nextVisibleSibling = allVisibleOptions[nextVisibleSiblingIndex];
343
+ const nextSiblingIndex = allOptions.indexOf(nextVisibleSibling);
344
+ this.activeIndex = nextSiblingIndex;
345
+ this.setFocusedOption();
346
+ this.scheduledAfterRender.push(() => {
347
+ option._multiSelectHidden = !option.selected;
348
+ });
236
349
  }
237
- selectOption(selectedValue) {
238
- const option = this.allOptions.find(({ value }) => value === selectedValue);
350
+ selectOption(selectedOption) {
351
+ const { multiple, noSelect, showSelected } = this;
352
+ if (!selectedOption || selectedOption.disabled || selectedOption.disabledGroup)
353
+ return;
354
+ const selectedValue = selectedOption.value;
239
355
  const valueObject = {
240
356
  value: selectedValue,
241
- display: option.display || option.innerText.trim(),
357
+ display: selectedOption.display || selectedOption.innerText.trim(),
242
358
  };
243
- const { multiple, noSelect } = this;
244
- let values;
359
+ let values = [];
245
360
  if (multiple) {
246
- const { selectedOptions = [] } = this;
247
- const isAlreadySelected = !!selectedOptions.find(({ value }) => value === selectedValue);
361
+ const { selectedOptions } = this;
362
+ const isAlreadySelected = selectedOptions.find(option => option.value === selectedValue);
248
363
  if (isAlreadySelected) {
249
364
  values = selectedOptions.filter(({ value }) => value !== selectedValue);
250
365
  }
251
366
  else {
252
367
  values = [...selectedOptions, valueObject];
253
368
  }
369
+ if (showSelected)
370
+ this.focusSelectedSibling(selectedOption);
254
371
  }
255
372
  else {
256
373
  values = [valueObject];
@@ -262,7 +379,7 @@ export class Q2OptionList {
262
379
  this.change.emit({ value: selectedValue, values });
263
380
  if (multiple)
264
381
  return;
265
- this.popoverState.emit({ open: false });
382
+ this.popoverState.emit({ open: false, action: 'select' });
266
383
  }
267
384
  adjustActiveOptionAndScroll(numToAdd) {
268
385
  this.activeIndex += numToAdd;
@@ -278,18 +395,29 @@ export class Q2OptionList {
278
395
  this.searchString = null;
279
396
  }, 2000);
280
397
  }
281
- searchAndFocus(key) {
398
+ searchOptions(key, shouldSelect) {
282
399
  this.resetTimer();
283
400
  let searchString = this.searchString ? `${this.searchString}${key}` : key;
284
- searchString = searchString.replace(/[^0-9a-z]/gi, '');
401
+ searchString = searchString.replace(/[^\w\s]/gi, '');
285
402
  this.searchString = searchString;
286
- const searchRegEx = new RegExp(searchString, 'i');
287
- const foundIndex = this.allOptions.findIndex(option => option.value === searchString || option.textContent.match(searchRegEx));
403
+ const searchRegEx = new RegExp(`^${searchString}`, 'i');
404
+ const { allOptions } = this;
405
+ const foundIndex = allOptions.findIndex(option => option.value === searchString || option.textContent.trim().match(searchRegEx));
288
406
  if (foundIndex === -1)
289
407
  return;
290
- this.setActiveElement(foundIndex);
408
+ if (shouldSelect)
409
+ this.selectOption(this.allOptions[foundIndex]);
410
+ else
411
+ this.setActiveElement(foundIndex);
291
412
  }
292
413
  /// Watchers ///
414
+ showSelectedUpdated(showSelected) {
415
+ if (showSelected && this.selectedOptions.length === 0) {
416
+ this.showSelected = false;
417
+ return;
418
+ }
419
+ this.allOptions.forEach(option => (option._multiSelectHidden = showSelected ? !option.selected : false));
420
+ }
293
421
  selectedOptionsUpdated() {
294
422
  if (this.multiple) {
295
423
  this.updateMultipleOptionAttrs();
@@ -302,8 +430,15 @@ export class Q2OptionList {
302
430
  delegateFocus(event) {
303
431
  if (!isEventFromElement(event, this.hostElement))
304
432
  return;
305
- this.popoverState.emit({ open: true });
306
- this.setDefaultActiveElement();
433
+ this.popoverState.emit({ open: true, action: 'open' });
434
+ const { activeIndex } = this;
435
+ if (typeof activeIndex === 'number' && activeIndex > -1) {
436
+ this.setActiveOption();
437
+ this.setFocusedOption();
438
+ }
439
+ else {
440
+ this.setDefaultActiveElement();
441
+ }
307
442
  }
308
443
  handleClick(event) {
309
444
  event.stopPropagation();
@@ -320,22 +455,17 @@ export class Q2OptionList {
320
455
  this.setFocusedOption();
321
456
  }
322
457
  async handleExternalKeydown(event) {
323
- const keysThatTriggerOpen = ['ArrowDown', 'ArrowUp', 'PageDown', 'PageUp', 'Home', 'End'];
324
- if (keysThatTriggerOpen.includes(event.key)) {
325
- this.popoverState.emit({ open: true });
326
- }
327
- const keysThatTriggerDefault = ['ArrowDown', 'ArrowUp'];
328
- if (keysThatTriggerDefault.includes(event.key)) {
329
- event.preventDefault();
330
- this.setDefaultActiveElement();
331
- }
332
- else {
333
- this.keydownHandler(event, true);
334
- }
458
+ this.externalKeydownHandler(event);
459
+ }
460
+ async getContents() {
461
+ return this.allContents;
462
+ }
463
+ async getOptions() {
464
+ return this.allOptions;
335
465
  }
336
466
  /// DOM ///
337
467
  render() {
338
- return (h(Host, null, h("div", { class: "content", ref: el => (this.contentElement = el), onFocusout: this.focusoutHandler }, h("div", { class: "options", role: this.type || 'listbox', onKeyDown: this.keydownHandler, onClick: this.clickHandler }, h("slot", null)))));
468
+ return (h(Host, null, h("div", { class: "content", ref: el => (this.contentElement = el), onFocusout: this.focusoutHandler }, h("div", { class: "options", role: this.type || 'listbox', onKeyDown: this.internalKeydownHandler, onClick: this.clickHandler }, h("slot", null)))));
339
469
  }
340
470
  static get is() { return "q2-option-list"; }
341
471
  static get encapsulation() { return "shadow"; }
@@ -369,24 +499,6 @@ export class Q2OptionList {
369
499
  "reflect": true,
370
500
  "defaultValue": "'listbox'"
371
501
  },
372
- "direction": {
373
- "type": "string",
374
- "mutable": false,
375
- "complexType": {
376
- "original": "'up' | 'down'",
377
- "resolved": "\"down\" | \"up\"",
378
- "references": {}
379
- },
380
- "required": false,
381
- "optional": false,
382
- "docs": {
383
- "tags": [],
384
- "text": ""
385
- },
386
- "attribute": "direction",
387
- "reflect": true,
388
- "defaultValue": "'down'"
389
- },
390
502
  "customSearch": {
391
503
  "type": "boolean",
392
504
  "mutable": false,
@@ -492,6 +604,23 @@ export class Q2OptionList {
492
604
  "attribute": "disabled",
493
605
  "reflect": true
494
606
  },
607
+ "showSelected": {
608
+ "type": "boolean",
609
+ "mutable": true,
610
+ "complexType": {
611
+ "original": "boolean",
612
+ "resolved": "boolean",
613
+ "references": {}
614
+ },
615
+ "required": false,
616
+ "optional": false,
617
+ "docs": {
618
+ "tags": [],
619
+ "text": ""
620
+ },
621
+ "attribute": "show-selected",
622
+ "reflect": true
623
+ },
495
624
  "type": {
496
625
  "type": "string",
497
626
  "mutable": false,
@@ -547,8 +676,23 @@ export class Q2OptionList {
547
676
  "text": ""
548
677
  },
549
678
  "complexType": {
550
- "original": "{ open: boolean }",
551
- "resolved": "{ open: boolean; }",
679
+ "original": "{ open: boolean; action: 'close' | 'select' | 'open' }",
680
+ "resolved": "{ open: boolean; action: \"select\" | \"open\" | \"close\"; }",
681
+ "references": {}
682
+ }
683
+ }, {
684
+ "method": "ready",
685
+ "name": "ready",
686
+ "bubbles": false,
687
+ "cancelable": true,
688
+ "composed": true,
689
+ "docs": {
690
+ "tags": [],
691
+ "text": ""
692
+ },
693
+ "complexType": {
694
+ "original": "any",
695
+ "resolved": "any",
552
696
  "references": {}
553
697
  }
554
698
  }];
@@ -611,12 +755,56 @@ export class Q2OptionList {
611
755
  "text": "",
612
756
  "tags": []
613
757
  }
758
+ },
759
+ "getContents": {
760
+ "complexType": {
761
+ "signature": "() => Promise<(HTMLQ2OptgroupElement | HTMLQ2OptionElement)[]>",
762
+ "parameters": [],
763
+ "references": {
764
+ "Promise": {
765
+ "location": "global"
766
+ },
767
+ "HTMLQ2OptgroupElement": {
768
+ "location": "global"
769
+ },
770
+ "HTMLQ2OptionElement": {
771
+ "location": "global"
772
+ }
773
+ },
774
+ "return": "Promise<(HTMLQ2OptgroupElement | HTMLQ2OptionElement)[]>"
775
+ },
776
+ "docs": {
777
+ "text": "",
778
+ "tags": []
779
+ }
780
+ },
781
+ "getOptions": {
782
+ "complexType": {
783
+ "signature": "() => Promise<HTMLQ2OptionElement[]>",
784
+ "parameters": [],
785
+ "references": {
786
+ "Promise": {
787
+ "location": "global"
788
+ },
789
+ "HTMLQ2OptionElement": {
790
+ "location": "global"
791
+ }
792
+ },
793
+ "return": "Promise<HTMLQ2OptionElement[]>"
794
+ },
795
+ "docs": {
796
+ "text": "",
797
+ "tags": []
798
+ }
614
799
  }
615
800
  };
616
801
  }
617
802
  static get elementRef() { return "hostElement"; }
618
803
  static get watchers() {
619
804
  return [{
805
+ "propName": "showSelected",
806
+ "methodName": "showSelectedUpdated"
807
+ }, {
620
808
  "propName": "selectedOptions",
621
809
  "methodName": "selectedOptionsUpdated"
622
810
  }];