@aquera/nile-elements 0.1.67-beta-1.9 → 0.1.67-beta-2.1

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 (213) hide show
  1. package/README.md +1 -23
  2. package/demo/index.html +61 -1
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.esm.js +1 -1
  5. package/dist/index.js +5640 -7857
  6. package/dist/internal/form.cjs.js +1 -1
  7. package/dist/internal/form.cjs.js.map +1 -1
  8. package/dist/internal/form.esm.js +1 -1
  9. package/dist/internal/resizable-table-styles.cjs.js +1 -1
  10. package/dist/internal/resizable-table-styles.cjs.js.map +1 -1
  11. package/dist/internal/resizable-table-styles.esm.js +3 -15
  12. package/dist/nile-accordion/nile-accordian.test.cjs.js +1 -1
  13. package/dist/nile-accordion/nile-accordian.test.esm.js +1 -1
  14. package/dist/nile-auto-complete/index.cjs.js +1 -1
  15. package/dist/nile-auto-complete/index.esm.js +1 -1
  16. package/dist/nile-auto-complete/nile-auto-complete.cjs.js +17 -1
  17. package/dist/nile-auto-complete/nile-auto-complete.cjs.js.map +1 -1
  18. package/dist/nile-auto-complete/nile-auto-complete.esm.js +29 -8
  19. package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js +1 -1
  20. package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js.map +1 -1
  21. package/dist/nile-auto-complete/nile-auto-complete.test.esm.js +1 -1
  22. package/dist/nile-avatar/nile-avatar.test.cjs.js +1 -1
  23. package/dist/nile-avatar/nile-avatar.test.esm.js +1 -1
  24. package/dist/nile-badge/nile-badge.test.cjs.js +1 -1
  25. package/dist/nile-badge/nile-badge.test.esm.js +1 -1
  26. package/dist/nile-button/nile-button.test.cjs.js +1 -1
  27. package/dist/nile-button/nile-button.test.esm.js +1 -1
  28. package/dist/nile-button-toggle-group/nile-button-toggle-group.test.cjs.js +1 -1
  29. package/dist/nile-button-toggle-group/nile-button-toggle-group.test.esm.js +1 -1
  30. package/dist/nile-calendar/nile-calendar.test.cjs.js +1 -1
  31. package/dist/nile-calendar/nile-calendar.test.cjs.js.map +1 -1
  32. package/dist/nile-calendar/nile-calendar.test.esm.js +1 -1
  33. package/dist/nile-card/nile-card.test.cjs.js +1 -1
  34. package/dist/nile-card/nile-card.test.esm.js +1 -1
  35. package/dist/nile-checkbox/nile-checkbox.test.cjs.js +1 -1
  36. package/dist/nile-checkbox/nile-checkbox.test.esm.js +1 -1
  37. package/dist/nile-chip/nile-chip.cjs.js +1 -1
  38. package/dist/nile-chip/nile-chip.cjs.js.map +1 -1
  39. package/dist/nile-chip/nile-chip.esm.js +1 -1
  40. package/dist/nile-chip/nile-chip.test.cjs.js +1 -1
  41. package/dist/nile-chip/nile-chip.test.cjs.js.map +1 -1
  42. package/dist/nile-chip/nile-chip.test.esm.js +1 -1
  43. package/dist/nile-code-editor/extensionSetup.cjs.js +5 -5
  44. package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
  45. package/dist/nile-code-editor/extensionSetup.esm.js +1 -1
  46. package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
  47. package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
  48. package/dist/nile-code-editor/nile-code-editor.esm.js +3 -3
  49. package/dist/nile-code-editor/theme.cjs.js +1 -1
  50. package/dist/nile-code-editor/theme.cjs.js.map +1 -1
  51. package/dist/nile-code-editor/theme.esm.js +1 -1
  52. package/dist/nile-dialog/nile-dialog.test.cjs.js +1 -1
  53. package/dist/nile-dialog/nile-dialog.test.esm.js +1 -1
  54. package/dist/nile-drawer/nile-drawer.test.cjs.js +1 -1
  55. package/dist/nile-drawer/nile-drawer.test.esm.js +1 -1
  56. package/dist/nile-dropdown/nile-dropdown.test.cjs.js +1 -1
  57. package/dist/nile-dropdown/nile-dropdown.test.esm.js +1 -1
  58. package/dist/nile-empty-state/nile-empty-state.test.cjs.js +1 -1
  59. package/dist/nile-empty-state/nile-empty-state.test.esm.js +1 -1
  60. package/dist/nile-error-message/nile-error-message.test.cjs.js +1 -1
  61. package/dist/nile-error-message/nile-error-message.test.esm.js +1 -1
  62. package/dist/nile-filter-chip/nile-filter-chip.test.cjs.js +1 -1
  63. package/dist/nile-filter-chip/nile-filter-chip.test.esm.js +1 -1
  64. package/dist/nile-form-group/nile-form-group.test.cjs.js +1 -1
  65. package/dist/nile-form-group/nile-form-group.test.esm.js +1 -1
  66. package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js +1 -1
  67. package/dist/nile-form-help-text/nile-form-help-text.test.esm.js +1 -1
  68. package/dist/nile-hero/nile-hero.test.cjs.js +1 -1
  69. package/dist/nile-hero/nile-hero.test.esm.js +1 -1
  70. package/dist/nile-icon/nile-icon.test.cjs.js +1 -1
  71. package/dist/nile-icon/nile-icon.test.esm.js +1 -1
  72. package/dist/nile-input/nile-input.test.cjs.js +1 -1
  73. package/dist/nile-input/nile-input.test.esm.js +1 -1
  74. package/dist/nile-link/nile-link.test.cjs.js +1 -1
  75. package/dist/nile-link/nile-link.test.esm.js +1 -1
  76. package/dist/nile-loader/nile-loader.test.cjs.js +1 -1
  77. package/dist/nile-loader/nile-loader.test.esm.js +1 -1
  78. package/dist/nile-option/nile-option.cjs.js +1 -1
  79. package/dist/nile-option/nile-option.cjs.js.map +1 -1
  80. package/dist/nile-option/nile-option.esm.js +3 -3
  81. package/dist/nile-popover/index.cjs.js +1 -1
  82. package/dist/nile-popover/index.esm.js +1 -1
  83. package/dist/nile-popover/nile-popover.cjs.js +11 -3
  84. package/dist/nile-popover/nile-popover.cjs.js.map +1 -1
  85. package/dist/nile-popover/nile-popover.esm.js +13 -7
  86. package/dist/nile-popover/nile-popover.test.cjs.js +1 -1
  87. package/dist/nile-popover/nile-popover.test.cjs.js.map +1 -1
  88. package/dist/nile-popover/nile-popover.test.esm.js +3 -3
  89. package/dist/nile-popup/nile-popup.test.cjs.js +1 -1
  90. package/dist/nile-popup/nile-popup.test.esm.js +1 -1
  91. package/dist/nile-progress-bar/nile-progress-bar.test.cjs.js +1 -1
  92. package/dist/nile-progress-bar/nile-progress-bar.test.esm.js +1 -1
  93. package/dist/nile-radio/nile-radio.test.cjs.js +1 -1
  94. package/dist/nile-radio/nile-radio.test.esm.js +1 -1
  95. package/dist/nile-radio-group/nile-radio-group.test.cjs.js +1 -1
  96. package/dist/nile-radio-group/nile-radio-group.test.esm.js +1 -1
  97. package/dist/nile-select/index.cjs.js +1 -1
  98. package/dist/nile-select/index.esm.js +1 -1
  99. package/dist/nile-select/nile-select.cjs.js +1 -1
  100. package/dist/nile-select/nile-select.cjs.js.map +1 -1
  101. package/dist/nile-select/nile-select.esm.js +9 -9
  102. package/dist/nile-select/nile-select.test.cjs.js +1 -1
  103. package/dist/nile-select/nile-select.test.cjs.js.map +1 -1
  104. package/dist/nile-select/nile-select.test.esm.js +2 -2
  105. package/dist/nile-slide-toggle/nile-slide-toggle.test.cjs.js +1 -1
  106. package/dist/nile-slide-toggle/nile-slide-toggle.test.esm.js +1 -1
  107. package/dist/nile-tab-group/nile-tab-group.test.cjs.js +1 -1
  108. package/dist/nile-tab-group/nile-tab-group.test.esm.js +1 -1
  109. package/dist/nile-table-cell-item/nile-table-cell-item.css.cjs.js +1 -1
  110. package/dist/nile-table-cell-item/nile-table-cell-item.css.cjs.js.map +1 -1
  111. package/dist/nile-table-cell-item/nile-table-cell-item.css.esm.js +6 -2
  112. package/dist/nile-table-header-item/nile-table-header-item.css.cjs.js +1 -1
  113. package/dist/nile-table-header-item/nile-table-header-item.css.cjs.js.map +1 -1
  114. package/dist/nile-table-header-item/nile-table-header-item.css.esm.js +4 -2
  115. package/dist/nile-table-row/nile-table-row.cjs.js +1 -1
  116. package/dist/nile-table-row/nile-table-row.cjs.js.map +1 -1
  117. package/dist/nile-table-row/nile-table-row.css.cjs.js +1 -1
  118. package/dist/nile-table-row/nile-table-row.css.cjs.js.map +1 -1
  119. package/dist/nile-table-row/nile-table-row.css.esm.js +51 -0
  120. package/dist/nile-table-row/nile-table-row.esm.js +26 -6
  121. package/dist/nile-textarea/nile-textarea.test.cjs.js +1 -1
  122. package/dist/nile-textarea/nile-textarea.test.esm.js +1 -1
  123. package/dist/src/index.d.ts +0 -4
  124. package/dist/src/index.js +0 -4
  125. package/dist/src/index.js.map +1 -1
  126. package/dist/src/internal/form.js +3 -3
  127. package/dist/src/internal/form.js.map +1 -1
  128. package/dist/src/internal/resizable-table-styles.js +0 -12
  129. package/dist/src/internal/resizable-table-styles.js.map +1 -1
  130. package/dist/src/nile-chip/nile-chip.js +1 -10
  131. package/dist/src/nile-chip/nile-chip.js.map +1 -1
  132. package/dist/src/nile-code-editor/nile-code-editor.d.ts +0 -3
  133. package/dist/src/nile-code-editor/nile-code-editor.js +3 -23
  134. package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
  135. package/dist/src/nile-code-editor/theme.d.ts +0 -6
  136. package/dist/src/nile-code-editor/theme.js +2 -8
  137. package/dist/src/nile-code-editor/theme.js.map +1 -1
  138. package/dist/src/nile-option/nile-option.d.ts +1 -4
  139. package/dist/src/nile-option/nile-option.js +15 -27
  140. package/dist/src/nile-option/nile-option.js.map +1 -1
  141. package/dist/src/nile-select/nile-select.d.ts +3 -20
  142. package/dist/src/nile-select/nile-select.js +22 -123
  143. package/dist/src/nile-select/nile-select.js.map +1 -1
  144. package/dist/src/nile-table-cell-item/nile-table-cell-item.css.js +4 -0
  145. package/dist/src/nile-table-cell-item/nile-table-cell-item.css.js.map +1 -1
  146. package/dist/src/nile-table-header-item/nile-table-header-item.css.js +2 -0
  147. package/dist/src/nile-table-header-item/nile-table-header-item.css.js.map +1 -1
  148. package/dist/src/nile-table-row/nile-table-row-expandable.d.ts +37 -0
  149. package/dist/src/nile-table-row/nile-table-row-expandable.js +105 -0
  150. package/dist/src/nile-table-row/nile-table-row-expandable.js.map +1 -0
  151. package/dist/src/nile-table-row/nile-table-row.css.js +51 -0
  152. package/dist/src/nile-table-row/nile-table-row.css.js.map +1 -1
  153. package/dist/src/nile-table-row/nile-table-row.d.ts +4 -0
  154. package/dist/src/nile-table-row/nile-table-row.js +58 -11
  155. package/dist/src/nile-table-row/nile-table-row.js.map +1 -1
  156. package/dist/src/nile-table-row-expandable/index.d.ts +1 -0
  157. package/dist/src/nile-table-row-expandable/index.js +2 -0
  158. package/dist/src/nile-table-row-expandable/index.js.map +1 -0
  159. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.css.d.ts +12 -0
  160. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.css.js +17 -0
  161. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.css.js.map +1 -0
  162. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.d.ts +37 -0
  163. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.js +103 -0
  164. package/dist/src/nile-table-row-expandable/nile-table-row-expandable.js.map +1 -0
  165. package/dist/tsconfig.tsbuildinfo +1 -1
  166. package/package.json +3 -4
  167. package/src/index.ts +1 -5
  168. package/src/internal/form.ts +3 -3
  169. package/src/internal/resizable-table-styles.ts +0 -12
  170. package/src/nile-chip/nile-chip.ts +1 -9
  171. package/src/nile-code-editor/nile-code-editor.ts +4 -25
  172. package/src/nile-code-editor/theme.ts +2 -8
  173. package/src/nile-option/nile-option.ts +12 -22
  174. package/src/nile-select/nile-select.ts +15 -139
  175. package/src/nile-table-cell-item/nile-table-cell-item.css.ts +4 -0
  176. package/src/nile-table-header-item/nile-table-header-item.css.ts +2 -0
  177. package/src/nile-table-row/nile-table-row.css.ts +51 -0
  178. package/src/nile-table-row/nile-table-row.ts +50 -7
  179. package/vscode-html-custom-data.json +23 -400
  180. package/src/nile-file-preview/index.ts +0 -1
  181. package/src/nile-file-preview/nile-file-preview.css.ts +0 -589
  182. package/src/nile-file-preview/nile-file-preview.template.ts +0 -259
  183. package/src/nile-file-preview/nile-file-preview.test.ts +0 -38
  184. package/src/nile-file-preview/nile-file-preview.ts +0 -205
  185. package/src/nile-file-preview/types/index.ts +0 -2
  186. package/src/nile-file-preview/types/nile-file-preview.enums.ts +0 -32
  187. package/src/nile-file-preview/types/nile-file-preview.interface.ts +0 -4
  188. package/src/nile-file-preview/utils/index.ts +0 -1
  189. package/src/nile-file-preview/utils/nile-file-preview.util.ts +0 -72
  190. package/src/nile-file-upload/index.ts +0 -1
  191. package/src/nile-file-upload/nile-file-upload.css.ts +0 -624
  192. package/src/nile-file-upload/nile-file-upload.template.ts +0 -217
  193. package/src/nile-file-upload/nile-file-upload.test.ts +0 -38
  194. package/src/nile-file-upload/nile-file-upload.ts +0 -161
  195. package/src/nile-file-upload/types/file-upload.enums.ts +0 -46
  196. package/src/nile-file-upload/types/file-upload.type.ts +0 -5
  197. package/src/nile-file-upload/types/index.ts +0 -2
  198. package/src/nile-file-upload/utils/drag-drop.util.ts +0 -106
  199. package/src/nile-file-upload/utils/file-validation.util.ts +0 -216
  200. package/src/nile-option-group/index.ts +0 -1
  201. package/src/nile-option-group/nile-option-group.css.ts +0 -60
  202. package/src/nile-option-group/nile-option-group.interface.ts +0 -24
  203. package/src/nile-option-group/nile-option-group.ts +0 -84
  204. package/src/nile-select/nile-select.interface.ts +0 -5
  205. package/src/nile-select/virtual-scroll-helper.ts +0 -56
  206. package/src/nile-virtual-select/index.ts +0 -1
  207. package/src/nile-virtual-select/nile-virtual-select.css.ts +0 -491
  208. package/src/nile-virtual-select/nile-virtual-select.test.ts +0 -774
  209. package/src/nile-virtual-select/nile-virtual-select.ts +0 -1314
  210. package/src/nile-virtual-select/renderer.ts +0 -102
  211. package/src/nile-virtual-select/search-manager.ts +0 -50
  212. package/src/nile-virtual-select/selection-manager.ts +0 -75
  213. package/src/nile-virtual-select/types.ts +0 -54
