frontile 0.18.0-alpha.13 → 0.18.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/components/buttons/chip.d.ts +35 -4
- package/declarations/components/collections/dropdown.d.ts +18 -0
- package/declarations/components/collections/listbox/item.d.ts +13 -0
- package/declarations/components/collections/listbox/listbox.d.ts +15 -6
- package/declarations/components/forms/autocomplete.d.ts +13 -5
- package/declarations/components/forms/checkbox-group.d.ts +20 -0
- package/declarations/components/forms/checkbox.d.ts +22 -0
- package/declarations/components/forms/form-control.d.ts +49 -0
- package/declarations/components/forms/form-description.d.ts +12 -0
- package/declarations/components/forms/form-feedback.d.ts +21 -0
- package/declarations/components/forms/form.d.ts +1 -1
- package/declarations/components/forms/input.d.ts +44 -1
- package/declarations/components/forms/label.d.ts +13 -0
- package/declarations/components/forms/native-select.d.ts +103 -6
- package/declarations/components/forms/radio-group.d.ts +21 -0
- package/declarations/components/forms/radio.d.ts +27 -0
- package/declarations/components/forms/select/end-content.d.ts +31 -0
- package/declarations/components/forms/select/native-mirror.d.ts +44 -0
- package/declarations/components/forms/select/select.d.ts +425 -0
- package/declarations/components/forms/select/selected-items.d.ts +80 -0
- package/declarations/components/forms/select/trigger.d.ts +76 -0
- package/declarations/components/forms/select/types.d.ts +411 -0
- package/declarations/components/forms/select.d.ts +2 -531
- package/declarations/components/forms/textarea.d.ts +35 -0
- package/declarations/components/overlays/drawer.d.ts +3 -0
- package/declarations/components/overlays/modal.d.ts +3 -0
- package/declarations/components/overlays/overlay.d.ts +23 -0
- package/declarations/components/overlays/popover.d.ts +62 -0
- package/declarations/components/overlays/portal-target.d.ts +5 -1
- package/declarations/components/status/progress-bar.d.ts +5 -0
- package/declarations/components/utilities/divider.d.ts +14 -0
- package/declarations/components/utilities/spinner.d.ts +8 -0
- package/declarations/utils/listManager.d.ts +30 -5
- package/dist/components/buttons/chip.js +1 -1
- package/dist/components/buttons/chip.js.map +1 -1
- package/dist/components/collections/dropdown.js +13 -1
- package/dist/components/collections/dropdown.js.map +1 -1
- package/dist/components/collections/listbox/item.js +13 -1
- package/dist/components/collections/listbox/item.js.map +1 -1
- package/dist/components/collections/listbox/listbox.js +12 -1
- package/dist/components/collections/listbox/listbox.js.map +1 -1
- package/dist/components/collections/simple-table/column.js +1 -1
- package/dist/components/collections/simple-table/column.js.map +1 -1
- package/dist/components/forms/autocomplete.js +0 -3
- package/dist/components/forms/autocomplete.js.map +1 -1
- package/dist/components/forms/checkbox-group.js.map +1 -1
- package/dist/components/forms/checkbox.js.map +1 -1
- package/dist/components/forms/field.js +1 -1
- package/dist/components/forms/form-control.js +1 -1
- package/dist/components/forms/form-control.js.map +1 -1
- package/dist/components/forms/form-description.js.map +1 -1
- package/dist/components/forms/form-feedback.js.map +1 -1
- package/dist/components/forms/index.js +1 -1
- package/dist/components/forms/input.js +32 -1
- package/dist/components/forms/input.js.map +1 -1
- package/dist/components/forms/label.js.map +1 -1
- package/dist/components/forms/native-select.js +2 -2
- package/dist/components/forms/native-select.js.map +1 -1
- package/dist/components/forms/radio-group.js.map +1 -1
- package/dist/components/forms/radio.js.map +1 -1
- package/dist/components/forms/select/end-content.js +24 -0
- package/dist/components/forms/select/end-content.js.map +1 -0
- package/dist/components/forms/select/native-mirror.js +29 -0
- package/dist/components/forms/select/native-mirror.js.map +1 -0
- package/dist/components/forms/select/select.js +599 -0
- package/dist/components/forms/select/select.js.map +1 -0
- package/dist/components/forms/select/selected-items.js +63 -0
- package/dist/components/forms/select/selected-items.js.map +1 -0
- package/dist/components/forms/select/trigger.js +30 -0
- package/dist/components/forms/select/trigger.js.map +1 -0
- package/dist/components/forms/select/types.js +2 -0
- package/dist/components/forms/select/types.js.map +1 -0
- package/dist/components/forms/select.js +1 -387
- package/dist/components/forms/select.js.map +1 -1
- package/dist/components/forms/textarea.js.map +1 -1
- package/dist/components/overlays/drawer.js.map +1 -1
- package/dist/components/overlays/modal.js.map +1 -1
- package/dist/components/overlays/overlay.js.map +1 -1
- package/dist/components/overlays/popover.js +53 -2
- package/dist/components/overlays/popover.js.map +1 -1
- package/dist/components/overlays/portal-target.js.map +1 -1
- package/dist/components/status/progress-bar.js +8 -1
- package/dist/components/status/progress-bar.js.map +1 -1
- package/dist/components/utilities/avatar.js +1 -1
- package/dist/components/utilities/avatar.js.map +1 -1
- package/dist/components/utilities/divider.js +8 -2
- package/dist/components/utilities/divider.js.map +1 -1
- package/dist/components/utilities/spinner.js +1 -1
- package/dist/components/utilities/spinner.js.map +1 -1
- package/dist/forms.js +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/listManager.js +63 -4
- package/dist/utils/listManager.js.map +1 -1
- package/dist/utils/nested-data.js +10 -1
- package/dist/utils/nested-data.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { on } from '@ember/modifier';
|
|
4
|
+
import { action } from '@ember/object';
|
|
5
|
+
import { later } from '@ember/runloop';
|
|
6
|
+
import { modifier } from 'ember-modifier';
|
|
7
|
+
import { useStyles } from '@frontile/theme';
|
|
8
|
+
import { Listbox } from '../../collections/listbox/listbox.js';
|
|
9
|
+
import { VisuallyHidden } from '../../utilities/visually-hidden.js';
|
|
10
|
+
import { Popover } from '../../overlays/popover.js';
|
|
11
|
+
import { FormControl } from '../form-control.js';
|
|
12
|
+
import { ref } from '../../../utils/ref.js';
|
|
13
|
+
import { triggerFormInputEvent } from '../../../utils/forms-utils-index.js';
|
|
14
|
+
import { canDeselectKey, defaultFilter, keyAndLabelForItem } from '../../../utils/listManager.js';
|
|
15
|
+
import { SelectNativeMirror } from './native-mirror.js';
|
|
16
|
+
import { SelectTrigger } from './trigger.js';
|
|
17
|
+
import { SelectedChips } from './selected-items.js';
|
|
18
|
+
import { SelectEndContent } from './end-content.js';
|
|
19
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
20
|
+
import { setComponentTemplate } from '@ember/component';
|
|
21
|
+
import { d as decorateFieldV2, i as initializeDeferredDecorator, a as decorateMethodV2 } from '../../../runtime--fcdnjmJ-BOdRhmsS.js';
|
|
22
|
+
|
|
23
|
+
const and = (a, b) => Boolean(a) && Boolean(b);
|
|
24
|
+
/*
|
|
25
|
+
* Internal: selection state architecture
|
|
26
|
+
*
|
|
27
|
+
* This component uses a **two-way data binding pattern** for managing selection state:
|
|
28
|
+
*
|
|
29
|
+
* ### Data Flow
|
|
30
|
+
* 1. **External → Internal (Initialization & Updates)**
|
|
31
|
+
* - Parent passes `@selectedKey` or `@selectedKeys` as arguments
|
|
32
|
+
* - Constructor initializes internal tracked properties (`_selectedKey` or `_selectedKeys`)
|
|
33
|
+
* - Modifiers (`updateSingleSelectValue`, `updateMultipleSelectValue`) sync internal state
|
|
34
|
+
* when parent updates the arguments
|
|
35
|
+
*
|
|
36
|
+
* 2. **Internal State Management**
|
|
37
|
+
* - `_selectedKey` / `_selectedKeys`: Internal tracked state (prefixed with underscore)
|
|
38
|
+
* - These serve as the "source of truth" for rendering and reactivity
|
|
39
|
+
* - Getters (`getSelectedKey`, `selectedKeys`) expose this internal state to the template
|
|
40
|
+
*
|
|
41
|
+
* 3. **Internal → External (User Interactions)**
|
|
42
|
+
* - User interactions trigger selection change handlers
|
|
43
|
+
* - Handlers update internal `_selectedKey` / `_selectedKeys` for immediate UI update
|
|
44
|
+
* - Handlers call parent's `@onSelectionChange` callback to notify of state change
|
|
45
|
+
* - Parent updates its state, which flows back through step 1
|
|
46
|
+
*
|
|
47
|
+
* ### Why Both Internal State AND Callbacks?
|
|
48
|
+
* - **Internal state:** Enables immediate, responsive UI updates (`_selectedKey` / `_selectedKeys`)
|
|
49
|
+
* - **Parent callback:** Enables parent to take action when changes occur (`@onSelectionChange`)
|
|
50
|
+
* - This pattern provides both responsive UX and parent inclusion over state
|
|
51
|
+
*
|
|
52
|
+
* ### Example Flow
|
|
53
|
+
* ```
|
|
54
|
+
* User clicks item
|
|
55
|
+
* → onSelectionChange handler
|
|
56
|
+
* → Updates _selectedKey (immediate UI update)
|
|
57
|
+
* → Calls parent's @onSelectionChange callback
|
|
58
|
+
* → Parent updates its @selectedKey state
|
|
59
|
+
* → updateSingleSelectValue modifier syncs _selectedKey with new arg value
|
|
60
|
+
* ```
|
|
61
|
+
*/ /**
|
|
62
|
+
* A dropdown selection component: a custom listbox in a popover, backed by a
|
|
63
|
+
* visually hidden native `<select>` so the value submits with a form.
|
|
64
|
+
*
|
|
65
|
+
* Selection can be controlled with `@selectedKey` / `@selectedKeys` plus
|
|
66
|
+
* `@onSelectionChange`, or left uncontrolled.
|
|
67
|
+
*/
|
|
68
|
+
class Select extends Component {
|
|
69
|
+
static {
|
|
70
|
+
decorateFieldV2(this.prototype, "nodes", [tracked], function () {
|
|
71
|
+
return [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
#nodes = (initializeDeferredDecorator(this, "nodes"), void 0);
|
|
75
|
+
/**
|
|
76
|
+
* Every item registered by the hidden native `<select>`, in item order.
|
|
77
|
+
*
|
|
78
|
+
* The hidden select is deliberately given the *unfiltered* `@items` — it
|
|
79
|
+
* carries the form value, which must not shrink to the filter — so this
|
|
80
|
+
* covers the whole list even while the listbox is filtered down. Chips and
|
|
81
|
+
* the joined text value can therefore be resolved straight from it.
|
|
82
|
+
*/
|
|
83
|
+
static {
|
|
84
|
+
decorateFieldV2(this.prototype, "isOpen", [tracked], function () {
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
#isOpen = (initializeDeferredDecorator(this, "isOpen"), void 0);
|
|
89
|
+
static {
|
|
90
|
+
decorateFieldV2(this.prototype, "_selectedKey", [tracked], function () {
|
|
91
|
+
return null;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
#_selectedKey = (initializeDeferredDecorator(this, "_selectedKey"), void 0);
|
|
95
|
+
/**
|
|
96
|
+
* Internal tracked state for single selection mode.
|
|
97
|
+
* Source of truth for rendering. Synced with @selectedKey via the updateSingleSelectValue modifier.
|
|
98
|
+
*/
|
|
99
|
+
static {
|
|
100
|
+
decorateFieldV2(this.prototype, "_selectedKeys", [tracked], function () {
|
|
101
|
+
return [];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
#_selectedKeys = (initializeDeferredDecorator(this, "_selectedKeys"), void 0);
|
|
105
|
+
/**
|
|
106
|
+
* Internal tracked state for multiple selection mode.
|
|
107
|
+
* Source of truth for rendering. Synced with @selectedKeys via the updateMultipleSelectValue modifier.
|
|
108
|
+
*/
|
|
109
|
+
/**
|
|
110
|
+
* Initializes the component and sets up initial selection state.
|
|
111
|
+
*
|
|
112
|
+
* **Initialization:**
|
|
113
|
+
* 1. Determines selection mode (single vs multiple)
|
|
114
|
+
* 2. Copies external arg values (@selectedKey or @selectedKeys) to internal tracked state
|
|
115
|
+
* 3. Logs warnings if incorrect args are used for the selection mode
|
|
116
|
+
*
|
|
117
|
+
* Note: After instantiation, modifiers keep internal state synced with external arguments.
|
|
118
|
+
*/
|
|
119
|
+
constructor(owner, args) {
|
|
120
|
+
super(owner, args);
|
|
121
|
+
// Initialize based on mode
|
|
122
|
+
if (this.args.selectionMode === 'multiple') {
|
|
123
|
+
this._selectedKeys = this.args.selectedKeys || [];
|
|
124
|
+
} else {
|
|
125
|
+
this._selectedKey = this.args.selectedKey || null;
|
|
126
|
+
}
|
|
127
|
+
// Runtime warnings for incorrect API usage
|
|
128
|
+
this.validateArgs();
|
|
129
|
+
}
|
|
130
|
+
validateArgs() {
|
|
131
|
+
if (this.args.selectionMode === 'multiple') {
|
|
132
|
+
if (typeof this.args['selectedKey'] !== 'undefined') {
|
|
133
|
+
console.warn('WARNING: selectedKey is not supported in multiple selection mode. Use selectedKeys instead.');
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
if (typeof this.args['selectedKeys'] !== 'undefined') {
|
|
137
|
+
console.warn('WARNING: selectedKeys is deprecated for single selection mode. Use selectedKey instead.');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
static {
|
|
142
|
+
decorateFieldV2(this.prototype, "filterValue", [tracked]);
|
|
143
|
+
}
|
|
144
|
+
#filterValue = (initializeDeferredDecorator(this, "filterValue"), void 0);
|
|
145
|
+
containerRef = ref();
|
|
146
|
+
triggerRef = ref();
|
|
147
|
+
chipsContainerRef = ref();
|
|
148
|
+
/**
|
|
149
|
+
* Handles selection changes from the Listbox component.
|
|
150
|
+
*
|
|
151
|
+
* **Flow:**
|
|
152
|
+
* 1. Updates internal state (`_selectedKey` or `_selectedKeys`) for immediate UI updates
|
|
153
|
+
* 2. Calls parent's `@onSelectionChange` callback to notify of the change
|
|
154
|
+
* 3. Parent updates its state, which flows back via modifier to complete the cycle
|
|
155
|
+
*
|
|
156
|
+
* **Side effects:**
|
|
157
|
+
* - Clears filter value (for searchable selects)
|
|
158
|
+
* - Triggers form input event for native form integration
|
|
159
|
+
*
|
|
160
|
+
* @param keys - Array of selected keys from Listbox (converted to single value in single mode)
|
|
161
|
+
*/
|
|
162
|
+
onSelectionChange = keys => {
|
|
163
|
+
if (this.args.selectionMode === 'multiple') {
|
|
164
|
+
this._selectedKeys = keys;
|
|
165
|
+
if (typeof this.args.onSelectionChange === 'function') {
|
|
166
|
+
this.args.onSelectionChange(keys);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
const singleKey = keys.length > 0 ? keys[0] || null : null;
|
|
170
|
+
this._selectedKey = singleKey;
|
|
171
|
+
if (typeof this.args.onSelectionChange === 'function') {
|
|
172
|
+
this.args.onSelectionChange(singleKey);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.filterValue = undefined;
|
|
176
|
+
triggerFormInputEvent(this.containerRef.current);
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Handles selection changes from the native <select> element.
|
|
180
|
+
*
|
|
181
|
+
* This is similar to `onSelectionChange` but accepts a single key directly
|
|
182
|
+
* rather than an array, matching the native select's single-value API.
|
|
183
|
+
*
|
|
184
|
+
* **Flow:**
|
|
185
|
+
* 1. Updates internal `_selectedKey` for immediate UI update
|
|
186
|
+
* 2. Calls parent's `@onSelectionChange` callback
|
|
187
|
+
*
|
|
188
|
+
* @param key - The selected key, or null if cleared
|
|
189
|
+
*/
|
|
190
|
+
onSingleSelectionChange = key => {
|
|
191
|
+
this._selectedKey = key;
|
|
192
|
+
if (typeof this.args.onSelectionChange === 'function') {
|
|
193
|
+
this.args.onSelectionChange(key);
|
|
194
|
+
}
|
|
195
|
+
this.filterValue = undefined;
|
|
196
|
+
triggerFormInputEvent(this.containerRef.current);
|
|
197
|
+
};
|
|
198
|
+
onOpenChange = isOpen => {
|
|
199
|
+
this.isOpen = isOpen;
|
|
200
|
+
};
|
|
201
|
+
onFilterChange = event => {
|
|
202
|
+
const target = event.target;
|
|
203
|
+
this.filterValue = target.value;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Backspace on an empty filter removes the last chip — the familiar tag-input
|
|
207
|
+
* gesture. With text in the filter, Backspace edits the text as usual.
|
|
208
|
+
*/
|
|
209
|
+
handleFilterKeydown = event => {
|
|
210
|
+
if (event.key !== 'Backspace' || !this.showChips) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const target = event.target;
|
|
214
|
+
if (target.value !== '') {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
this.removeLastSelectedKey();
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* The non-filterable counterpart of {@link handleFilterKeydown}.
|
|
221
|
+
*
|
|
222
|
+
* Chip close buttons are deliberately outside the tab order (they would
|
|
223
|
+
* otherwise cost a Tab stop each before the combobox is reached), so
|
|
224
|
+
* Backspace/Delete on the trigger is the *only* keyboard route to removing a
|
|
225
|
+
* chip here. There is no text to edit on a button trigger, so both keys act
|
|
226
|
+
* immediately; `preventDefault` keeps Backspace from navigating back.
|
|
227
|
+
*/
|
|
228
|
+
handleTriggerKeydown = event => {
|
|
229
|
+
if (!this.showChips || this.args.isDisabled) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (event.key !== 'Backspace' && event.key !== 'Delete') {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
this.removeLastSelectedKey();
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Removes the trailing chip. `removeSelectedKey` applies the same
|
|
240
|
+
* `@allowEmpty` rule the chip close buttons follow, so the last required
|
|
241
|
+
* selection stays put.
|
|
242
|
+
*/
|
|
243
|
+
removeLastSelectedKey() {
|
|
244
|
+
const items = this.selectedItems;
|
|
245
|
+
const last = items[items.length - 1];
|
|
246
|
+
if (last) {
|
|
247
|
+
this.removeSelectedKey(last.key);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Returns current selection as an array for template rendering.
|
|
252
|
+
*
|
|
253
|
+
* Normalizes both single and multiple selection modes to a consistent array interface:
|
|
254
|
+
* - Multiple mode: Returns `_selectedKeys` directly
|
|
255
|
+
* - Single mode: Converts `_selectedKey` to array format (or empty array if null)
|
|
256
|
+
*
|
|
257
|
+
* Note: Always returns internal tracked state rather than arguments. External updates
|
|
258
|
+
* sync through modifiers to maintain consistency.
|
|
259
|
+
*
|
|
260
|
+
* @returns Array of selected keys (empty array if none selected)
|
|
261
|
+
*/
|
|
262
|
+
get selectedKeys() {
|
|
263
|
+
if (this.args.selectionMode === 'multiple') {
|
|
264
|
+
return this._selectedKeys;
|
|
265
|
+
} else {
|
|
266
|
+
// Single mode: convert selectedKey to array for internal use
|
|
267
|
+
const key = this.getSelectedKey;
|
|
268
|
+
return key ? [key] : [];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Returns the selected key for single selection mode.
|
|
273
|
+
*
|
|
274
|
+
* **Returns:**
|
|
275
|
+
* - Single mode: Returns `_selectedKey` (string or null)
|
|
276
|
+
* - Multiple mode: Returns null (not applicable)
|
|
277
|
+
*
|
|
278
|
+
* Note: Always returns internal tracked state rather than arguments. External updates
|
|
279
|
+
* sync through modifiers to maintain consistency.
|
|
280
|
+
*
|
|
281
|
+
* @returns The selected key, or null if none selected or in multiple mode
|
|
282
|
+
*/
|
|
283
|
+
get getSelectedKey() {
|
|
284
|
+
return this._selectedKey;
|
|
285
|
+
}
|
|
286
|
+
get blockScroll() {
|
|
287
|
+
if (this.args.blockScroll === false) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
get disableFocusTrap() {
|
|
293
|
+
if (this.args.disableFocusTrap === false) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
onAction = key => {
|
|
299
|
+
if (typeof this.args.onAction === 'function') {
|
|
300
|
+
this.args.onAction(key);
|
|
301
|
+
}
|
|
302
|
+
if (this.args.closeOnItemSelect !== false && this.args.selectionMode !== 'multiple') {
|
|
303
|
+
this.isOpen = false;
|
|
304
|
+
}
|
|
305
|
+
// wait a beat for any side effects to complete before calling onBlur
|
|
306
|
+
later(() => {
|
|
307
|
+
this.args.onBlur?.();
|
|
308
|
+
}, 150);
|
|
309
|
+
};
|
|
310
|
+
handleBlur() {
|
|
311
|
+
later(() => {
|
|
312
|
+
this.args.onBlur?.();
|
|
313
|
+
}, 150);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* In chips mode the trigger is only as wide as the room left over beside the
|
|
317
|
+
* chips, so the field's padding -- and the strip under the chevron -- are not
|
|
318
|
+
* part of it, and with a single selection the trigger can be a narrow sliver.
|
|
319
|
+
* Without this, clicking anywhere else in the field would do nothing, while
|
|
320
|
+
* the same click anywhere on a non-chips field opens the dropdown (there the
|
|
321
|
+
* trigger *is* the whole field). Forwards such a click to the trigger,
|
|
322
|
+
* including clicks on a chip's own body, so the whole field is a click
|
|
323
|
+
* target. The one exception is a chip's close button: within the chips
|
|
324
|
+
* container the only `<button>` elements a chip ever renders are its close
|
|
325
|
+
* button (see chip.gts / close-button.gts), so `closest('button')` combined
|
|
326
|
+
* with containment against `chipsContainerRef` identifies it without relying
|
|
327
|
+
* on any test-only attribute. Clicks on the trigger itself are left alone
|
|
328
|
+
* too, since it already handles its own clicks.
|
|
329
|
+
*/
|
|
330
|
+
static {
|
|
331
|
+
decorateMethodV2(this.prototype, "handleBlur", [action]);
|
|
332
|
+
}
|
|
333
|
+
handleFieldClick = event => {
|
|
334
|
+
if (!this.showChips || this.args.isDisabled) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const trigger = this.triggerRef.current;
|
|
338
|
+
const target = event.target;
|
|
339
|
+
if (!trigger || !(target instanceof Element)) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
// The trigger handles its own clicks; this listener also sees them bubble.
|
|
343
|
+
if (trigger === target || trigger.contains(target)) {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const chipsContainer = this.chipsContainerRef.current;
|
|
347
|
+
if (chipsContainer && chipsContainer.contains(target)) {
|
|
348
|
+
const closeButton = target.closest('button');
|
|
349
|
+
if (closeButton && chipsContainer.contains(closeButton)) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
trigger.focus();
|
|
354
|
+
trigger.click();
|
|
355
|
+
};
|
|
356
|
+
clearSelectedKeys = () => {
|
|
357
|
+
this.onSelectionChange([]);
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Resolved chip appearance: `@chip` wins, then the Select's own `@intent`,
|
|
361
|
+
* then chip defaults tuned for sitting inside a field.
|
|
362
|
+
*/
|
|
363
|
+
get chipOptions() {
|
|
364
|
+
const chip = this.args.selectionMode === 'multiple' ? this.args.chip : undefined;
|
|
365
|
+
return {
|
|
366
|
+
appearance: chip?.appearance ?? 'faded',
|
|
367
|
+
intent: chip?.intent ?? this.args.intent ?? 'default',
|
|
368
|
+
size: chip?.size ?? 'sm',
|
|
369
|
+
radius: chip?.radius,
|
|
370
|
+
withDot: chip?.withDot ?? false
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Whether chips may be removed. Mirrors the listbox: with `@allowEmpty`
|
|
375
|
+
* false — the default — the final selection cannot be deselected, so its
|
|
376
|
+
* chip renders without a close button rather than with a dead one.
|
|
377
|
+
*/
|
|
378
|
+
get chipsRemovable() {
|
|
379
|
+
// Asks `canDeselectKey` — the rule the listbox itself applies when an
|
|
380
|
+
// already-selected option is clicked — rather than restating it, so a chip
|
|
381
|
+
// and its option can never disagree about the same removal.
|
|
382
|
+
//
|
|
383
|
+
// Asked of `selectedItems`, the collection the chips render from, so the
|
|
384
|
+
// decision cannot disagree with what is on screen either (a selected key
|
|
385
|
+
// with no remembered item would otherwise be counted but never render a
|
|
386
|
+
// chip at all). Every chip's key is in that collection by construction, so
|
|
387
|
+
// the rule's answer is the same for all of them; it is asked of the last
|
|
388
|
+
// chip, the one Backspace removes.
|
|
389
|
+
const keys = this.selectedItems.map(item => item.key);
|
|
390
|
+
const lastKey = keys[keys.length - 1];
|
|
391
|
+
// With nothing selected there is no chip, so nothing reads this today --
|
|
392
|
+
// but the answer is deliberately `@allowEmpty`, not `false`. That is what
|
|
393
|
+
// this getter has always returned for an empty selection, and keeping it
|
|
394
|
+
// means the answer never depends on whether a chip happens to exist right
|
|
395
|
+
// now. `canDeselectKey` cannot be asked here (it needs a key), so the
|
|
396
|
+
// empty case is answered directly. Do not "simplify" this away.
|
|
397
|
+
if (lastKey === undefined) {
|
|
398
|
+
return this.args.allowEmpty === true;
|
|
399
|
+
}
|
|
400
|
+
return canDeselectKey(keys, lastKey, this.args.allowEmpty);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Removes a single selection from a chip's close button. Routes through
|
|
404
|
+
* `onSelectionChange`, which already syncs internal state, notifies the
|
|
405
|
+
* parent and dispatches the form input event.
|
|
406
|
+
*/
|
|
407
|
+
removeSelectedKey = key => {
|
|
408
|
+
if (this.args.isDisabled || !this.chipsRemovable) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
this.onSelectionChange(this.selectedKeys.filter(k => k !== key));
|
|
412
|
+
};
|
|
413
|
+
onItemsChange = (nodes, _) => {
|
|
414
|
+
// `onItemsChange` runs while a modifier installs, i.e. inside a render
|
|
415
|
+
// pass. Reading a tracked field here and writing it in the same
|
|
416
|
+
// computation would trip Glimmer's read-then-write assertion, so `nodes`
|
|
417
|
+
// is only ever written, never read, in this callback.
|
|
418
|
+
this.nodes = nodes;
|
|
419
|
+
};
|
|
420
|
+
didClose = () => {
|
|
421
|
+
this.filterValue = undefined;
|
|
422
|
+
if (typeof this.args.didClose === 'function') {
|
|
423
|
+
this.args.didClose();
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Whether selections render as chips. Chips are the default presentation for
|
|
428
|
+
* multiple selection mode; `@selectedItemsDisplay="text"` opts back out to the
|
|
429
|
+
* comma-joined string.
|
|
430
|
+
*/
|
|
431
|
+
get showChips() {
|
|
432
|
+
return this.args.selectionMode === 'multiple' && this.args.selectedItemsDisplay !== 'text';
|
|
433
|
+
}
|
|
434
|
+
get hasSelection() {
|
|
435
|
+
return this.selectedKeys.length > 0;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* The accessible name for the trigger when its own text cannot supply one.
|
|
439
|
+
*
|
|
440
|
+
* Left to itself the trigger names itself from its own text -- the selected
|
|
441
|
+
* label, or the placeholder -- and that is still what happens in the plain
|
|
442
|
+
* case; see the trigger, which only applies this when it has to.
|
|
443
|
+
*
|
|
444
|
+
* Two cases need it:
|
|
445
|
+
*
|
|
446
|
+
* - **Chips mode.** The trigger renders nothing; the chips are its siblings
|
|
447
|
+
* and are read separately. Naming the *control* is both enough and
|
|
448
|
+
* correct here -- appending the selection would have it read twice -- so
|
|
449
|
+
* this returns the bare name.
|
|
450
|
+
* - **A `:selectedItem` block.** The block owns the trigger's content and may
|
|
451
|
+
* render nothing readable at all (an avatar, an icon), which would leave
|
|
452
|
+
* the combobox announced as an unnamed button. The selection is not
|
|
453
|
+
* readable anywhere else in that case, so the name carries it: the control
|
|
454
|
+
* name *and* the selected options' text.
|
|
455
|
+
*
|
|
456
|
+
* The two halves are composed so that the separator only appears when both
|
|
457
|
+
* are there. A selected key with no registered option behind it resolves to
|
|
458
|
+
* no text at all, and `"Owner, "` is announced as "Owner comma"; and with
|
|
459
|
+
* neither `@label` nor `@placeholder` the only control name available is the
|
|
460
|
+
* hardcoded, unlocalizable `Select options`, so the selected text is left to
|
|
461
|
+
* name the control on its own rather than be prefixed by English.
|
|
462
|
+
*/
|
|
463
|
+
get triggerAccessibleName() {
|
|
464
|
+
const name = this.args.label || this.args.placeholder;
|
|
465
|
+
// Chips mode names the *control* only -- the chips are read separately --
|
|
466
|
+
// and has no better fallback than the literal.
|
|
467
|
+
if (this.showChips) {
|
|
468
|
+
return name || 'Select options';
|
|
469
|
+
}
|
|
470
|
+
const selectedText = this.hasSelection ? this.selectedTextValue : '';
|
|
471
|
+
if (!name) {
|
|
472
|
+
return selectedText || 'Select options';
|
|
473
|
+
}
|
|
474
|
+
return selectedText ? `${name}, ${selectedText}` : name;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* The selected options in item order (not click order) so chips do not
|
|
478
|
+
* reorder underneath the user as they select.
|
|
479
|
+
*
|
|
480
|
+
* Resolved against `nodes`, which the hidden native `<select>` populates from
|
|
481
|
+
* the unfiltered `@items`, so a chip stays put while a filter hides the item
|
|
482
|
+
* it came from.
|
|
483
|
+
*/
|
|
484
|
+
get selectedItems() {
|
|
485
|
+
const keys = this.selectedKeys;
|
|
486
|
+
return this.nodes.filter(node => keys.includes(node.key)).map(node => ({
|
|
487
|
+
key: node.key,
|
|
488
|
+
textValue: node.textValue,
|
|
489
|
+
item: node.item
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* The same selection `selectedItems` describes, rendered as text.
|
|
494
|
+
*
|
|
495
|
+
* Chips and this string are two presentations of one thing, so they read one
|
|
496
|
+
* projection: walking `nodes` a second time here is how a fix to the
|
|
497
|
+
* selection's contents once landed in the chips and not in the text.
|
|
498
|
+
*/
|
|
499
|
+
get selectedTextValue() {
|
|
500
|
+
return this.selectedItems.map(item => item.textValue).join(', ');
|
|
501
|
+
}
|
|
502
|
+
get backdrop() {
|
|
503
|
+
if (typeof this.args.backdrop === 'undefined') {
|
|
504
|
+
return 'transparent';
|
|
505
|
+
}
|
|
506
|
+
return this.args.backdrop;
|
|
507
|
+
}
|
|
508
|
+
get classes() {
|
|
509
|
+
const {
|
|
510
|
+
select
|
|
511
|
+
} = useStyles();
|
|
512
|
+
return select({
|
|
513
|
+
size: this.args.inputSize,
|
|
514
|
+
hasChips: this.showChips,
|
|
515
|
+
isFilterable: !!this.args.isFilterable
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
get isClearable() {
|
|
519
|
+
return this.args.isClearable && this.selectedKeys && this.selectedKeys.length > 0;
|
|
520
|
+
}
|
|
521
|
+
get filterFieldValue() {
|
|
522
|
+
if (this.filterValue !== undefined) {
|
|
523
|
+
return this.filterValue;
|
|
524
|
+
}
|
|
525
|
+
// With chips, the selection is already visible beside the input. Echoing
|
|
526
|
+
// the joined text here would fill the box and block typing.
|
|
527
|
+
if (this.showChips) {
|
|
528
|
+
return '';
|
|
529
|
+
}
|
|
530
|
+
return this.selectedTextValue;
|
|
531
|
+
}
|
|
532
|
+
get filteredItems() {
|
|
533
|
+
if (this.filterValue === undefined) {
|
|
534
|
+
return this.args.items;
|
|
535
|
+
}
|
|
536
|
+
let filter = this.args.filter || defaultFilter;
|
|
537
|
+
return this.args.items?.filter(item => filter(keyAndLabelForItem(item).label, this.filterValue || ''));
|
|
538
|
+
}
|
|
539
|
+
get showEmptyContent() {
|
|
540
|
+
return this.filteredItems?.length === 0 && !this.args.hideEmptyContent;
|
|
541
|
+
}
|
|
542
|
+
get autoActivateMode() {
|
|
543
|
+
if (this.filterValue === undefined || this.filterValue === '') {
|
|
544
|
+
return 'selected';
|
|
545
|
+
}
|
|
546
|
+
return 'first';
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Syncs internal `_selectedKeys` with external `@selectedKeys` argument.
|
|
550
|
+
*
|
|
551
|
+
* Runs whenever `@selectedKeys` changes:
|
|
552
|
+
* - Updates `_selectedKeys` to match the new external value
|
|
553
|
+
* - Normalizes undefined/null to empty array
|
|
554
|
+
*
|
|
555
|
+
* This enables UI updates when the external value changes.
|
|
556
|
+
*/
|
|
557
|
+
updateMultipleSelectValue = modifier((_, [selectedKeys]) => {
|
|
558
|
+
if (selectedKeys !== undefined && selectedKeys !== null) {
|
|
559
|
+
this._selectedKeys = selectedKeys;
|
|
560
|
+
} else {
|
|
561
|
+
// NOTE: is this the right behavior?
|
|
562
|
+
this._selectedKeys = [];
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
/**
|
|
566
|
+
* Syncs internal `_selectedKey` with external `@selectedKey` argument.
|
|
567
|
+
*
|
|
568
|
+
* Runs whenever `@selectedKey` changes:
|
|
569
|
+
* - Updates `_selectedKey` to match the new external value
|
|
570
|
+
* - Handles null values for cleared selections
|
|
571
|
+
*
|
|
572
|
+
* This enables UI updates when the external value changes.
|
|
573
|
+
*/
|
|
574
|
+
updateSingleSelectValue = modifier((_, [selectedKey]) => {
|
|
575
|
+
if (selectedKey !== undefined) {
|
|
576
|
+
this._selectedKey = selectedKey;
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
static {
|
|
580
|
+
setComponentTemplate(precompileTemplate("<div {{this.updateMultipleSelectValue @selectedKeys}} {{this.updateSingleSelectValue @selectedKey}} {{this.containerRef.setup}} class={{this.classes.base class=@classes.base}} ...attributes>\n <FormControl @id={{@id}} @size={{@inputSize}} @label={{@label}} @isRequired={{@isRequired}} @description={{@description}} @errors={{@errors}} @isInvalid={{@isInvalid}} as |c|>\n <Popover @placement={{@placement}} @flipOptions={{@flipOptions}} @middleware={{@middleware}} @shiftOptions={{@shiftOptions}} @offsetOptions={{@offsetOptions}} @strategy={{@strategy}} @didClose={{this.didClose}} @isOpen={{this.isOpen}} @onOpenChange={{this.onOpenChange}} as |p|>\n <VisuallyHidden>\n <SelectNativeMirror @items={{@items}} @allowEmpty={{@allowEmpty}} @disabledKeys={{@disabledKeys}} @selectionMode={{@selectionMode}} @selectedKeys={{this.selectedKeys}} @selectedKey={{this.getSelectedKey}} @onSelectionChange={{this.onSelectionChange}} @onSingleSelectionChange={{this.onSingleSelectionChange}} @onItemsChange={{this.onItemsChange}} @placeholder={{@placeholder}} @id={{c.id}} @name={{@name}} @isDisabled={{@isDisabled}}>\n <:default as |l|>\n {{!-- @glint-expect-error: the signature of the native select is not the same as the listbox--}}\n {{yield l to=\"default\"}}\n </:default>\n </SelectNativeMirror>\n </VisuallyHidden>\n\n <div class={{this.classes.innerContainer class=@classes.innerContainer}}>\n {{#if (has-block \"startContent\")}}\n <div data-test-id=\"input-start-content\" class={{this.classes.startContent class=@classes.startContent startContentPointerEvents=(if @startContentPointerEvents @startContentPointerEvents \"auto\")}}>\n {{yield to=\"startContent\"}}\n </div>\n {{/if}}\n {{!-- The wrapper, not the trigger, is the popover's width reference:\n in chips mode the trigger is only as wide as the space left over\n inside the field. The wrapper is a real full-width box in both\n modes, so the dropdown matches the field either way. --}}\n <div {{p.anchor}} {{p.measureWidth}} {{on \"click\" this.handleFieldClick}} data-test-id={{if this.showChips \"chips-field\"}} {{!-- These flags are stringified rather than handed the boolean.\n Glimmer renders a true boolean attribute as an empty value, so\n passing isInvalid straight through produced an empty data-invalid\n and the theme selector keyed on the value true never matched. --}} data-has-chips={{if this.showChips \"true\" \"false\"}} data-invalid={{if c.isInvalid \"true\" \"false\"}} data-disabled={{if @isDisabled \"true\" \"false\"}} class={{this.classes.chipsField class=@classes.chipsField hasStartContent=(has-block \"startContent\") hasEndContent=true}}>\n {{#if (and this.showChips this.hasSelection)}}\n {{!-- A block cannot be passed conditionally in Glimmer, so the\n :item block below is always supplied and the branch lives\n inside it: with no :selectedItem block from the consumer, both\n it and the trigger render exactly what they rendered before. --}}\n <SelectedChips @containerRef={{this.chipsContainerRef.setup}} @items={{this.selectedItems}} @classes={{this.classes}} @userClasses={{@classes}} @chipOptions={{this.chipOptions}} @isDisabled={{@isDisabled}} @isRemovable={{this.chipsRemovable}} @onRemove={{this.removeSelectedKey}}>\n <:item as |selected|>\n {{~#if (has-block \"selectedItem\")~}}\n {{~yield selected to=\"selectedItem\"~}}\n {{~else~}}\n {{~selected.label~}}\n {{~/if~}}\n </:item>\n </SelectedChips>\n {{/if}}\n <SelectTrigger @isFilterable={{@isFilterable}} @trigger={{p.trigger}} @triggerRef={{this.triggerRef.setup}} @isDisabled={{@isDisabled}} @showChips={{this.showChips}} @accessibleName={{this.triggerAccessibleName}} @placeholder={{@placeholder}} @hasSelection={{this.hasSelection}} @hasStartContent={{has-block \"startContent\"}} @classes={{this.classes}} @userClasses={{@classes}} @items={{this.selectedItems}} @filterValue={{this.filterFieldValue}} @onFilterInput={{this.onFilterChange}} @onFilterKeydown={{this.handleFilterKeydown}} @onKeydown={{this.handleTriggerKeydown}} @onBlur={{this.handleBlur}} @hasCustomContent={{has-block \"selectedItem\"}}>\n <:selectedItem as |selected|>\n {{~#if (has-block \"selectedItem\")~}}\n {{~yield selected to=\"selectedItem\"~}}\n {{~else~}}\n {{~selected.label~}}\n {{~/if~}}\n </:selectedItem>\n </SelectTrigger>\n </div>\n <SelectEndContent @classes={{this.classes}} @userClasses={{@classes}} @endContentPointerEvents={{@endContentPointerEvents}} @inputSize={{@inputSize}} @isLoading={{@isLoading}} @isClearable={{this.isClearable}} @onClear={{this.clearSelectedKeys}}>\n {{yield to=\"endContent\"}}\n </SelectEndContent>\n </div>\n\n <p.Content @size={{if @popoverSize @popoverSize \"trigger\"}} @target={{@target}} @renderInPlace={{@renderInPlace}} @disableFocusTrap={{this.disableFocusTrap}} @blockScroll={{this.blockScroll}} @transitionDuration={{@transitionDuration}} @backdrop={{this.backdrop}} @disableTransitions={{@disableTransitions}} @focusTrapOptions={{@focusTrapOptions}} @closeOnOutsideClick={{@closeOnOutsideClick}} @closeOnEscapeKey={{@closeOnEscapeKey}} @backdropTransition={{@backdropTransition}} @transition={{@transition}} @preventAutoFocus={{true}}>\n <Listbox @items={{this.filteredItems}} @allowEmpty={{@allowEmpty}} @appearance={{@appearance}} @disabledKeys={{@disabledKeys}} @intent={{@intent}} @isKeyboardEventsEnabled={{true}} @onAction={{this.onAction}} @onSelectionChange={{this.onSelectionChange}} @selectedKeys={{this.selectedKeys}} @selectionMode={{if @selectionMode @selectionMode \"single\"}} @type=\"listbox\" @class={{this.classes.listbox class=@classes.listbox}} @elementToAddKeyboardEvents={{this.triggerRef.current}} @autoActivateMode={{this.autoActivateMode}}>\n <:item as |l|>\n {{#if (has-block \"item\")}}\n {{yield l to=\"item\"}}\n {{else}}\n <l.Item @key={{l.key}} @appearance={{@appearance}} @intent={{@intent}}>\n {{l.label}}\n </l.Item>\n {{/if}}\n </:item>\n <:default as |l|>\n {{yield l to=\"default\"}}\n </:default>\n </Listbox>\n {{#if this.showEmptyContent}}\n <div class={{this.classes.emptyContent class=@classes.emptyContent}} data-test-id=\"empty-content\">\n {{#if (has-block \"emptyContent\")}}\n {{yield to=\"emptyContent\"}}\n {{else}}\n No results found.\n {{/if}}\n </div>\n {{/if}}\n </p.Content>\n </Popover>\n </FormControl>\n</div>", {
|
|
581
|
+
strictMode: true,
|
|
582
|
+
scope: () => ({
|
|
583
|
+
FormControl,
|
|
584
|
+
Popover,
|
|
585
|
+
VisuallyHidden,
|
|
586
|
+
SelectNativeMirror,
|
|
587
|
+
on,
|
|
588
|
+
and,
|
|
589
|
+
SelectedChips,
|
|
590
|
+
SelectTrigger,
|
|
591
|
+
SelectEndContent,
|
|
592
|
+
Listbox
|
|
593
|
+
})
|
|
594
|
+
}), this);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export { Select, Select as default };
|
|
599
|
+
//# sourceMappingURL=select.js.map
|