@smilodon/vanilla 1.9.3 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPLETE-GUIDE.md +28 -34
- package/README.md +154 -46
- package/package.json +2 -2
package/COMPLETE-GUIDE.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# @smilodon/vanilla - Complete Guide
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Vanilla JavaScript select component guide**
|
|
4
4
|
|
|
5
5
|
This guide provides comprehensive documentation for using Smilodon Select with Vanilla JavaScript (no framework), covering all features, styling options, and advanced use cases.
|
|
6
6
|
|
|
7
|
+
> Capability caveat: the public `virtualized` option enables chunked rendering for large flat lists, not viewport-windowed virtualization. Older examples below that say “only visible rows” or imply bounded DOM are not current release guarantees. See [Known Limitations](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
|
|
8
|
+
>
|
|
9
|
+
> Compatibility note: this long-form guide contains examples from the legacy `NativeSelect` API and is not a reliable current API inventory. For the maintained `EnhancedSelect` and `@smilodon/vanilla` helper signatures, follow the [API reference](../../docs/API-REFERENCE.md) and exported TypeScript declarations. Accessibility verification and manual assistive-technology assessment remain pending; this is not a WCAG conformance statement.
|
|
10
|
+
|
|
7
11
|
---
|
|
8
12
|
|
|
9
13
|
## Table of Contents
|
|
@@ -139,30 +143,21 @@ select.addEventListener('change', (event) => {
|
|
|
139
143
|
### Properties
|
|
140
144
|
|
|
141
145
|
```javascript
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
select
|
|
152
|
-
console.log(select.selectedValues); // ['apple', 'banana']
|
|
153
|
-
|
|
154
|
-
// Behavior properties
|
|
155
|
-
select.multiple = true; // Enable multi-select
|
|
156
|
-
select.searchable = true; // Enable search (default: true)
|
|
157
|
-
select.disabled = false; // Disable select
|
|
158
|
-
select.placeholder = 'Select...'; // Placeholder text
|
|
159
|
-
|
|
160
|
-
// Display properties
|
|
161
|
-
select.maxHeight = 300; // Max dropdown height (px)
|
|
162
|
-
select.estimatedItemHeight = 48; // Item height for virtualization
|
|
146
|
+
// Current helper API
|
|
147
|
+
import { createSelect } from '@smilodon/vanilla';
|
|
148
|
+
|
|
149
|
+
const select = createSelect({
|
|
150
|
+
items: [{ value: '1', label: 'Option 1' }],
|
|
151
|
+
multiple: true,
|
|
152
|
+
searchable: true,
|
|
153
|
+
virtualized: true, // Incremental chunk rendering; not viewport windowing
|
|
154
|
+
});
|
|
155
|
+
document.body.append(select);
|
|
163
156
|
|
|
164
|
-
//
|
|
165
|
-
select.
|
|
157
|
+
// Current EnhancedSelect imperative API
|
|
158
|
+
select.setSelectedValues(['1']);
|
|
159
|
+
console.log(select.getSelectedValues());
|
|
160
|
+
select.updateConfig({ virtualize: true });
|
|
166
161
|
```
|
|
167
162
|
|
|
168
163
|
### Methods
|
|
@@ -889,7 +884,8 @@ enhanced-select {
|
|
|
889
884
|
|
|
890
885
|
select.items = users;
|
|
891
886
|
select.placeholder = 'Select a user';
|
|
892
|
-
|
|
887
|
+
// estimatedItemHeight only configures the guarded viewport-window test path.
|
|
888
|
+
select.updateConfig({ estimatedItemHeight: 60 });
|
|
893
889
|
|
|
894
890
|
// Set custom renderer
|
|
895
891
|
select.optionTemplate = (item) => `
|
|
@@ -929,8 +925,7 @@ enhanced-select {
|
|
|
929
925
|
}));
|
|
930
926
|
|
|
931
927
|
select.items = items;
|
|
932
|
-
select.
|
|
933
|
-
select.estimatedItemHeight = 48;
|
|
928
|
+
select.updateConfig({ virtualize: true }); // Incremental chunks, not viewport windowing
|
|
934
929
|
select.searchable = true;
|
|
935
930
|
select.placeholder = 'Search 100k items...';
|
|
936
931
|
</script>
|
|
@@ -1036,7 +1031,7 @@ enhanced-select {
|
|
|
1036
1031
|
|
|
1037
1032
|
## Accessibility
|
|
1038
1033
|
|
|
1039
|
-
Smilodon
|
|
1034
|
+
Smilodon implements selected keyboard and ARIA behavior. Pinned cross-browser verification and manual assistive-technology assessment remain pending; this is not a WCAG conformance claim.
|
|
1040
1035
|
|
|
1041
1036
|
### Keyboard Navigation
|
|
1042
1037
|
|
|
@@ -1053,7 +1048,7 @@ The component automatically includes:
|
|
|
1053
1048
|
- `role="combobox"`
|
|
1054
1049
|
- `aria-expanded`
|
|
1055
1050
|
- `aria-haspopup`
|
|
1056
|
-
- `aria-label` / `aria-
|
|
1051
|
+
- `aria-label` / `aria-description` (literal host attributes are forwarded)
|
|
1057
1052
|
- `aria-activedescendant`
|
|
1058
1053
|
- `aria-multiselectable` (when `multiple`)
|
|
1059
1054
|
|
|
@@ -1062,7 +1057,7 @@ The component automatically includes:
|
|
|
1062
1057
|
```html
|
|
1063
1058
|
<label id="country-label">Country</label>
|
|
1064
1059
|
<enhanced-select
|
|
1065
|
-
aria-
|
|
1060
|
+
aria-label="Country"
|
|
1066
1061
|
placeholder="Select your country"
|
|
1067
1062
|
></enhanced-select>
|
|
1068
1063
|
```
|
|
@@ -1221,13 +1216,12 @@ select.selectedValues = ['apple', 'banana'];
|
|
|
1221
1216
|
|
|
1222
1217
|
If you experience slow rendering with large datasets:
|
|
1223
1218
|
|
|
1224
|
-
1.
|
|
1225
|
-
2.
|
|
1219
|
+
1. `virtualize` enables incremental chunk rendering; it does not bound mounted DOM.
|
|
1220
|
+
2. Use host-controlled paging if the full result set should not be loaded at once.
|
|
1226
1221
|
3. Use debouncing for search events
|
|
1227
1222
|
|
|
1228
1223
|
```javascript
|
|
1229
|
-
select.
|
|
1230
|
-
select.estimatedItemHeight = 60;
|
|
1224
|
+
select.updateConfig({ virtualize: true });
|
|
1231
1225
|
|
|
1232
1226
|
// Debounce search
|
|
1233
1227
|
let searchTimeout;
|
package/README.md
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Vanilla JavaScript/TypeScript helpers for Smilodon Select. Part of the [Smilodon](https://github.com/navidrezadoost/smilodon) UI toolkit.
|
|
4
4
|
|
|
5
|
+
> Large-list status: the helper's public `virtualized` option maps to legacy chunked rendering for large flat lists; it does not window rows to the viewport. True viewport virtualization remains guarded by a private test seam and is not a supported production mode. See the [current limitation record](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
|
|
6
|
+
|
|
7
|
+
> Current API: use the [API reference](../../docs/API-REFERENCE.md) and the package's exported TypeScript declarations. The long-form guide below contains legacy `NativeSelect` examples and is not a current API inventory.
|
|
8
|
+
>
|
|
9
|
+
> **Registration prerequisite:** import `@smilodon/core` before calling `createSelect()` or `initSelect()`. The Vanilla helper creates an `enhanced-select` element and immediately calls its imperative methods; it does not wait for custom-element registration/upgrade. For an existing host, await `customElements.whenDefined('enhanced-select')` before `initSelect()`.
|
|
10
|
+
|
|
5
11
|
## Features
|
|
6
12
|
|
|
7
13
|
- ✨ **Simple API** - Easy-to-use helper functions for vanilla JS
|
|
8
14
|
- 🔍 **Zero Dependencies** - Only requires @smilodon/core
|
|
9
|
-
- ♿ **
|
|
10
|
-
- ⚡ **
|
|
15
|
+
- ♿ **Accessibility behaviors** - The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit. This does not certify every Vanilla integration, minimum browser versions, or WCAG conformance; manual assistive-technology assessment remains pending.
|
|
16
|
+
- ⚡ **Bundle size** - Size depends on the selected package entry, dependency graph, and bundler output. No current version-specific gzipped-size measurement is claimed here.
|
|
11
17
|
- 🔧 **TypeScript** - Full type safety included
|
|
12
18
|
- 📦 **Tree-Shakeable** - Import only what you need
|
|
13
19
|
- 🎯 **Web Standards** - Built on native Web Components
|
|
@@ -18,7 +24,7 @@ Vanilla JavaScript/TypeScript helpers for Smilodon Select. Part of the [Smilodon
|
|
|
18
24
|
|
|
19
25
|
**Framework integration (Vue 3, Nuxt 4, React, SSR, Vite):** [`docs/FRAMEWORK-INTEGRATION.md`](../../docs/FRAMEWORK-INTEGRATION.md)
|
|
20
26
|
|
|
21
|
-
👉 **[
|
|
27
|
+
👉 **[Legacy Vanilla JS Guide (mixed-era examples)](./COMPLETE-GUIDE.md)** 👈
|
|
22
28
|
|
|
23
29
|
## Installation
|
|
24
30
|
|
|
@@ -31,6 +37,7 @@ npm install @smilodon/vanilla @smilodon/core
|
|
|
31
37
|
### Using the Helper Function
|
|
32
38
|
|
|
33
39
|
```typescript
|
|
40
|
+
import '@smilodon/core';
|
|
34
41
|
import { createSelect } from '@smilodon/vanilla';
|
|
35
42
|
|
|
36
43
|
const select = createSelect({
|
|
@@ -51,6 +58,14 @@ document.body.appendChild(select);
|
|
|
51
58
|
### Direction and option-state controls
|
|
52
59
|
|
|
53
60
|
```typescript
|
|
61
|
+
import '@smilodon/core';
|
|
62
|
+
import { createSelect } from '@smilodon/vanilla';
|
|
63
|
+
|
|
64
|
+
const items = [
|
|
65
|
+
{ value: 'a', label: 'Alpha' },
|
|
66
|
+
{ value: 'b', label: 'Beta' },
|
|
67
|
+
];
|
|
68
|
+
|
|
54
69
|
const select = createSelect({
|
|
55
70
|
items,
|
|
56
71
|
direction: 'rtl',
|
|
@@ -84,6 +99,7 @@ Use these when you want advanced core features without writing the whole `update
|
|
|
84
99
|
- `config`
|
|
85
100
|
|
|
86
101
|
```typescript
|
|
102
|
+
import '@smilodon/core';
|
|
87
103
|
import { createSelect } from '@smilodon/vanilla';
|
|
88
104
|
|
|
89
105
|
const select = createSelect({
|
|
@@ -120,6 +136,14 @@ const select = createSelect({
|
|
|
120
136
|
#### Full `config` passthrough
|
|
121
137
|
|
|
122
138
|
```typescript
|
|
139
|
+
import '@smilodon/core';
|
|
140
|
+
import { createSelect } from '@smilodon/vanilla';
|
|
141
|
+
|
|
142
|
+
const items = [
|
|
143
|
+
{ value: 'react', label: 'React' },
|
|
144
|
+
{ value: 'vue', label: 'Vue' },
|
|
145
|
+
];
|
|
146
|
+
|
|
123
147
|
const select = createSelect({
|
|
124
148
|
items,
|
|
125
149
|
multiple: true,
|
|
@@ -154,8 +178,11 @@ const select = createSelect({
|
|
|
154
178
|
#### Global defaults from `@smilodon/vanilla`
|
|
155
179
|
|
|
156
180
|
```typescript
|
|
181
|
+
import '@smilodon/core';
|
|
157
182
|
import { configureSelect, createSelect } from '@smilodon/vanilla';
|
|
158
183
|
|
|
184
|
+
const items = [{ value: 'react', label: 'React' }];
|
|
185
|
+
|
|
159
186
|
configureSelect({
|
|
160
187
|
searchable: true,
|
|
161
188
|
clearControl: {
|
|
@@ -183,15 +210,26 @@ In addition to `open()`, `close()`, `clear()`, `setItems()`, and `setGroupedItem
|
|
|
183
210
|
- `clearError(element)`
|
|
184
211
|
- `setRequired(element, required)`
|
|
185
212
|
- `validate(element)`
|
|
213
|
+
- `getCapabilities(element)` and `getKnownLimitations(element)`
|
|
214
|
+
- `getTrackingSnapshot(element)`, `clearTracking(element, source?)`, and `setLimitationPolicies(element, policies)`
|
|
215
|
+
- `getValue(element)` and `setValue(element, value)`
|
|
216
|
+
- global `configureSelect(config)`, `resetSelectConfig()`, and `selectConfig`
|
|
186
217
|
|
|
187
218
|
```typescript
|
|
219
|
+
import '@smilodon/core';
|
|
188
220
|
import {
|
|
221
|
+
createSelect,
|
|
189
222
|
clearSearch,
|
|
190
223
|
updateConfig,
|
|
191
224
|
setError,
|
|
192
225
|
validate,
|
|
193
226
|
} from '@smilodon/vanilla';
|
|
194
227
|
|
|
228
|
+
const select = createSelect({
|
|
229
|
+
items: [{ value: 'choice', label: 'Choice' }],
|
|
230
|
+
});
|
|
231
|
+
document.body.appendChild(select);
|
|
232
|
+
|
|
195
233
|
clearSearch(select);
|
|
196
234
|
updateConfig(select, { selection: { showSelectedIndicator: false } });
|
|
197
235
|
setError(select, 'Please choose at least one option');
|
|
@@ -204,33 +242,44 @@ console.log(validate(select));
|
|
|
204
242
|
<!DOCTYPE html>
|
|
205
243
|
<html>
|
|
206
244
|
<head>
|
|
245
|
+
<meta charset="utf-8">
|
|
246
|
+
<title>Smilodon Vanilla example</title>
|
|
247
|
+
</head>
|
|
248
|
+
<body>
|
|
249
|
+
<div id="app">
|
|
250
|
+
<enhanced-select placeholder="Select a language..."></enhanced-select>
|
|
251
|
+
</div>
|
|
207
252
|
<script type="module">
|
|
208
253
|
import '@smilodon/core';
|
|
209
254
|
import { initSelect } from '@smilodon/vanilla';
|
|
210
255
|
|
|
211
|
-
|
|
212
|
-
|
|
256
|
+
await customElements.whenDefined('enhanced-select');
|
|
257
|
+
const select = document.querySelector<HTMLElement>('enhanced-select');
|
|
258
|
+
if (!select) throw new Error('Expected an enhanced-select element');
|
|
259
|
+
|
|
213
260
|
initSelect(select, {
|
|
214
261
|
items: [
|
|
215
262
|
{ value: 'js', label: 'JavaScript' },
|
|
216
263
|
{ value: 'ts', label: 'TypeScript' },
|
|
217
264
|
{ value: 'py', label: 'Python' },
|
|
218
265
|
],
|
|
219
|
-
value: 'js'
|
|
266
|
+
value: 'js',
|
|
267
|
+
searchable: true,
|
|
268
|
+
placeholder: 'Select a language...'
|
|
220
269
|
});
|
|
221
270
|
</script>
|
|
222
|
-
</head>
|
|
223
|
-
<body>
|
|
224
|
-
<enhanced-select placeholder="Select a language..."></enhanced-select>
|
|
225
271
|
</body>
|
|
226
272
|
</html>
|
|
227
273
|
```
|
|
228
274
|
|
|
229
275
|
## Examples
|
|
230
276
|
|
|
277
|
+
Every standalone helper example below imports `@smilodon/core` before calling `createSelect()`. In an application, one core side-effect import at the browser entry point is sufficient. When initializing an existing host with `initSelect()`, wait for `customElements.whenDefined('enhanced-select')` as shown above.
|
|
278
|
+
|
|
231
279
|
### Searchable Select
|
|
232
280
|
|
|
233
281
|
```typescript
|
|
282
|
+
import '@smilodon/core';
|
|
234
283
|
import { createSelect } from '@smilodon/vanilla';
|
|
235
284
|
|
|
236
285
|
const select = createSelect({
|
|
@@ -244,12 +293,13 @@ const select = createSelect({
|
|
|
244
293
|
onChange: (value) => console.log('Country:', value)
|
|
245
294
|
});
|
|
246
295
|
|
|
247
|
-
document.
|
|
296
|
+
document.body.appendChild(select);
|
|
248
297
|
```
|
|
249
298
|
|
|
250
299
|
### Multi-Select
|
|
251
300
|
|
|
252
301
|
```typescript
|
|
302
|
+
import '@smilodon/core';
|
|
253
303
|
import { createSelect } from '@smilodon/vanilla';
|
|
254
304
|
|
|
255
305
|
const select = createSelect({
|
|
@@ -265,12 +315,15 @@ const select = createSelect({
|
|
|
265
315
|
}
|
|
266
316
|
});
|
|
267
317
|
|
|
268
|
-
document.
|
|
318
|
+
document.body.appendChild(select);
|
|
269
319
|
```
|
|
270
320
|
|
|
271
321
|
### Grouped Options
|
|
272
322
|
|
|
323
|
+
Vanilla's adapter input intentionally uses `{ group, items }`. The core runtime's `setGroupedItems()` contract uses `{ label, options }`; the helper converts the Vanilla shape to the core shape internally. Use the Vanilla shape with `createSelect()` / helper `setGroupedItems()` and the core shape only when calling the core element directly.
|
|
324
|
+
|
|
273
325
|
```typescript
|
|
326
|
+
import '@smilodon/core';
|
|
274
327
|
import { createSelect } from '@smilodon/vanilla';
|
|
275
328
|
|
|
276
329
|
const select = createSelect({
|
|
@@ -293,46 +346,56 @@ const select = createSelect({
|
|
|
293
346
|
onChange: (value) => console.log('Food:', value)
|
|
294
347
|
});
|
|
295
348
|
|
|
296
|
-
document.
|
|
349
|
+
document.body.appendChild(select);
|
|
297
350
|
```
|
|
298
351
|
|
|
299
352
|
### Infinite Scroll
|
|
300
353
|
|
|
301
354
|
```typescript
|
|
355
|
+
import '@smilodon/core';
|
|
302
356
|
import { createSelect, setItems } from '@smilodon/vanilla';
|
|
303
357
|
|
|
304
|
-
|
|
305
|
-
|
|
358
|
+
const pageSize = 50;
|
|
359
|
+
const total = 500;
|
|
360
|
+
let items = makeItems(1, pageSize);
|
|
361
|
+
let loading = false;
|
|
306
362
|
|
|
307
363
|
const select = createSelect({
|
|
308
364
|
items,
|
|
309
365
|
infiniteScroll: true,
|
|
310
|
-
pageSize
|
|
366
|
+
pageSize,
|
|
311
367
|
placeholder: 'Scroll to load more...',
|
|
312
|
-
onLoadMore: (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
368
|
+
onLoadMore: () => {
|
|
369
|
+
if (loading || items.length >= total) return;
|
|
370
|
+
|
|
371
|
+
loading = true;
|
|
372
|
+
const start = items.length + 1;
|
|
373
|
+
const count = Math.min(pageSize, total - items.length);
|
|
374
|
+
items = [...items, ...makeItems(start, count)];
|
|
316
375
|
setItems(select, items);
|
|
376
|
+
loading = false;
|
|
317
377
|
}
|
|
318
378
|
});
|
|
319
379
|
|
|
320
|
-
function
|
|
321
|
-
return Array.from({ length:
|
|
380
|
+
function makeItems(start: number, count: number) {
|
|
381
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
322
382
|
value: start + i,
|
|
323
383
|
label: `Item ${start + i}`,
|
|
324
384
|
}));
|
|
325
385
|
}
|
|
326
386
|
|
|
327
|
-
document.
|
|
387
|
+
document.body.appendChild(select);
|
|
328
388
|
```
|
|
329
389
|
|
|
330
|
-
|
|
390
|
+
For remote data, keep the in-flight flag set until the request settles, detect the server's end-of-data response, and report/retry failures in the host application. The helper invokes `onLoadMore`; it does not own the data source or deduplicate asynchronous requests for you.
|
|
391
|
+
|
|
392
|
+
### Incremental Chunk Rendering (Large Flat Lists)
|
|
331
393
|
|
|
332
394
|
```typescript
|
|
395
|
+
import '@smilodon/core';
|
|
333
396
|
import { createSelect } from '@smilodon/vanilla';
|
|
334
397
|
|
|
335
|
-
// Generate
|
|
398
|
+
// Generate a large flat item set
|
|
336
399
|
const items = Array.from({ length: 100000 }, (_, i) => ({
|
|
337
400
|
value: i + 1,
|
|
338
401
|
label: `Item ${i + 1}`,
|
|
@@ -340,40 +403,59 @@ const items = Array.from({ length: 100000 }, (_, i) => ({
|
|
|
340
403
|
|
|
341
404
|
const select = createSelect({
|
|
342
405
|
items,
|
|
343
|
-
virtualized: true,
|
|
406
|
+
virtualized: true, // Incremental chunks, not viewport windowing
|
|
344
407
|
searchable: true,
|
|
345
|
-
placeholder: '
|
|
408
|
+
placeholder: 'Large item list'
|
|
346
409
|
});
|
|
347
410
|
|
|
348
|
-
document.
|
|
411
|
+
document.body.appendChild(select);
|
|
349
412
|
```
|
|
350
413
|
|
|
351
414
|
### Server-Side Search
|
|
352
415
|
|
|
353
416
|
```typescript
|
|
417
|
+
import '@smilodon/core';
|
|
354
418
|
import { createSelect, setItems } from '@smilodon/vanilla';
|
|
355
419
|
|
|
420
|
+
let searchRequest = 0;
|
|
421
|
+
let activeController: AbortController | undefined;
|
|
422
|
+
|
|
356
423
|
const select = createSelect({
|
|
357
424
|
searchable: true,
|
|
358
425
|
placeholder: 'Type to search...',
|
|
359
426
|
onSearch: async (query) => {
|
|
427
|
+
const requestId = ++searchRequest;
|
|
428
|
+
activeController?.abort();
|
|
429
|
+
|
|
360
430
|
if (!query) {
|
|
361
431
|
setItems(select, []);
|
|
362
432
|
return;
|
|
363
433
|
}
|
|
364
434
|
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
435
|
+
const controller = new AbortController();
|
|
436
|
+
activeController = controller;
|
|
437
|
+
try {
|
|
438
|
+
const response = await fetch(`/api/search?q=${encodeURIComponent(query)}`, {
|
|
439
|
+
signal: controller.signal,
|
|
440
|
+
});
|
|
441
|
+
if (!response.ok) throw new Error(`Search failed: ${response.status}`);
|
|
442
|
+
const data = await response.json();
|
|
443
|
+
if (requestId === searchRequest) setItems(select, data.results);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
if (!(error instanceof DOMException && error.name === 'AbortError') && requestId === searchRequest) {
|
|
446
|
+
console.error('Unable to search options', error);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
368
449
|
}
|
|
369
450
|
});
|
|
370
451
|
|
|
371
|
-
document.
|
|
452
|
+
document.body.appendChild(select);
|
|
372
453
|
```
|
|
373
454
|
|
|
374
455
|
### Programmatic Control
|
|
375
456
|
|
|
376
457
|
```typescript
|
|
458
|
+
import '@smilodon/core';
|
|
377
459
|
import { createSelect, getValue, setValue, clear, open, close } from '@smilodon/vanilla';
|
|
378
460
|
|
|
379
461
|
const select = createSelect({
|
|
@@ -385,26 +467,32 @@ const select = createSelect({
|
|
|
385
467
|
});
|
|
386
468
|
|
|
387
469
|
// Add to DOM
|
|
388
|
-
|
|
470
|
+
const buttons = Object.entries({ open: 'Open', close: 'Close', set: 'Set value', get: 'Get value', clear: 'Clear' }).map(([id, label]) => {
|
|
471
|
+
const button = document.createElement('button');
|
|
472
|
+
button.id = `btn-${id}`;
|
|
473
|
+
button.textContent = label;
|
|
474
|
+
return button;
|
|
475
|
+
});
|
|
476
|
+
document.body.append(select, ...buttons);
|
|
389
477
|
|
|
390
478
|
// Programmatic API
|
|
391
|
-
document.getElementById('btn-open')
|
|
479
|
+
document.getElementById('btn-open')!.addEventListener('click', () => {
|
|
392
480
|
open(select);
|
|
393
481
|
});
|
|
394
482
|
|
|
395
|
-
document.getElementById('btn-close')
|
|
483
|
+
document.getElementById('btn-close')!.addEventListener('click', () => {
|
|
396
484
|
close(select);
|
|
397
485
|
});
|
|
398
486
|
|
|
399
|
-
document.getElementById('btn-set')
|
|
487
|
+
document.getElementById('btn-set')!.addEventListener('click', () => {
|
|
400
488
|
setValue(select, 'published');
|
|
401
489
|
});
|
|
402
490
|
|
|
403
|
-
document.getElementById('btn-get')
|
|
491
|
+
document.getElementById('btn-get')!.addEventListener('click', () => {
|
|
404
492
|
console.log('Current value:', getValue(select));
|
|
405
493
|
});
|
|
406
494
|
|
|
407
|
-
document.getElementById('btn-clear')
|
|
495
|
+
document.getElementById('btn-clear')!.addEventListener('click', () => {
|
|
408
496
|
clear(select);
|
|
409
497
|
});
|
|
410
498
|
```
|
|
@@ -412,6 +500,7 @@ document.getElementById('btn-clear').addEventListener('click', () => {
|
|
|
412
500
|
### Clear Control (Reset Selection/Search)
|
|
413
501
|
|
|
414
502
|
```typescript
|
|
503
|
+
import '@smilodon/core';
|
|
415
504
|
import { createSelect } from '@smilodon/vanilla';
|
|
416
505
|
|
|
417
506
|
const select = createSelect({
|
|
@@ -438,11 +527,15 @@ document.body.appendChild(select);
|
|
|
438
527
|
|
|
439
528
|
Styling hooks: `::part(clear-button)`, `::part(clear-icon)`, and `--select-clear-*` CSS variables.
|
|
440
529
|
|
|
441
|
-
The default `hideWhenEmpty: true` behavior means an empty clearable select reserves no action-area space. A selection or enabled search query reveals the button and coordinated input/arrow layout; clearing both restores the normal layout
|
|
530
|
+
The shared runtime's default `hideWhenEmpty: true` behavior means an empty clearable select reserves no action-area space. A selection or enabled search query reveals the button and coordinated input/arrow layout; clearing both restores the normal layout for single/multi-select and LTR/RTL configurations. This describes the runtime behavior, not exhaustive Vanilla integration certification.
|
|
442
531
|
|
|
443
532
|
Use full config passthrough when a permanently visible disabled-when-empty action is intentional:
|
|
444
533
|
|
|
445
534
|
```typescript
|
|
535
|
+
import '@smilodon/core';
|
|
536
|
+
import { createSelect } from '@smilodon/vanilla';
|
|
537
|
+
|
|
538
|
+
const items = [{ value: 'selected', label: 'Selected item' }];
|
|
446
539
|
const select = createSelect({
|
|
447
540
|
items,
|
|
448
541
|
clearable: true,
|
|
@@ -455,10 +548,14 @@ const select = createSelect({
|
|
|
455
548
|
### With Event Listeners
|
|
456
549
|
|
|
457
550
|
```typescript
|
|
551
|
+
import '@smilodon/core';
|
|
458
552
|
import { createSelect } from '@smilodon/vanilla';
|
|
459
553
|
|
|
460
554
|
const select = createSelect({
|
|
461
|
-
items: [
|
|
555
|
+
items: [
|
|
556
|
+
{ value: 'first', label: 'First option' },
|
|
557
|
+
{ value: 'second', label: 'Second option' },
|
|
558
|
+
],
|
|
462
559
|
onChange: (value, items) => {
|
|
463
560
|
console.log('Value changed:', value);
|
|
464
561
|
console.log('Selected items:', items);
|
|
@@ -477,16 +574,19 @@ const select = createSelect({
|
|
|
477
574
|
}
|
|
478
575
|
});
|
|
479
576
|
|
|
480
|
-
document.
|
|
577
|
+
document.body.appendChild(select);
|
|
481
578
|
```
|
|
482
579
|
|
|
483
580
|
### Custom Styling
|
|
484
581
|
|
|
485
582
|
```typescript
|
|
583
|
+
import '@smilodon/core';
|
|
486
584
|
import { createSelect } from '@smilodon/vanilla';
|
|
487
585
|
|
|
488
586
|
const select = createSelect({
|
|
489
|
-
items: [
|
|
587
|
+
items: [
|
|
588
|
+
{ value: 'custom', label: 'Custom styled option' },
|
|
589
|
+
],
|
|
490
590
|
className: 'my-custom-select',
|
|
491
591
|
style: {
|
|
492
592
|
width: '300px',
|
|
@@ -494,7 +594,7 @@ const select = createSelect({
|
|
|
494
594
|
}
|
|
495
595
|
});
|
|
496
596
|
|
|
497
|
-
document.
|
|
597
|
+
document.body.appendChild(select);
|
|
498
598
|
```
|
|
499
599
|
|
|
500
600
|
```css
|
|
@@ -528,11 +628,14 @@ Creates and returns a new select element.
|
|
|
528
628
|
| `error` | `boolean` | `false` | Show error state |
|
|
529
629
|
| `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
|
|
530
630
|
| `pageSize` | `number` | `50` | Items per page |
|
|
531
|
-
| `virtualized` | `boolean` | `
|
|
631
|
+
| `virtualized` | `boolean` | `false` | Enable legacy chunked rendering for large flat lists; not viewport windowing |
|
|
532
632
|
| `maxSelections` | `number` | `undefined` | Max selections |
|
|
533
633
|
| `placement` | `'bottom' \| 'top' \| 'auto'` | `'auto'` | Dropdown placement |
|
|
534
634
|
| `className` | `string` | `''` | Custom CSS class |
|
|
535
|
-
| `style` | `CSSStyleDeclaration
|
|
635
|
+
| `style` | `Partial<CSSStyleDeclaration>` | `{}` | Inline host-element styles |
|
|
636
|
+
| `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config` | core configuration types | - | Shared runtime configuration groups |
|
|
637
|
+
| `direction`, `removeButtonIcon`, `disabledOptionBehavior`, `showSelectedIndicator` | documented values/configs | - | Direction, chip, and option-state settings |
|
|
638
|
+
| `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, `clearIcon` | booleans / strings | - | Clear-control configuration |
|
|
536
639
|
| `onChange` | `(value, items) => void` | `undefined` | Change callback |
|
|
537
640
|
| `onSelect` | `(item, index) => void` | `undefined` | Select callback |
|
|
538
641
|
| `onOpen` | `() => void` | `undefined` | Open callback |
|
|
@@ -540,6 +643,9 @@ Creates and returns a new select element.
|
|
|
540
643
|
| `onSearch` | `(query) => void` | `undefined` | Search callback |
|
|
541
644
|
| `onLoadMore` | `(page) => void` | `undefined` | Load more callback |
|
|
542
645
|
| `onCreate` | `(value) => void` | `undefined` | Create callback |
|
|
646
|
+
| `onClear` | `(detail) => void` | `undefined` | Clear result callback |
|
|
647
|
+
| `onDiagnostic` | `(detail) => void` | `undefined` | Diagnostic callback |
|
|
648
|
+
| `trackingEnabled`, `trackEvents`, `trackStyling`, `trackLimitations`, `emitDiagnostics`, `trackingMaxEntries`, `limitationPolicies`, `autoMitigateRuntimeModeSwitch` | tracking/policy types | - | Diagnostic and limitation controls |
|
|
543
649
|
|
|
544
650
|
**Returns:** `HTMLElement`
|
|
545
651
|
|
|
@@ -548,8 +654,8 @@ Creates and returns a new select element.
|
|
|
548
654
|
Initialize an existing select element in the DOM.
|
|
549
655
|
|
|
550
656
|
**Parameters:**
|
|
551
|
-
- `element: HTMLElement` -
|
|
552
|
-
- `options
|
|
657
|
+
- `element: HTMLElement` - An `enhanced-select` host whose custom-element definition has already loaded and upgraded.
|
|
658
|
+
- `options` - `initSelect` accepts `items`, Vanilla-shaped `groupedItems`, `value`, `multiple`, `searchable`, `placeholder`, `disabled`, `infiniteScroll`, `pageSize`, `virtualized`, `maxSelections`, `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config`, `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, and `clearIcon`. It does not accept the callbacks, `className`, `style`, or diagnostics options available on `createSelect`.
|
|
553
659
|
|
|
554
660
|
### `getValue(element)`
|
|
555
661
|
|
|
@@ -630,6 +736,8 @@ enhanced-select {
|
|
|
630
736
|
|
|
631
737
|
## Browser Support
|
|
632
738
|
|
|
739
|
+
The versions listed below are repository compatibility targets, not browser versions certified by the current Phase 4 matrix. The completed scoped matrix uses current pinned Chromium, Firefox, and WebKit builds; see the [browser support policy](../../docs/compliance/BROWSER-SUPPORT.md) for declared targets.
|
|
740
|
+
|
|
633
741
|
- Chrome/Edge 90+
|
|
634
742
|
- Firefox 88+
|
|
635
743
|
- Safari 14+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smilodon/vanilla",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Vanilla JavaScript helpers for Smilodon Select - part of the Smilodon UI toolkit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@smilodon/core": "^1.
|
|
27
|
+
"@smilodon/core": "^1.10.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"typescript": "^5.6.2",
|