@@ -1,1314 +0,0 @@
1
- /**
2
- * Copyright Aquera Inc 2025
3
- *
4
- * This source code is licensed under the BSD-3-Clause license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {
9
- LitElement,
10
- html,
11
- } from 'lit';
12
- import { customElement, property } from 'lit/decorators.js';
13
- import { styles } from './nile-virtual-select.css';
14
-
15
- import '../nile-icon';
16
- import '../nile-popup/nile-popup';
17
- import '../nile-tag/nile-tag';
18
- import '../nile-checkbox/nile-checkbox';
19
- import { animateTo, stopAnimations } from '../internal/animate';
20
- import { classMap } from 'lit/directives/class-map.js';
21
- import { query, state } from 'lit/decorators.js';
22
- import { defaultValue } from '../internal/default-value';
23
- import { FormControlController } from '../internal/form';
24
- import {
25
- getAnimation,
26
- setDefaultAnimation,
27
- } from '../utilities/animation-registry';
28
- import { HasSlotController } from '../internal/slot';
29
- import { waitForEvent } from '../internal/event';
30
- import { watch } from '../internal/watch';
31
- import NileElement from '../internal/nile-element';
32
- import type { CSSResultGroup, TemplateResult } from 'lit';
33
- import type { NileFormControl } from '../internal/nile-element';
34
- import type NileOption from '../nile-option/nile-option';
35
- import type NilePopup from '../nile-popup/nile-popup';
36
- import { ifDefined } from 'lit/directives/if-defined.js';
37
-
38
- import type { VirtualOption, NileRemoveEvent, RenderItemConfig } from './types.js';
39
- import { VirtualSelectSelectionManager } from './selection-manager.js';
40
- import { VirtualSelectSearchManager } from './search-manager.js';
41
- import { VirtualSelectRenderer } from './renderer.js';
42
-
43
- /**
44
- * Nile Virtual Select component.
45
- *
46
- * @tag nile-virtual-select
47
- *
48
- */
49
-
50
- /**
51
- * @summary Virtual select component for handling large datasets with virtual scrolling.
52
- * @status stable
53
- * @since 2.0
54
- *
55
- * @dependency nile-icon
56
- * @dependency nile-popup
57
- * @dependency nile-tag
58
- * @dependency nile-checkbox
59
- *
60
- * @slot label - The input's label. Alternatively, you can use the `label` attribute.
61
- * @slot prefix - Used to prepend a presentational icon or similar element to the combobox.
62
- * @slot clear-icon - An icon to use in lieu of the default clear icon.
63
- * @slot expand-icon - The icon to show when the control is expanded and collapsed.
64
- * @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute.
65
- *
66
- * @event nile-change - Emitted when the control's value changes.
67
- * @event nile-clear - Emitted when the control's value is cleared.
68
- * @event nile-input - Emitted when the control receives input.
69
- * @event nile-focus - Emitted when the control gains focus.
70
- * @event nile-blur - Emitted when the control loses focus.
71
- * @event nile-show - Emitted when the select's menu opens.
72
- * @event nile-after-show - Emitted after the select's menu opens and all animations are complete.
73
- * @event nile-hide - Emitted when the select's menu closes.
74
- * @event nile-after-hide - Emitted after the select's menu closes and all animations are complete.
75
- * @event nile-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied.
76
- *
77
- * @csspart form-control - The form control that wraps the label, input, and help text.
78
- * @csspart form-control-label - The label's wrapper.
79
- * @csspart form-control-input - The select's wrapper.
80
- * @csspart form-control-help-text - The help text's wrapper.
81
- * @csspart combobox - The container the wraps the prefix, combobox, clear icon, and expand button.
82
- * @csspart prefix - The container that wraps the prefix slot.
83
- * @csspart display-input - The element that displays the selected option's label, an `<input>` element.
84
- * @csspart listbox - The listbox container where options are slotted.
85
- * @csspart tags - The container that houses option tags when `multiple` is used.
86
- * @csspart tag - The individual tags that represent each multiselect option.
87
- * @csspart clear-button - The clear button.
88
- * @csspart expand-icon - The container that wraps the expand icon.
89
- * @csspart footer - The footer container with show selected and clear all options.
90
- */
91
-
92
- @customElement('nile-virtual-select')
93
- export class NileVirtualSelect extends NileElement implements NileFormControl {
94
- static styles: CSSResultGroup = styles;
95
-
96
- private readonly formControlController = new FormControlController(this, {
97
- assumeInteractionOn: ['nile-blur', 'nile-input'],
98
- });
99
- private readonly hasSlotController = new HasSlotController(
100
- this,
101
- 'help-text',
102
- 'label'
103
- );
104
-
105
- @query('.select') popup: NilePopup;
106
- @query('.select__display-input') displayInput: HTMLInputElement;
107
- @query('.select__value-input') valueInput: HTMLInputElement;
108
- @query('.virtualized') virtualizedContainer: HTMLElement;
109
-
110
- @state() private hasFocus = false;
111
- @state() displayLabel = '';
112
- @state() selectedOptions: VirtualOption[] = [];
113
- @state() oldValue: string | string[] = '';
114
-
115
- /** The name of the select, submitted as a name/value pair with form data. */
116
- @property() name = '';
117
-
118
- /** Array of all option items for virtual scrolling */
119
- @property({ type: Array }) data: any = [];
120
-
121
- /** Original unfiltered option items for search functionality */
122
- @state() private originalOptionItems: any = [];
123
-
124
- /**
125
- * The current value of the select. When `multiple` is enabled, the value will be an array of selected values.
126
- */
127
- @property({
128
- converter: {
129
- fromAttribute: (value: string) => value.split(' '),
130
- toAttribute: (value: string[]) => value.join(' '),
131
- },
132
- })
133
- value: string | string[] = '';
134
-
135
- /** The default value of the form control. Primarily used for resetting the form control. */
136
- @defaultValue() defaultValue: string | string[] = '';
137
-
138
- /** The select's size. */
139
- @property() size: 'small' | 'medium' | 'large' = 'medium';
140
-
141
- /** Placeholder text to show as a hint when the select is empty. */
142
- @property() placeholder = 'Select...';
143
-
144
- /** Current search value */
145
- @state() searchValue: string = '';
146
-
147
- /** Enable search functionality */
148
- @property({ type: Boolean, reflect: true }) searchEnabled = false;
149
-
150
- /** Search input placeholder */
151
- @property({attribute:'internal-search-placeholder'}) internalSearchPlaceHolder = 'Search...';
152
-
153
- /** Disable local search filtering */
154
- @property({ type: Boolean, reflect: true }) disableLocalSearch = false;
155
-
156
- /** Show loading state */
157
- @property({ type: Boolean, reflect: true }) optionsLoading = false;
158
-
159
- /** Allows more than one option to be selected. */
160
- @property({ type: Boolean, reflect: true }) multiple = false;
161
-
162
- /** Help text */
163
- @property({ attribute: 'help-text', reflect: true }) helpText = '';
164
-
165
- /** Error message */
166
- @property({ attribute: 'error-message', reflect: true }) errorMessage = '';
167
-
168
- /** Sets the input to a warning state */
169
- @property({ type: Boolean }) warning = false;
170
-
171
- /** Sets the input to an error state */
172
- @property({ type: Boolean }) error = false;
173
-
174
- /** Sets the input to a success state */
175
- @property({ type: Boolean }) success = false;
176
-
177
- /** Disables the select control. */
178
- @property({ type: Boolean, reflect: true }) disabled = false;
179
-
180
- /** Adds a clear button when the select is not empty. */
181
- @property({ type: Boolean, reflect: true }) clearable = false;
182
-
183
- /** The select's open state. */
184
- @property({ type: Boolean, reflect: true }) open = false;
185
-
186
- /**
187
- * Enable this option to prevent the listbox from being clipped when the component is placed inside a container with
188
- * `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios.
189
- */
190
- @property({ type: Boolean }) hoist = false;
191
-
192
- /** Draws a filled select. */
193
- @property({ type: Boolean, reflect: true }) filled = false;
194
-
195
- /** Draws a pill-style select with rounded edges. */
196
- @property({ type: Boolean, reflect: true }) pill = false;
197
-
198
- /** The select's label. If you need to display HTML, use the `label` slot instead. */
199
- @property() label = '';
200
-
201
- /**
202
- * The preferred placement of the select's menu. Note that the actual placement may vary as needed to keep the listbox
203
- * inside of the viewport.
204
- */
205
- @property({ reflect: true }) placement: 'top' | 'bottom' = 'bottom';
206
-
207
- /**
208
- * By default, form controls are associated with the nearest containing `<form>` element. This attribute allows you
209
- * to place the form control outside of a form and associate it with the form that has this `id`. The form must be in
210
- * the same document or shadow root for this to work.
211
- */
212
- @property({ reflect: true }) form = '';
213
-
214
- /** The select's required attribute. */
215
- @property({ type: Boolean, reflect: true }) required = false;
216
-
217
- /** Show no results message */
218
- @property({ type: Boolean }) showNoResults: boolean = false;
219
-
220
- /** No results message */
221
- @property({ type: String }) noResultsMessage: string = 'No results found';
222
-
223
- /** Show selected options only */
224
- @property({ type: Boolean }) showSelected = false;
225
-
226
- /** Enhanced configuration for rendering items with support for display text, value, and search text */
227
- @property({ attribute:false}) renderItemConfig?: RenderItemConfig;
228
-
229
- /** Block value change events */
230
- @property({ type: Boolean, reflect: true }) blockValueChange = false;
231
-
232
- /** Disable width synchronization */
233
- @property({ type: Boolean, reflect: true }) noWidthSync = false;
234
-
235
- /**
236
- * The maximum number of selected options to show when `multiple` is true. After the maximum, "+n" will be shown to
237
- * indicate the number of additional items that are selected. Set to 0 to remove the limit.
238
- */
239
- @property({ attribute: 'max-options-visible', type: Number })
240
- maxOptionsVisible = 3;
241
-
242
- @state() oldMaxOptionsVisible: number = 1;
243
-
244
- /** Gets the validity state object */
245
- get validity() {
246
- return this.valueInput?.validity;
247
- }
248
-
249
- /** Gets the validation message */
250
- get validationMessage() {
251
- return this.valueInput?.validationMessage ?? '';
252
- }
253
-
254
- connectedCallback() {
255
- super.connectedCallback();
256
- this.initializeComponent();
257
- this.setupEventListeners();
258
-
259
- this.updateComplete.then(() => {
260
- if (this.value && this.data.length > 0) {
261
- this.selectionChanged();
262
- }
263
- });
264
- }
265
-
266
- disconnectedCallback() {
267
- this.removeOpenListeners();
268
- }
269
-
270
- private initializeComponent(): void {
271
- this.open = false;
272
- this.emit('nile-init');
273
- }
274
-
275
- /**
276
- * Get display text for an item using renderItemConfig
277
- */
278
- private getDisplayText(item: any): string {
279
- if (this.renderItemConfig?.getDisplayText) {
280
- return this.renderItemConfig.getDisplayText(item);
281
- }
282
- // Fallback to basic display
283
- return item?.label || item?.name || item?.toString() || '';
284
- }
285
-
286
- /**
287
- * Get value for an item using renderItemConfig or fallback to item.value
288
- */
289
- private getItemValue(item: any): string {
290
- if (this.renderItemConfig?.getValue) {
291
- return this.renderItemConfig.getValue(item);
292
- }
293
- return item?.value || item;
294
- }
295
-
296
- /**
297
- * Get search text for an item using renderItemConfig or fallback to display text
298
- */
299
- private getSearchText(item: any): string {
300
- if (this.renderItemConfig?.getSearchText) {
301
- return this.renderItemConfig.getSearchText(item);
302
- }
303
- return this.getDisplayText(item);
304
- }
305
-
306
- private setupEventListeners(): void {
307
- this.handleDocumentFocusIn = this.handleDocumentFocusIn.bind(this);
308
- this.handleDocumentKeyDown = this.handleDocumentKeyDown.bind(this);
309
- this.handleDocumentMouseDown = this.handleDocumentMouseDown.bind(this);
310
- }
311
-
312
- private addOpenListeners(): void {
313
- document.addEventListener('focusin', this.handleDocumentFocusIn);
314
- document.addEventListener('keydown', this.handleDocumentKeyDown);
315
- document.addEventListener('mousedown', this.handleDocumentMouseDown);
316
- }
317
-
318
- private removeOpenListeners(): void {
319
- document.removeEventListener('focusin', this.handleDocumentFocusIn);
320
- document.removeEventListener('keydown', this.handleDocumentKeyDown);
321
- document.removeEventListener('mousedown', this.handleDocumentMouseDown);
322
- }
323
-
324
- private handleFocus(): void {
325
- this.hasFocus = true;
326
- this.emit('nile-focus');
327
- }
328
-
329
- private handleBlur(): void {
330
- this.hasFocus = false;
331
- this.emit('nile-blur');
332
- }
333
-
334
- private handleDocumentFocusIn(event: FocusEvent): void {
335
- if (!this.open) return;
336
- const path = event.composedPath();
337
- const hitSelf = path.includes(this);
338
- const hitPopup = this.popup && path.includes(this.popup);
339
-
340
- if (!hitSelf && !hitPopup) {
341
- this.hide();
342
- }
343
- }
344
-
345
- private handleDocumentKeyDown(event: KeyboardEvent): void {
346
- if (this.shouldIgnoreKeyPress(event)) {
347
- return;
348
- }
349
-
350
- if (this.isEscapeKey(event)) {
351
- this.handleEscapeKey(event);
352
- }
353
-
354
- if (this.isEnterOrSpaceKey(event)) {
355
- this.handleEnterOrSpaceKey(event);
356
- }
357
- }
358
-
359
- private shouldIgnoreKeyPress(event: KeyboardEvent): boolean {
360
- const target = event.target as HTMLElement;
361
- const isClearButton = target.closest('.select__clear') !== null;
362
- const isIconButton = target.closest('nile-icon-button') !== null;
363
- return isClearButton || isIconButton;
364
- }
365
-
366
- private isEscapeKey(event: KeyboardEvent): boolean {
367
- return event.key === 'Escape' && this.open;
368
- }
369
-
370
- private handleEscapeKey(event: KeyboardEvent): void {
371
- event.preventDefault();
372
- event.stopPropagation();
373
- this.hide();
374
- this.displayInput.focus({ preventScroll: true });
375
- }
376
-
377
- private isEnterOrSpaceKey(event: KeyboardEvent): boolean {
378
- return event.key === 'Enter' || event.key === ' ';
379
- }
380
-
381
- private handleEnterOrSpaceKey(event: KeyboardEvent): void {
382
- event.preventDefault();
383
- event.stopImmediatePropagation();
384
-
385
- if (!this.open) {
386
- this.show();
387
- return;
388
- }
389
-
390
- if (!this.multiple) {
391
- this.hide();
392
- this.displayInput.focus({ preventScroll: true });
393
- }
394
- }
395
-
396
- private handleDocumentMouseDown = (event: MouseEvent): void => {
397
- if (!this.open) return;
398
-
399
- const path = event.composedPath();
400
- const hitSelf = path.includes(this);
401
- const hitPopup = this.popup && path.includes(this.popup);
402
-
403
- if (!hitSelf && !hitPopup) {
404
- this.hide();
405
- }
406
- };
407
-
408
- private handleFooterClick(event: MouseEvent): void {
409
- event.stopPropagation();
410
- event.preventDefault();
411
- }
412
-
413
- private toggleShowSelected(event: Event): void {
414
- event.stopPropagation();
415
- event.preventDefault();
416
- if (this.selectedOptions?.length === 0) {
417
- return;
418
- }
419
- this.showSelected = !this.showSelected;
420
-
421
- if (this.showSelected) {
422
- const selectedValues = Array.isArray(this.value) ? this.value : [this.value];
423
- this.data = this.originalOptionItems.filter((item: any) =>
424
- selectedValues.includes(item.value)
425
- );
426
- } else {
427
- this.data = [...this.originalOptionItems];
428
- }
429
-
430
- this.requestUpdate();
431
- this.resetScrollPosition();
432
- }
433
-
434
- private unSelectAll(): void {
435
- this.showSelected = false;
436
- this.value = this.multiple ? [] : '';
437
- this.data = [...this.originalOptionItems];
438
- this.selectionChanged();
439
- this.emit('nile-change', { value: this.value, name: this.name });
440
- this.emit('nile-clear', { value: this.multiple ? this.value : '', name: this.name });
441
- this.resetScrollPosition();
442
- }
443
-
444
- private handleLabelClick(): void {
445
- this.displayInput.focus();
446
- this.hide();
447
- }
448
-
449
- private handleComboboxMouseDown(event: MouseEvent): void {
450
- if (this.shouldIgnoreComboboxClick(event)) {
451
- return;
452
- }
453
-
454
- event.preventDefault();
455
- this.displayInput.focus({ preventScroll: true });
456
- this.open = !this.open;
457
- }
458
-
459
- private shouldIgnoreComboboxClick(event: MouseEvent): boolean {
460
- const path = event.composedPath();
461
- const isIconButton = path.some(
462
- el =>
463
- el instanceof Element && el.tagName.toLowerCase() === 'nile-icon-button'
464
- );
465
- return this.disabled || isIconButton;
466
- }
467
-
468
- private handleComboboxKeyDown(event: KeyboardEvent): void {
469
- if (this.isEnterOrSpaceKey(event)) {
470
- event.preventDefault();
471
- this.open = !this.open;
472
- }
473
- }
474
-
475
- private handleClearClick(event: MouseEvent): void {
476
- event.stopPropagation();
477
- this.clearSelection();
478
- }
479
-
480
- private clearSelection(): void {
481
- const oldValue = this.value;
482
- this.value = this.multiple ? [] : '';
483
- this.selectionChanged();
484
-
485
- this.updateComplete.then(() => {
486
- this.nileInput({ value: this.value, name: this.name });
487
- this.nileChange({ value: this.value, name: this.name });
488
- this.emit('nile-clear');
489
- });
490
- }
491
-
492
- private handleClearMouseDown(event: MouseEvent): void {
493
- event.stopPropagation();
494
- }
495
-
496
- private handleOptionClick(event: MouseEvent): void {
497
- const target = event.target as HTMLElement;
498
- const option = target.closest('nile-option');
499
-
500
- if (this.shouldBlockValueChange(option)) {
501
- return;
502
- }
503
-
504
- const oldValue = this.value;
505
- this.oldValue = oldValue;
506
-
507
- if (option && !option.disabled) {
508
- this.handleOptionSelection(option);
509
- }
510
- }
511
-
512
- private shouldBlockValueChange(option: Element | null): boolean {
513
- if (this.blockValueChange && option) {
514
- this.emit('nile-block-change', { value: (option as any)?.value, name: this.name });
515
- this.hide();
516
- return true;
517
- }
518
- return false;
519
- }
520
-
521
- private handleOptionSelection(option: Element): void {
522
- const optionValue = (option as any).value;
523
-
524
- if (this.multiple) {
525
- this.toggleOptionSelection(optionValue);
526
- } else {
527
- this.setSelectedOptions(optionValue);
528
- }
529
-
530
- this.updateComplete.then(() =>
531
- this.displayInput.focus({ preventScroll: true })
532
- );
533
-
534
- if (this.value !== this.oldValue) {
535
- this.updateComplete.then(() => {
536
- this.nileInput({ value: this.value, name: this.name });
537
- this.nileChange({ value: this.value, name: this.name });
538
- });
539
- }
540
-
541
- if (!this.multiple) {
542
- this.hide();
543
- this.displayInput.focus({ preventScroll: true });
544
- }
545
- }
546
-
547
- private setSelectedOptions(optionValue: string): void {
548
- this.value = optionValue;
549
- this.selectionChanged();
550
- }
551
-
552
- private toggleOptionSelection(optionValue: string): void {
553
- const currentValues = Array.isArray(this.value) ? this.value : [];
554
-
555
- if (currentValues.includes(optionValue)) {
556
- this.value = currentValues.filter(v => v !== optionValue);
557
- } else {
558
- this.value = [...currentValues, optionValue];
559
- }
560
-
561
- this.selectionChanged();
562
- }
563
-
564
- private handleTagRemove(event: NileRemoveEvent, option: VirtualOption): void {
565
- event.stopPropagation();
566
-
567
- if (!this.disabled) {
568
- this.removeTagFromSelection(option);
569
- this.emitTagRemovalEvent(option);
570
- }
571
- }
572
-
573
- private removeTagFromSelection(option: VirtualOption): void {
574
- let currentValue = this.value;
575
- if (!Array.isArray(currentValue)) {
576
- currentValue = currentValue ? [currentValue] : [];
577
- }
578
- const newValue = currentValue.filter((v: string) => v !== option.value);
579
- this.value = newValue;
580
- this.selectionChanged();
581
- }
582
-
583
- private emitTagRemovalEvent(option: VirtualOption): void {
584
- this.updateComplete.then(() => {
585
- this.nileInput({ value: this.value, name: this.name });
586
- this.nileChange({ value: this.value, name: this.name });
587
- this.emit('nile-tag-remove', { value: this.value, name: this.name, removedtagvalue: option.value });
588
- });
589
- }
590
-
591
- private selectionChanged(): void {
592
- const itemsToSearch = this.originalOptionItems.length > 0 ? this.originalOptionItems : this.data;
593
- this.selectedOptions = VirtualSelectSelectionManager.createVirtualOptionsFromValues(
594
- this.value,
595
- itemsToSearch,
596
- this.getDisplayText.bind(this),
597
- this.renderItemConfig?.getValue
598
- );
599
-
600
- if (this.multiple) {
601
- if (this.placeholder && this.value.length === 0) {
602
- this.displayLabel = '';
603
- } else {
604
- this.displayLabel = this.selectedOptions.length + ' selected';
605
- }
606
- } else {
607
- const currentValue = Array.isArray(this.value) ? this.value[0] : this.value;
608
- const label = this.selectedOptions[0]?.getTextLabel();
609
- this.displayLabel = label ? label : currentValue ?? '';
610
- }
611
-
612
- this.updateValidity();
613
-
614
- if (this.selectedOptions.length === 0) {
615
- this.showSelected = false;
616
- }
617
-
618
- this.calculateTotalWidthOfTags();
619
- }
620
-
621
- handleSearchFocus(): void {
622
- document.removeEventListener('keydown', this.handleDocumentKeyDown);
623
- }
624
-
625
- handleSearchBlur(): void {
626
- document.addEventListener('keydown', this.handleDocumentKeyDown);
627
- }
628
-
629
- handleSearchChange(e: any): void {
630
- this.searchValue = e.detail.value;
631
- if (!this.disableLocalSearch) {
632
- this.filterVirtualOptions(this.searchValue);
633
- this.resetScrollPosition();
634
- }
635
- }
636
-
637
- filterVirtualOptions(searchValue: string): void {
638
- const result = VirtualSelectSearchManager.filterVirtualOptions(
639
- searchValue,
640
- this.originalOptionItems,
641
- this.data,
642
- this.getDisplayText.bind(this),
643
- this.renderItemConfig?.getSearchText
644
- );
645
-
646
- this.data = result.filteredItems;
647
- this.showNoResults = result.showNoResults;
648
- this.showSelected = false;
649
- this.requestUpdate();
650
- }
651
-
652
- private handleInvalid(event: Event): void {
653
- this.formControlController.setValidity(false);
654
- this.formControlController.emitInvalidEvent(event);
655
- }
656
-
657
- @watch('disabled', { waitUntilFirstUpdate: true })
658
- handleDisabledChange(): void {
659
- if (this.disabled) {
660
- this.open = false;
661
- this.handleOpenChange();
662
- }
663
- }
664
-
665
- @watch('value', { waitUntilFirstUpdate: true })
666
- handleValueChange(): void {
667
- this.selectionChanged();
668
- this.requestUpdate();
669
- }
670
-
671
- @watch('data', { waitUntilFirstUpdate: true })
672
- handleDataChange(): void {
673
- this.selectionChanged();
674
- // Show no results message when data is empty and not loading
675
- if (!this.optionsLoading && this.data.length === 0) {
676
- this.showNoResults = true;
677
- } else if (this.data.length > 0) {
678
- this.showNoResults = false;
679
- }
680
- this.requestUpdate();
681
-
682
- if (this.open) {
683
- this.resetScrollPosition();
684
- }
685
- }
686
-
687
- @watch('renderItemConfig', { waitUntilFirstUpdate: true })
688
- handleRenderItemConfigChange(): void {
689
- if (this.value && this.data.length > 0) {
690
- this.selectionChanged();
691
- this.requestUpdate();
692
- }
693
- }
694
-
695
- @watch('optionsLoading', { waitUntilFirstUpdate: true })
696
- handleOptionsLoadingChange(): void {
697
- // Show no results message when loading stops and there are no results
698
- if (!this.optionsLoading && this.data.length === 0) {
699
- this.showNoResults = true;
700
- }
701
- this.requestUpdate();
702
- }
703
-
704
- @watch('open', { waitUntilFirstUpdate: true })
705
- async handleOpenChange(): Promise<void> {
706
- if (this.open && !this.disabled) {
707
- await this.handleOpen();
708
- } else {
709
- await this.handleClose();
710
- }
711
- }
712
-
713
- private async handleOpen(): Promise<void> {
714
- this.emit('nile-show', { value: this.value, name: this.name });
715
- this.addOpenListeners();
716
- this.showNoResults = !this.data?.length;
717
-
718
- await stopAnimations(this);
719
- this.popup.active = true;
720
-
721
- const { keyframes, options } = getAnimation(this, 'select.show', {
722
- dir: 'ltr',
723
- });
724
- await animateTo(this.popup.popup, keyframes, options);
725
-
726
- this.initializeOriginalItems();
727
- this.filterVirtualOptions(this.searchValue);
728
- this.resetScrollPosition();
729
- this.emit('nile-after-show', { value: this.value, name: this.name });
730
- }
731
-
732
- private async handleClose(): Promise<void> {
733
- this.emit('nile-hide', { value: this.value, name: this.name });
734
- this.removeOpenListeners();
735
-
736
- await stopAnimations(this);
737
- const { keyframes, options } = getAnimation(this, 'select.hide', {
738
- dir: 'ltr',
739
- });
740
- await animateTo(this.popup.popup, keyframes, options);
741
- this.popup.active = false;
742
-
743
- this.searchValue = '';
744
- this.emit('nile-after-hide', { value: this.value, name: this.name });
745
- }
746
-
747
- private initializeOriginalItems(): void {
748
- if (this.originalOptionItems.length === 0 && this.data.length > 0) {
749
- this.originalOptionItems = [...this.data];
750
- }
751
- }
752
-
753
- async show(): Promise<unknown> {
754
- if (this.open || this.disabled) {
755
- this.open = false;
756
- return undefined;
757
- }
758
-
759
- this.open = true;
760
- return waitForEvent(this, 'nile-after-show');
761
- }
762
-
763
- async hide(): Promise<unknown> {
764
- if (!this.open || this.disabled) {
765
- this.open = false;
766
- return undefined;
767
- }
768
-
769
- this.open = false;
770
- return waitForEvent(this, 'nile-after-hide');
771
- }
772
-
773
- checkValidity(): boolean {
774
- return this.valueInput.checkValidity();
775
- }
776
-
777
- getForm(): HTMLFormElement | null {
778
- return this.formControlController.getForm();
779
- }
780
-
781
- reportValidity(): boolean {
782
- return this.valueInput.reportValidity();
783
- }
784
-
785
- setCustomValidity(message: string): void {
786
- this.valueInput.setCustomValidity(message);
787
- this.formControlController.updateValidity();
788
- }
789
-
790
- focus(options?: FocusOptions): void {
791
- this.displayInput.focus(options);
792
- }
793
-
794
- blur(): void {
795
- this.displayInput.blur();
796
- }
797
-
798
- onInputChange(event: Event): void {
799
- event.stopPropagation();
800
- }
801
-
802
- render(): TemplateResult {
803
- const hasLabelSlot = this.hasSlotController.test('label');
804
- const hasHelpTextSlot = this.hasSlotController.test('help-text');
805
- const hasLabelSuffixSlot = this.hasSlotController.test('label-suffix');
806
- const hasCustomSelect = this.hasSlotController.test('custom-select');
807
- const hasLabel = this.label ? true : !!hasLabelSlot;
808
- const hasClearIcon =
809
- this.clearable && !this.disabled && this.value.length > 0;
810
- const isPlaceholderVisible = !!this.placeholder && this.value.length === 0;
811
- const hasHelpText = !!this.helpText;
812
- const hasErrorMessage = !!this.errorMessage;
813
-
814
- return html`
815
- <div
816
- part="form-control"
817
- class=${classMap({
818
- 'form-control': true,
819
- 'form-control--small': this.size === 'small',
820
- 'form-control--medium': this.size === 'medium',
821
- 'form-control--large': this.size === 'large',
822
- 'form-control--has-label': hasLabel,
823
- 'form-control--has-help-text': hasHelpText,
824
- })}
825
- >
826
- ${this.renderLabel(hasLabel, hasLabelSuffixSlot)}
827
- ${this.renderFormControlInput(hasCustomSelect, hasClearIcon, isPlaceholderVisible, hasHelpText, hasErrorMessage)}
828
- </div>
829
- `;
830
- }
831
-
832
- private renderLabel(hasLabel: boolean, hasLabelSuffixSlot: boolean): TemplateResult {
833
- return html`
834
- <label
835
- id="label"
836
- part="form-control-label"
837
- class="form-control__label"
838
- aria-hidden=${hasLabel ? 'false' : 'true'}
839
- @click=${this.handleLabelClick}
840
- >
841
- <slot name="label">${this.label}</slot>
842
- </label>
843
-
844
- ${hasLabelSuffixSlot ? html` <slot name="label-suffix"></slot> ` : ``}
845
- `;
846
- }
847
-
848
- private renderFormControlInput(
849
- hasCustomSelect: boolean,
850
- hasClearIcon: boolean,
851
- isPlaceholderVisible: boolean,
852
- hasHelpText: boolean,
853
- hasErrorMessage: boolean
854
- ): TemplateResult {
855
- return html`
856
- <div part="form-control-input" class="form-control-input">
857
- ${this.renderPopup(hasCustomSelect, hasClearIcon, isPlaceholderVisible)}
858
- ${this.renderHelpText(hasHelpText, hasErrorMessage)}
859
- </div>
860
- `;
861
- }
862
-
863
- private renderPopup(hasCustomSelect: boolean, hasClearIcon: boolean, isPlaceholderVisible: boolean): TemplateResult {
864
- return html`
865
- <nile-popup
866
- class=${classMap({
867
- select: true,
868
- 'select--warning': this.warning,
869
- 'select--error': this.error,
870
- 'select--success': this.success,
871
- 'select--standard': true,
872
- 'select--filled': this.filled,
873
- 'select--pill': this.pill,
874
- 'select--open': this.open,
875
- 'select--disabled': this.disabled,
876
- 'select--multiple': this.multiple,
877
- 'select--focused': this.hasFocus,
878
- 'select--placeholder-visible': isPlaceholderVisible,
879
- 'select--top': this.placement === 'top',
880
- 'select--bottom': this.placement === 'bottom',
881
- 'select--small': this.size === 'small',
882
- 'select--medium': this.size === 'medium',
883
- 'select--large': this.size === 'large',
884
- })}
885
- placement=${this.placement}
886
- strategy=${this.hoist ? 'fixed' : 'absolute'}
887
- distance="6"
888
- flip
889
- shift
890
- sync=${ifDefined(!this.noWidthSync ? 'width' : undefined)}
891
- auto-size="vertical"
892
- auto-size-padding="10"
893
- >
894
- ${this.renderCustomSelect(hasCustomSelect)}
895
- ${this.renderCombobox(hasCustomSelect, hasClearIcon)}
896
- ${this.renderListbox()}
897
- </nile-popup>
898
- `;
899
- }
900
-
901
- private renderCustomSelect(hasCustomSelect: boolean): TemplateResult {
902
- return hasCustomSelect
903
- ? html`<slot
904
- slot="anchor"
905
- name="custom-select"
906
- class="custom-select"
907
- @keydown=${this.handleComboboxKeyDown}
908
- @mousedown=${this.handleComboboxMouseDown}
909
- ></slot>`
910
- : html``;
911
- }
912
-
913
- private renderCombobox(hasCustomSelect: boolean, hasClearIcon: boolean): TemplateResult {
914
- return html`
915
- <div
916
- part="combobox"
917
- class=${classMap({
918
- select__combobox: true,
919
- 'select__hide-default': hasCustomSelect,
920
- })}
921
- slot="anchor"
922
- @keydown=${this.handleComboboxKeyDown}
923
- @mousedown=${this.handleComboboxMouseDown}
924
- >
925
- ${this.renderPrefix()}
926
- ${this.renderDisplayInput()}
927
- ${this.renderTags()}
928
- ${this.renderValueInput()}
929
- ${this.renderClearButton(hasClearIcon)}
930
- ${this.renderSuffix()}
931
- ${this.renderExpandIcon()}
932
- </div>
933
- `;
934
- }
935
-
936
- private renderPrefix(): TemplateResult {
937
- return html`
938
- <slot
939
- part="prefix"
940
- name="prefix"
941
- class=${classMap({
942
- select__prefix: true,
943
- multiple: this.multiple,
944
- })}
945
- ></slot>
946
- `;
947
- }
948
-
949
- private renderDisplayInput(): TemplateResult {
950
- return html`
951
- <input
952
- part="display-input"
953
- class="select__display-input"
954
- type="text"
955
- placeholder=${this.placeholder}
956
- .disabled=${this.disabled}
957
- .value=${this.displayLabel}
958
- autocomplete="off"
959
- spellcheck="false"
960
- autocapitalize="off"
961
- readonly
962
- aria-controls="listbox"
963
- aria-expanded=${this.open ? 'true' : 'false'}
964
- aria-haspopup="listbox"
965
- aria-labelledby="label"
966
- aria-disabled=${this.disabled ? 'true' : 'false'}
967
- aria-describedby="help-text"
968
- role="combobox"
969
- tabindex="0"
970
- />
971
- `;
972
- }
973
-
974
- private renderTags(): TemplateResult {
975
- return this.multiple
976
- ? html`
977
- <div part="tags" class="select__tags">
978
- ${this.selectedOptions.map((option, index) => {
979
- if (
980
- index < this.maxOptionsVisible ||
981
- this.maxOptionsVisible <= 0
982
- ) {
983
- const classes = {
984
- select__invisible:
985
- index + 1 > this.oldMaxOptionsVisible &&
986
- this.maxOptionsVisible === Infinity,
987
- };
988
- return html`
989
- <nile-tag
990
- class=${classMap(classes)}
991
- part="tag"
992
- exportparts="
993
- base:tag__base,
994
- content:tag__content,
995
- remove-button:tag__remove-button,
996
- remove-button__base:tag__remove-button__base
997
- "
998
- ?pill=${this.pill}
999
- size=${this.size}
1000
- removable
1001
- @nile-remove=${(event: NileRemoveEvent) =>
1002
- this.handleTagRemove(event, option)}
1003
- >
1004
- ${option.getTextLabel()}
1005
- </nile-tag>
1006
- `;
1007
- } else if (index === this.maxOptionsVisible) {
1008
- return html`
1009
- <span class="select__tags-count"
1010
- >+${this.selectedOptions.length - index} More
1011
- </span>
1012
- `;
1013
- } else {
1014
- return null;
1015
- }
1016
- })}
1017
- </div>
1018
- `
1019
- : html``;
1020
- }
1021
-
1022
- private renderValueInput(): TemplateResult {
1023
- return html`
1024
- <input
1025
- class="select__value-input"
1026
- type="text"
1027
- ?disabled=${this.disabled}
1028
- ?required=${this.required}
1029
- .value=${Array.isArray(this.value)
1030
- ? this.value.join(', ')
1031
- : this.value}
1032
- tabindex="-1"
1033
- aria-hidden="true"
1034
- @focus=${() => this.focus()}
1035
- @invalid=${this.handleInvalid}
1036
- />
1037
- `;
1038
- }
1039
-
1040
- private renderClearButton(hasClearIcon: boolean): TemplateResult {
1041
- return hasClearIcon
1042
- ? html`
1043
- <button
1044
- part="clear-button"
1045
- class="select__clear"
1046
- type="button"
1047
- aria-label="clearEntry"
1048
- @mousedown=${this.handleClearMouseDown}
1049
- @click=${this.handleClearClick}
1050
- tabindex="-1"
1051
- >
1052
- <slot name="clear-icon">
1053
- <nile-icon name="close" library="system"></nile-icon>
1054
- </slot>
1055
- </button>
1056
- `
1057
- : html``;
1058
- }
1059
-
1060
- private renderSuffix(): TemplateResult {
1061
- return html`
1062
- <slot
1063
- part="suffix"
1064
- name="suffix"
1065
- class=${classMap({
1066
- select__suffix: true,
1067
- })}
1068
- ></slot>
1069
- `;
1070
- }
1071
-
1072
- private renderExpandIcon(): TemplateResult {
1073
- return html`
1074
- <slot
1075
- name="expand-icon"
1076
- part="expand-icon"
1077
- class="select__expand-icon"
1078
- >
1079
- <nile-icon library="system" name="arrowdown"></nile-icon>
1080
- </slot>
1081
- `;
1082
- }
1083
-
1084
- private renderListbox(): TemplateResult {
1085
- return html`
1086
- <div
1087
- id="listbox"
1088
- role="listbox"
1089
- aria-expanded=${this.open ? 'true' : 'false'}
1090
- aria-multiselectable=${this.multiple ? 'true' : 'false'}
1091
- aria-labelledby="label"
1092
- part="listbox"
1093
- class="select__listbox ${this.searchEnabled
1094
- ? 'select__search-enabled '
1095
- : ''}"
1096
- tabindex="-1"
1097
- @mouseup=${this.handleOptionClick}
1098
- >
1099
- ${this.renderSearch()}
1100
- ${this.renderLoader()}
1101
- ${this.getVirtualizedContent()}
1102
- ${this.renderFooter()}
1103
- </div>
1104
- `;
1105
- }
1106
-
1107
- private renderSearch(): TemplateResult {
1108
- return this.searchEnabled
1109
- ? html`
1110
- <div class="select__search">
1111
- <nile-input
1112
- size="small"
1113
- clearable
1114
- .value=${this.searchValue}
1115
- placeholder="${this.internalSearchPlaceHolder}"
1116
- @nile-input=${this.handleSearchChange}
1117
- @nile-focus=${this.handleSearchFocus}
1118
- @nile-change="${this.onInputChange}"
1119
- >
1120
- <nile-icon name="search" slot="suffix"> </nile-icon>
1121
- </nile-input>
1122
- </div>
1123
- `
1124
- : html``;
1125
- }
1126
-
1127
- private renderLoader(): TemplateResult {
1128
- return this.optionsLoading
1129
- ? html`
1130
- <span class="select__loader">
1131
- <nile-icon
1132
- class="select__loader--icon"
1133
- name="button-loading-blue"
1134
- ></nile-icon>
1135
- </span>
1136
- `
1137
- : html``;
1138
- }
1139
-
1140
- private renderFooter(): TemplateResult {
1141
- return this.multiple
1142
- ? html`
1143
- <div
1144
- part="footer"
1145
- class="select__footer"
1146
- @click="${this.handleFooterClick}"
1147
- >
1148
- <span
1149
- @click="${this.toggleShowSelected}"
1150
- style="cursor: pointer;"
1151
- >
1152
- <nile-checkbox
1153
- ?disabled="${this.selectedOptions.length === 0}"
1154
- ?checked="${this.showSelected}"
1155
- >
1156
- &nbsp; Show Selected</nile-checkbox
1157
- >
1158
- </span>
1159
- ${this.selectedOptions.length !== 0
1160
- ? html`
1161
- <span
1162
- class="select__clear"
1163
- @click="${this.unSelectAll}"
1164
- >
1165
- Clear All
1166
- </span>
1167
- `
1168
- : ``}
1169
- </div>
1170
- `
1171
- : html``;
1172
- }
1173
-
1174
- private renderHelpText(hasHelpText: boolean, hasErrorMessage: boolean): TemplateResult {
1175
- return html`
1176
- ${hasHelpText
1177
- ? html` <nile-form-help-text>${this.helpText}</nile-form-help-text> `
1178
- : ``}
1179
- ${hasErrorMessage
1180
- ? html`
1181
- <nile-form-error-message
1182
- >${this.errorMessage}</nile-form-error-message
1183
- >
1184
- `
1185
- : ``}
1186
- `;
1187
- }
1188
-
1189
- getVirtualizedContent(): TemplateResult {
1190
- return VirtualSelectRenderer.getVirtualizedContent(
1191
- this.data,
1192
- this.searchEnabled,
1193
- this.getDisplayText.bind(this),
1194
- this.value,
1195
- this.multiple,
1196
- this.renderItemConfig?.getDisplayText,
1197
- this.renderItemConfig?.getValue,
1198
- this.showNoResults,
1199
- this.noResultsMessage,
1200
- this.optionsLoading
1201
- );
1202
- }
1203
-
1204
- nileInput(value: any): void {
1205
- this.emit('nile-input', value);
1206
- }
1207
-
1208
- nileChange(value: any): void {
1209
- this.emit('nile-change', value);
1210
- }
1211
-
1212
- private updateValidity(): void {
1213
- this.updateComplete.then(() => {
1214
- this.formControlController.updateValidity();
1215
- });
1216
- }
1217
-
1218
- private calculateWidthOfSelectTagsDiv(): number | null {
1219
- if (this.shadowRoot) {
1220
- const selectTagsDiv = this.shadowRoot.querySelector('.select__tags') as HTMLElement;
1221
- if (selectTagsDiv) {
1222
- const width = selectTagsDiv.offsetWidth;
1223
- return width - 70;
1224
- }
1225
- }
1226
- return null;
1227
- }
1228
-
1229
- private calculateTotalWidthOfTags(): void {
1230
- if (this.maxOptionsVisible !== Infinity) {
1231
- this.oldMaxOptionsVisible = this.maxOptionsVisible;
1232
- }
1233
-
1234
- this.maxOptionsVisible = Infinity;
1235
- setTimeout(() => {
1236
- let widths: number[] = [];
1237
- if (this.shadowRoot) {
1238
- const tags = this.shadowRoot.querySelectorAll('nile-tag');
1239
- tags.forEach(tag => {
1240
- if (tag instanceof HTMLElement) {
1241
- widths.push(tag.offsetWidth);
1242
- }
1243
- });
1244
- }
1245
- if (this.value.length !== widths.length) {
1246
- return;
1247
- }
1248
-
1249
- let sum = widths.reduce(
1250
- (accumulator, currentValue) => accumulator + currentValue,
1251
- 0
1252
- );
1253
- const widthOfSelectTagsDiv = this.calculateWidthOfSelectTagsDiv();
1254
- if (!widthOfSelectTagsDiv) {
1255
- return;
1256
- }
1257
-
1258
- let summ = 0;
1259
- let lastindex = 0;
1260
-
1261
- for (let i = 0; i < widths.length; i++) {
1262
- summ += widths[i];
1263
-
1264
- if (summ > widthOfSelectTagsDiv) {
1265
- lastindex = i;
1266
- break;
1267
- }
1268
- }
1269
- this.maxOptionsVisible = lastindex;
1270
- }, 1);
1271
- }
1272
-
1273
- private resetScrollPosition(): void {
1274
- this.updateComplete.then(() => {
1275
- if (this.virtualizedContainer) {
1276
- this.virtualizedContainer.scrollTop = 0;
1277
-
1278
- const listbox = this.shadowRoot?.querySelector('.select__listbox') as HTMLElement;
1279
- if (listbox) {
1280
- listbox.scrollTop = 0;
1281
- }
1282
-
1283
- const virtualizer = this.virtualizedContainer.querySelector('lit-virtualizer') as HTMLElement;
1284
- if (virtualizer) {
1285
- virtualizer.scrollTop = 0;
1286
- }
1287
- }
1288
- });
1289
- }
1290
- }
1291
-
1292
- setDefaultAnimation('select.show', {
1293
- keyframes: [
1294
- { opacity: 0, scale: 0.9 },
1295
- { opacity: 1, scale: 1 },
1296
- ],
1297
- options: { duration: 100, easing: 'ease' },
1298
- });
1299
-
1300
- setDefaultAnimation('select.hide', {
1301
- keyframes: [
1302
- { opacity: 1, scale: 1 },
1303
- { opacity: 0, scale: 0.9 },
1304
- ],
1305
- options: { duration: 100, easing: 'ease' },
1306
- });
1307
-
1308
- export default NileVirtualSelect;
1309
-
1310
- declare global {
1311
- interface HTMLElementTagNameMap {
1312
- 'nile-virtual-select': NileVirtualSelect;
1313
- }
1314
- }