@smilodon/vanilla 1.4.10 → 1.8.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 +1255 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +90 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,1255 @@
|
|
|
1
|
+
# @smilodon/vanilla - Complete Guide
|
|
2
|
+
|
|
3
|
+
**Production-ready, accessible Select component for Vanilla JavaScript applications**
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Installation & Setup](#installation--setup)
|
|
12
|
+
2. [Basic Usage](#basic-usage)
|
|
13
|
+
3. [Complete API Reference](#complete-api-reference)
|
|
14
|
+
4. [Input Formats](#input-formats)
|
|
15
|
+
5. [Single Selection](#single-selection)
|
|
16
|
+
6. [Multi-Selection](#multi-selection)
|
|
17
|
+
7. [Searchable Select](#searchable-select)
|
|
18
|
+
8. [Grouped Options](#grouped-options)
|
|
19
|
+
9. [Disabled States](#disabled-states)
|
|
20
|
+
10. [Event Handling](#event-handling)
|
|
21
|
+
11. [Styling & Theming](#styling--theming)
|
|
22
|
+
12. [Custom Renderers](#custom-renderers)
|
|
23
|
+
13. [Performance Optimization](#performance-optimization)
|
|
24
|
+
14. [DOM Manipulation](#dom-manipulation)
|
|
25
|
+
15. [Accessibility](#accessibility)
|
|
26
|
+
16. [Advanced Patterns](#advanced-patterns)
|
|
27
|
+
17. [Troubleshooting](#troubleshooting)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Installation & Setup
|
|
32
|
+
|
|
33
|
+
### Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @smilodon/core
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
or with yarn:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
yarn add @smilodon/core
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
or with pnpm:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pnpm add @smilodon/core
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### CDN Usage (No Build Step)
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<!DOCTYPE html>
|
|
55
|
+
<html>
|
|
56
|
+
<head>
|
|
57
|
+
<title>Smilodon Select</title>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<enhanced-select id="my-select"></enhanced-select>
|
|
61
|
+
|
|
62
|
+
<script type="module">
|
|
63
|
+
import '@smilodon/core';
|
|
64
|
+
|
|
65
|
+
const select = document.getElementById('my-select');
|
|
66
|
+
select.items = ['Apple', 'Banana', 'Cherry'];
|
|
67
|
+
|
|
68
|
+
select.addEventListener('change', (e) => {
|
|
69
|
+
console.log('Selected:', e.detail);
|
|
70
|
+
});
|
|
71
|
+
</script>
|
|
72
|
+
</body>
|
|
73
|
+
</html>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Module Import
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
import '@smilodon/core';
|
|
80
|
+
|
|
81
|
+
// Component is now registered as <enhanced-select>
|
|
82
|
+
const select = document.querySelector('enhanced-select');
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Basic Usage
|
|
88
|
+
|
|
89
|
+
### Minimal Example
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<!DOCTYPE html>
|
|
93
|
+
<html>
|
|
94
|
+
<head>
|
|
95
|
+
<script type="module">
|
|
96
|
+
import '@smilodon/core';
|
|
97
|
+
</script>
|
|
98
|
+
</head>
|
|
99
|
+
<body>
|
|
100
|
+
<enhanced-select id="my-select"></enhanced-select>
|
|
101
|
+
|
|
102
|
+
<script type="module">
|
|
103
|
+
const select = document.getElementById('my-select');
|
|
104
|
+
select.items = ['Apple', 'Banana', 'Cherry'];
|
|
105
|
+
|
|
106
|
+
select.addEventListener('change', (event) => {
|
|
107
|
+
console.log('Selected:', event.detail.value);
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### With Object Array
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
import '@smilodon/core';
|
|
118
|
+
|
|
119
|
+
const select = document.querySelector('enhanced-select');
|
|
120
|
+
|
|
121
|
+
select.items = [
|
|
122
|
+
{ value: 'apple', label: 'Apple' },
|
|
123
|
+
{ value: 'banana', label: 'Banana' },
|
|
124
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
select.placeholder = 'Select a fruit...';
|
|
128
|
+
|
|
129
|
+
select.addEventListener('change', (event) => {
|
|
130
|
+
document.getElementById('result').textContent =
|
|
131
|
+
`Selected: ${event.detail.value}`;
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Complete API Reference
|
|
138
|
+
|
|
139
|
+
### Properties
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
// Get/Set items
|
|
143
|
+
select.items = [{ value: '1', label: 'Option 1' }];
|
|
144
|
+
console.log(select.items); // Array of items
|
|
145
|
+
|
|
146
|
+
// Get/Set value
|
|
147
|
+
select.value = 'apple';
|
|
148
|
+
console.log(select.value); // 'apple'
|
|
149
|
+
|
|
150
|
+
// Get/Set multiple values (multi-select)
|
|
151
|
+
select.selectedValues = ['apple', 'banana'];
|
|
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
|
|
163
|
+
|
|
164
|
+
// Advanced properties
|
|
165
|
+
select.virtualization = true; // Enable virtual scrolling (default: true)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Methods
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
// Open/close dropdown
|
|
172
|
+
select.open();
|
|
173
|
+
select.close();
|
|
174
|
+
select.toggle();
|
|
175
|
+
|
|
176
|
+
// Check if open
|
|
177
|
+
const isOpen = select.isOpen();
|
|
178
|
+
|
|
179
|
+
// Clear selection
|
|
180
|
+
select.clearSelection();
|
|
181
|
+
|
|
182
|
+
// Select all (multi-select only)
|
|
183
|
+
if (select.multiple) {
|
|
184
|
+
select.selectAll();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Scroll to specific index
|
|
188
|
+
select.scrollToIndex(10, 'smooth');
|
|
189
|
+
|
|
190
|
+
// Get selected items (returns array)
|
|
191
|
+
const selectedItems = select.getSelectedItems();
|
|
192
|
+
|
|
193
|
+
// Set selected values
|
|
194
|
+
select.setSelectedValues(['apple', 'banana']);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Events
|
|
198
|
+
|
|
199
|
+
```javascript
|
|
200
|
+
// Selection changed
|
|
201
|
+
select.addEventListener('change', (event) => {
|
|
202
|
+
console.log('Value:', event.detail.value);
|
|
203
|
+
console.log('Label:', event.detail.label);
|
|
204
|
+
console.log('Selected items:', event.detail.selectedItems);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Dropdown opened
|
|
208
|
+
select.addEventListener('open', () => {
|
|
209
|
+
console.log('Dropdown opened');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Dropdown closed
|
|
213
|
+
select.addEventListener('close', () => {
|
|
214
|
+
console.log('Dropdown closed');
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Search query changed
|
|
218
|
+
select.addEventListener('search', (event) => {
|
|
219
|
+
console.log('Search query:', event.detail.query);
|
|
220
|
+
});
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Attributes
|
|
224
|
+
|
|
225
|
+
```html
|
|
226
|
+
<!-- Use HTML attributes for initial configuration -->
|
|
227
|
+
<enhanced-select
|
|
228
|
+
placeholder="Choose an option"
|
|
229
|
+
searchable
|
|
230
|
+
multiple
|
|
231
|
+
disabled
|
|
232
|
+
max-height="400"
|
|
233
|
+
estimated-item-height="60"
|
|
234
|
+
></enhanced-select>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Input Formats
|
|
240
|
+
|
|
241
|
+
Smilodon accepts three input formats for maximum flexibility:
|
|
242
|
+
|
|
243
|
+
### 1. Object Array (SelectItem[])
|
|
244
|
+
|
|
245
|
+
```javascript
|
|
246
|
+
select.items = [
|
|
247
|
+
{ value: 'us', label: 'United States' },
|
|
248
|
+
{ value: 'ca', label: 'Canada' },
|
|
249
|
+
{ value: 'mx', label: 'Mexico' },
|
|
250
|
+
];
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 2. String Array (Auto-converted)
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
select.items = ['Apple', 'Banana', 'Cherry', 'Date'];
|
|
257
|
+
|
|
258
|
+
// Automatically converted to:
|
|
259
|
+
// [
|
|
260
|
+
// { value: 'Apple', label: 'Apple' },
|
|
261
|
+
// { value: 'Banana', label: 'Banana' },
|
|
262
|
+
// { value: 'Cherry', label: 'Cherry' },
|
|
263
|
+
// { value: 'Date', label: 'Date' },
|
|
264
|
+
// ]
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 3. Number Array (Auto-converted)
|
|
268
|
+
|
|
269
|
+
```javascript
|
|
270
|
+
select.items = [1, 2, 3, 5, 8, 13, 21];
|
|
271
|
+
|
|
272
|
+
// Automatically converted to:
|
|
273
|
+
// [
|
|
274
|
+
// { value: 1, label: '1' },
|
|
275
|
+
// { value: 2, label: '2' },
|
|
276
|
+
// { value: 3, label: '3' },
|
|
277
|
+
// ...
|
|
278
|
+
// ]
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Single Selection
|
|
284
|
+
|
|
285
|
+
### Basic Single Select
|
|
286
|
+
|
|
287
|
+
```html
|
|
288
|
+
<div>
|
|
289
|
+
<label for="country-select">Country:</label>
|
|
290
|
+
<enhanced-select id="country-select"></enhanced-select>
|
|
291
|
+
<p id="result"></p>
|
|
292
|
+
</div>
|
|
293
|
+
|
|
294
|
+
<script type="module">
|
|
295
|
+
import '@smilodon/core';
|
|
296
|
+
|
|
297
|
+
const select = document.getElementById('country-select');
|
|
298
|
+
|
|
299
|
+
select.items = [
|
|
300
|
+
{ value: 'us', label: 'United States' },
|
|
301
|
+
{ value: 'ca', label: 'Canada' },
|
|
302
|
+
{ value: 'uk', label: 'United Kingdom' },
|
|
303
|
+
{ value: 'au', label: 'Australia' },
|
|
304
|
+
];
|
|
305
|
+
|
|
306
|
+
select.placeholder = 'Select your country';
|
|
307
|
+
|
|
308
|
+
select.addEventListener('change', (event) => {
|
|
309
|
+
document.getElementById('result').textContent =
|
|
310
|
+
`Selected: ${event.detail.value}`;
|
|
311
|
+
});
|
|
312
|
+
</script>
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### With Form Integration
|
|
316
|
+
|
|
317
|
+
```html
|
|
318
|
+
<form id="user-form">
|
|
319
|
+
<div>
|
|
320
|
+
<label for="name">Name:</label>
|
|
321
|
+
<input type="text" id="name" name="name" />
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
<div>
|
|
325
|
+
<label for="country">Country:</label>
|
|
326
|
+
<enhanced-select id="country" name="country"></enhanced-select>
|
|
327
|
+
</div>
|
|
328
|
+
|
|
329
|
+
<div>
|
|
330
|
+
<label for="language">Language:</label>
|
|
331
|
+
<enhanced-select id="language" name="language"></enhanced-select>
|
|
332
|
+
</div>
|
|
333
|
+
|
|
334
|
+
<button type="submit">Submit</button>
|
|
335
|
+
</form>
|
|
336
|
+
|
|
337
|
+
<script type="module">
|
|
338
|
+
import '@smilodon/core';
|
|
339
|
+
|
|
340
|
+
const countrySelect = document.getElementById('country');
|
|
341
|
+
const languageSelect = document.getElementById('language');
|
|
342
|
+
const form = document.getElementById('user-form');
|
|
343
|
+
|
|
344
|
+
countrySelect.items = ['USA', 'Canada', 'Mexico', 'UK', 'Australia'];
|
|
345
|
+
languageSelect.items = ['English', 'Spanish', 'French', 'German'];
|
|
346
|
+
|
|
347
|
+
form.addEventListener('submit', (e) => {
|
|
348
|
+
e.preventDefault();
|
|
349
|
+
|
|
350
|
+
const formData = {
|
|
351
|
+
name: document.getElementById('name').value,
|
|
352
|
+
country: countrySelect.value,
|
|
353
|
+
language: languageSelect.value,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
console.log('Form data:', formData);
|
|
357
|
+
});
|
|
358
|
+
</script>
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Multi-Selection
|
|
364
|
+
|
|
365
|
+
### Basic Multi-Select
|
|
366
|
+
|
|
367
|
+
```html
|
|
368
|
+
<div>
|
|
369
|
+
<enhanced-select id="languages-select" multiple></enhanced-select>
|
|
370
|
+
<div id="selected-list"></div>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<script type="module">
|
|
374
|
+
import '@smilodon/core';
|
|
375
|
+
|
|
376
|
+
const select = document.getElementById('languages-select');
|
|
377
|
+
|
|
378
|
+
select.items = [
|
|
379
|
+
{ value: 'js', label: 'JavaScript' },
|
|
380
|
+
{ value: 'ts', label: 'TypeScript' },
|
|
381
|
+
{ value: 'py', label: 'Python' },
|
|
382
|
+
{ value: 'rs', label: 'Rust' },
|
|
383
|
+
{ value: 'go', label: 'Go' },
|
|
384
|
+
];
|
|
385
|
+
|
|
386
|
+
select.placeholder = 'Select programming languages';
|
|
387
|
+
|
|
388
|
+
select.addEventListener('change', (event) => {
|
|
389
|
+
const values = event.detail.selectedValues || [];
|
|
390
|
+
const listEl = document.getElementById('selected-list');
|
|
391
|
+
|
|
392
|
+
if (values.length > 0) {
|
|
393
|
+
listEl.innerHTML = `
|
|
394
|
+
<strong>Selected (${values.length}):</strong>
|
|
395
|
+
<ul>${values.map(v => `<li>${v}</li>`).join('')}</ul>
|
|
396
|
+
`;
|
|
397
|
+
} else {
|
|
398
|
+
listEl.innerHTML = '<p>No languages selected</p>';
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
</script>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Multi-Select with Limit
|
|
405
|
+
|
|
406
|
+
```html
|
|
407
|
+
<div>
|
|
408
|
+
<enhanced-select id="colors-select" multiple></enhanced-select>
|
|
409
|
+
<p id="count-display"></p>
|
|
410
|
+
</div>
|
|
411
|
+
|
|
412
|
+
<script type="module">
|
|
413
|
+
import '@smilodon/core';
|
|
414
|
+
|
|
415
|
+
const select = document.getElementById('colors-select');
|
|
416
|
+
const maxSelections = 3;
|
|
417
|
+
|
|
418
|
+
select.items = ['Red', 'Blue', 'Green', 'Yellow', 'Purple', 'Orange'];
|
|
419
|
+
select.placeholder = `Select up to ${maxSelections} colors`;
|
|
420
|
+
|
|
421
|
+
select.addEventListener('change', (event) => {
|
|
422
|
+
const values = event.detail.selectedValues || [];
|
|
423
|
+
|
|
424
|
+
if (values.length > maxSelections) {
|
|
425
|
+
// Trim to max selections
|
|
426
|
+
select.setSelectedValues(values.slice(0, maxSelections));
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
document.getElementById('count-display').textContent =
|
|
430
|
+
`${values.length} / ${maxSelections} selected`;
|
|
431
|
+
});
|
|
432
|
+
</script>
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## Searchable Select
|
|
438
|
+
|
|
439
|
+
### Basic Search
|
|
440
|
+
|
|
441
|
+
```html
|
|
442
|
+
<enhanced-select id="country-search" searchable></enhanced-select>
|
|
443
|
+
|
|
444
|
+
<script type="module">
|
|
445
|
+
import '@smilodon/core';
|
|
446
|
+
|
|
447
|
+
const select = document.getElementById('country-search');
|
|
448
|
+
|
|
449
|
+
// Large dataset (200+ countries)
|
|
450
|
+
select.items = [
|
|
451
|
+
{ value: 'us', label: 'United States' },
|
|
452
|
+
{ value: 'ca', label: 'Canada' },
|
|
453
|
+
{ value: 'mx', label: 'Mexico' },
|
|
454
|
+
{ value: 'br', label: 'Brazil' },
|
|
455
|
+
{ value: 'ar', label: 'Argentina' },
|
|
456
|
+
// ... 200+ more
|
|
457
|
+
];
|
|
458
|
+
|
|
459
|
+
select.placeholder = 'Search for a country...';
|
|
460
|
+
</script>
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### Search with Event Handler
|
|
464
|
+
|
|
465
|
+
```html
|
|
466
|
+
<div>
|
|
467
|
+
<enhanced-select id="fruit-search" searchable></enhanced-select>
|
|
468
|
+
<p id="search-query"></p>
|
|
469
|
+
</div>
|
|
470
|
+
|
|
471
|
+
<script type="module">
|
|
472
|
+
import '@smilodon/core';
|
|
473
|
+
|
|
474
|
+
const select = document.getElementById('fruit-search');
|
|
475
|
+
|
|
476
|
+
select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
|
|
477
|
+
select.placeholder = 'Type to search...';
|
|
478
|
+
|
|
479
|
+
select.addEventListener('search', (event) => {
|
|
480
|
+
const query = event.detail.query;
|
|
481
|
+
document.getElementById('search-query').textContent =
|
|
482
|
+
query ? `Current search: ${query}` : '';
|
|
483
|
+
|
|
484
|
+
// Optionally trigger API call, analytics, etc.
|
|
485
|
+
console.log('Searching for:', query);
|
|
486
|
+
});
|
|
487
|
+
</script>
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
---
|
|
491
|
+
|
|
492
|
+
## Grouped Options
|
|
493
|
+
|
|
494
|
+
### Basic Groups
|
|
495
|
+
|
|
496
|
+
```html
|
|
497
|
+
<enhanced-select id="food-select"></enhanced-select>
|
|
498
|
+
|
|
499
|
+
<script type="module">
|
|
500
|
+
import '@smilodon/core';
|
|
501
|
+
|
|
502
|
+
const select = document.getElementById('food-select');
|
|
503
|
+
|
|
504
|
+
select.items = [
|
|
505
|
+
// Fruits group
|
|
506
|
+
{ value: 'apple', label: 'Apple', group: 'Fruits' },
|
|
507
|
+
{ value: 'banana', label: 'Banana', group: 'Fruits' },
|
|
508
|
+
{ value: 'cherry', label: 'Cherry', group: 'Fruits' },
|
|
509
|
+
|
|
510
|
+
// Vegetables group
|
|
511
|
+
{ value: 'carrot', label: 'Carrot', group: 'Vegetables' },
|
|
512
|
+
{ value: 'broccoli', label: 'Broccoli', group: 'Vegetables' },
|
|
513
|
+
{ value: 'spinach', label: 'Spinach', group: 'Vegetables' },
|
|
514
|
+
];
|
|
515
|
+
|
|
516
|
+
select.placeholder = 'Select food...';
|
|
517
|
+
</script>
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Complex Grouped Structure
|
|
521
|
+
|
|
522
|
+
```html
|
|
523
|
+
<enhanced-select id="tech-select" searchable></enhanced-select>
|
|
524
|
+
|
|
525
|
+
<script type="module">
|
|
526
|
+
import '@smilodon/core';
|
|
527
|
+
|
|
528
|
+
const select = document.getElementById('tech-select');
|
|
529
|
+
|
|
530
|
+
select.items = [
|
|
531
|
+
// Frontend
|
|
532
|
+
{ value: 'react', label: 'React', group: 'Frontend' },
|
|
533
|
+
{ value: 'vue', label: 'Vue.js', group: 'Frontend' },
|
|
534
|
+
{ value: 'svelte', label: 'Svelte', group: 'Frontend' },
|
|
535
|
+
|
|
536
|
+
// Backend
|
|
537
|
+
{ value: 'node', label: 'Node.js', group: 'Backend' },
|
|
538
|
+
{ value: 'django', label: 'Django', group: 'Backend' },
|
|
539
|
+
{ value: 'rails', label: 'Ruby on Rails', group: 'Backend' },
|
|
540
|
+
|
|
541
|
+
// Database
|
|
542
|
+
{ value: 'postgres', label: 'PostgreSQL', group: 'Database' },
|
|
543
|
+
{ value: 'mongo', label: 'MongoDB', group: 'Database' },
|
|
544
|
+
{ value: 'redis', label: 'Redis', group: 'Database' },
|
|
545
|
+
];
|
|
546
|
+
|
|
547
|
+
select.placeholder = 'Select technology...';
|
|
548
|
+
</script>
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
## Disabled States
|
|
554
|
+
|
|
555
|
+
### Disabled Select
|
|
556
|
+
|
|
557
|
+
```html
|
|
558
|
+
<enhanced-select id="disabled-select" disabled></enhanced-select>
|
|
559
|
+
|
|
560
|
+
<script type="module">
|
|
561
|
+
import '@smilodon/core';
|
|
562
|
+
|
|
563
|
+
const select = document.getElementById('disabled-select');
|
|
564
|
+
select.items = ['Option 1', 'Option 2', 'Option 3'];
|
|
565
|
+
select.placeholder = 'This select is disabled';
|
|
566
|
+
</script>
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### Disabled Options
|
|
570
|
+
|
|
571
|
+
```html
|
|
572
|
+
<enhanced-select id="partial-disabled"></enhanced-select>
|
|
573
|
+
|
|
574
|
+
<script type="module">
|
|
575
|
+
import '@smilodon/core';
|
|
576
|
+
|
|
577
|
+
const select = document.getElementById('partial-disabled');
|
|
578
|
+
|
|
579
|
+
select.items = [
|
|
580
|
+
{ value: '1', label: 'Available Option 1' },
|
|
581
|
+
{ value: '2', label: 'Available Option 2' },
|
|
582
|
+
{ value: '3', label: 'Disabled Option', disabled: true },
|
|
583
|
+
{ value: '4', label: 'Available Option 3' },
|
|
584
|
+
{ value: '5', label: 'Disabled Option 2', disabled: true },
|
|
585
|
+
];
|
|
586
|
+
|
|
587
|
+
select.placeholder = 'Some options are disabled';
|
|
588
|
+
</script>
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
### Conditional Disabling
|
|
592
|
+
|
|
593
|
+
```html
|
|
594
|
+
<div>
|
|
595
|
+
<enhanced-select id="loading-select"></enhanced-select>
|
|
596
|
+
<p id="loading-status"></p>
|
|
597
|
+
</div>
|
|
598
|
+
|
|
599
|
+
<script type="module">
|
|
600
|
+
import '@smilodon/core';
|
|
601
|
+
|
|
602
|
+
const select = document.getElementById('loading-select');
|
|
603
|
+
const statusEl = document.getElementById('loading-status');
|
|
604
|
+
|
|
605
|
+
select.items = ['Option 1', 'Option 2', 'Option 3'];
|
|
606
|
+
select.placeholder = 'Select an option';
|
|
607
|
+
|
|
608
|
+
select.addEventListener('change', async (event) => {
|
|
609
|
+
select.disabled = true;
|
|
610
|
+
select.placeholder = 'Loading...';
|
|
611
|
+
statusEl.textContent = 'Processing selection...';
|
|
612
|
+
|
|
613
|
+
// Simulate API call
|
|
614
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
615
|
+
|
|
616
|
+
select.disabled = false;
|
|
617
|
+
select.placeholder = 'Select an option';
|
|
618
|
+
statusEl.textContent = '';
|
|
619
|
+
});
|
|
620
|
+
</script>
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
## Event Handling
|
|
626
|
+
|
|
627
|
+
### All Events
|
|
628
|
+
|
|
629
|
+
```html
|
|
630
|
+
<div>
|
|
631
|
+
<enhanced-select id="event-select"></enhanced-select>
|
|
632
|
+
<div>
|
|
633
|
+
<p>Current value: <span id="current-value">None</span></p>
|
|
634
|
+
<p>Dropdown is: <span id="dropdown-status">Closed</span></p>
|
|
635
|
+
</div>
|
|
636
|
+
<div>
|
|
637
|
+
<strong>Event Log:</strong>
|
|
638
|
+
<ul id="event-log" style="max-height: 200px; overflow: auto;"></ul>
|
|
639
|
+
</div>
|
|
640
|
+
</div>
|
|
641
|
+
|
|
642
|
+
<script type="module">
|
|
643
|
+
import '@smilodon/core';
|
|
644
|
+
|
|
645
|
+
const select = document.getElementById('event-select');
|
|
646
|
+
const logEl = document.getElementById('event-log');
|
|
647
|
+
|
|
648
|
+
select.items = ['Apple', 'Banana', 'Cherry'];
|
|
649
|
+
select.placeholder = 'Select a fruit';
|
|
650
|
+
|
|
651
|
+
function addLog(message) {
|
|
652
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
653
|
+
const li = document.createElement('li');
|
|
654
|
+
li.textContent = `[${timestamp}] ${message}`;
|
|
655
|
+
logEl.appendChild(li);
|
|
656
|
+
logEl.scrollTop = logEl.scrollHeight;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
select.addEventListener('change', (event) => {
|
|
660
|
+
const value = event.detail.value;
|
|
661
|
+
document.getElementById('current-value').textContent = value || 'None';
|
|
662
|
+
addLog(`Changed to: ${value}`);
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
select.addEventListener('open', () => {
|
|
666
|
+
document.getElementById('dropdown-status').textContent = 'Open';
|
|
667
|
+
addLog('Dropdown opened');
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
select.addEventListener('close', () => {
|
|
671
|
+
document.getElementById('dropdown-status').textContent = 'Closed';
|
|
672
|
+
addLog('Dropdown closed');
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
select.addEventListener('search', (event) => {
|
|
676
|
+
addLog(`Searching for: ${event.detail.query}`);
|
|
677
|
+
});
|
|
678
|
+
</script>
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
---
|
|
682
|
+
|
|
683
|
+
## Styling & Theming
|
|
684
|
+
|
|
685
|
+
### Inline Styles with CSS Variables
|
|
686
|
+
|
|
687
|
+
```html
|
|
688
|
+
<enhanced-select
|
|
689
|
+
id="styled-select"
|
|
690
|
+
style="
|
|
691
|
+
--select-input-border: 2px solid #3b82f6;
|
|
692
|
+
--select-input-border-radius: 8px;
|
|
693
|
+
--select-input-focus-border: #2563eb;
|
|
694
|
+
--select-option-hover-bg: #dbeafe;
|
|
695
|
+
--select-option-selected-bg: #3b82f6;
|
|
696
|
+
--select-option-selected-color: white;
|
|
697
|
+
--select-badge-bg: #3b82f6;
|
|
698
|
+
"
|
|
699
|
+
></enhanced-select>
|
|
700
|
+
|
|
701
|
+
<script type="module">
|
|
702
|
+
import '@smilodon/core';
|
|
703
|
+
|
|
704
|
+
const select = document.getElementById('styled-select');
|
|
705
|
+
select.items = ['Red', 'Blue', 'Green'];
|
|
706
|
+
</script>
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### Dynamic Styling with JavaScript
|
|
710
|
+
|
|
711
|
+
```html
|
|
712
|
+
<enhanced-select id="dynamic-select"></enhanced-select>
|
|
713
|
+
|
|
714
|
+
<script type="module">
|
|
715
|
+
import '@smilodon/core';
|
|
716
|
+
|
|
717
|
+
const select = document.getElementById('dynamic-select');
|
|
718
|
+
select.items = ['Option 1', 'Option 2', 'Option 3'];
|
|
719
|
+
|
|
720
|
+
// Set CSS variables dynamically
|
|
721
|
+
select.style.setProperty('--select-input-border', '2px solid #10b981');
|
|
722
|
+
select.style.setProperty('--select-input-border-radius', '12px');
|
|
723
|
+
select.style.setProperty('--select-option-hover-bg', '#d1fae5');
|
|
724
|
+
select.style.setProperty('--select-option-selected-bg', '#10b981');
|
|
725
|
+
select.style.setProperty('--select-option-selected-color', 'white');
|
|
726
|
+
select.style.setProperty('--select-badge-bg', '#10b981');
|
|
727
|
+
select.style.setProperty('--select-separator-gradient',
|
|
728
|
+
'linear-gradient(to bottom, transparent 0%, #10b981 20%, #10b981 80%, transparent 100%)'
|
|
729
|
+
);
|
|
730
|
+
</script>
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
### Complete CSS Variables Reference
|
|
734
|
+
|
|
735
|
+
```css
|
|
736
|
+
/* styles.css */
|
|
737
|
+
enhanced-select {
|
|
738
|
+
/* Input Container */
|
|
739
|
+
--select-input-gap: 6px;
|
|
740
|
+
--select-input-padding: 6px 52px 6px 8px;
|
|
741
|
+
--select-input-min-height: 44px;
|
|
742
|
+
--select-input-bg: white;
|
|
743
|
+
--select-input-border: 1px solid #d1d5db;
|
|
744
|
+
--select-input-border-radius: 6px;
|
|
745
|
+
--select-input-focus-border: #667eea;
|
|
746
|
+
--select-input-focus-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
747
|
+
|
|
748
|
+
/* Input Field */
|
|
749
|
+
--select-input-min-width: 120px;
|
|
750
|
+
--select-input-field-padding: 4px;
|
|
751
|
+
--select-input-font-size: 14px;
|
|
752
|
+
--select-input-line-height: 1.5;
|
|
753
|
+
--select-input-color: #1f2937;
|
|
754
|
+
--select-input-placeholder-color: #9ca3af;
|
|
755
|
+
--select-font-family: inherit;
|
|
756
|
+
|
|
757
|
+
/* Dropdown Arrow */
|
|
758
|
+
--select-arrow-width: 40px;
|
|
759
|
+
--select-arrow-size: 16px;
|
|
760
|
+
--select-arrow-color: #667eea;
|
|
761
|
+
--select-arrow-hover-color: #667eea;
|
|
762
|
+
--select-arrow-hover-bg: rgba(102, 126, 234, 0.08);
|
|
763
|
+
--select-arrow-border-radius: 0 4px 4px 0;
|
|
764
|
+
|
|
765
|
+
/* Separator Line */
|
|
766
|
+
--select-separator-position: 40px;
|
|
767
|
+
--select-separator-width: 1px;
|
|
768
|
+
--select-separator-height: 60%;
|
|
769
|
+
--select-separator-gradient: linear-gradient(to bottom, transparent, #ccc, transparent);
|
|
770
|
+
|
|
771
|
+
/* Selection Badges (Multi-select) */
|
|
772
|
+
--select-badge-gap: 4px;
|
|
773
|
+
--select-badge-padding: 4px 8px;
|
|
774
|
+
--select-badge-margin: 2px;
|
|
775
|
+
--select-badge-bg: #667eea;
|
|
776
|
+
--select-badge-color: white;
|
|
777
|
+
--select-badge-border-radius: 4px;
|
|
778
|
+
--select-badge-font-size: 13px;
|
|
779
|
+
|
|
780
|
+
/* Badge Remove Button */
|
|
781
|
+
--select-badge-remove-size: 16px;
|
|
782
|
+
--select-badge-remove-bg: rgba(255, 255, 255, 0.3);
|
|
783
|
+
--select-badge-remove-color: white;
|
|
784
|
+
--select-badge-remove-font-size: 16px;
|
|
785
|
+
--select-badge-remove-hover-bg: rgba(255, 255, 255, 0.5);
|
|
786
|
+
|
|
787
|
+
/* Dropdown */
|
|
788
|
+
--select-dropdown-margin-top: 4px;
|
|
789
|
+
--select-dropdown-max-height: 300px;
|
|
790
|
+
--select-dropdown-border-radius: 4px;
|
|
791
|
+
--select-dropdown-bg: white;
|
|
792
|
+
--select-dropdown-border: 1px solid #ccc;
|
|
793
|
+
--select-dropdown-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
794
|
+
|
|
795
|
+
/* Options */
|
|
796
|
+
--select-options-bg: white;
|
|
797
|
+
--select-option-padding: 8px 12px;
|
|
798
|
+
--select-option-color: #1f2937;
|
|
799
|
+
--select-option-bg: white;
|
|
800
|
+
--select-option-font-size: 14px;
|
|
801
|
+
--select-option-hover-bg: #f3f4f6;
|
|
802
|
+
--select-option-selected-bg: #e0e7ff;
|
|
803
|
+
--select-option-selected-color: #4338ca;
|
|
804
|
+
}
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
### Theme Examples
|
|
808
|
+
|
|
809
|
+
#### Bootstrap Theme
|
|
810
|
+
|
|
811
|
+
```css
|
|
812
|
+
.bootstrap-select {
|
|
813
|
+
--select-input-border: 1px solid #ced4da;
|
|
814
|
+
--select-input-border-radius: 0.375rem;
|
|
815
|
+
--select-input-focus-border: #86b7fe;
|
|
816
|
+
--select-input-focus-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
|
|
817
|
+
--select-option-hover-bg: #e9ecef;
|
|
818
|
+
--select-option-selected-bg: #0d6efd;
|
|
819
|
+
--select-option-selected-color: white;
|
|
820
|
+
--select-badge-bg: #0d6efd;
|
|
821
|
+
}
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
```html
|
|
825
|
+
<enhanced-select class="bootstrap-select"></enhanced-select>
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
#### Material Design Theme
|
|
829
|
+
|
|
830
|
+
```css
|
|
831
|
+
.material-select {
|
|
832
|
+
--select-input-border-radius: 4px;
|
|
833
|
+
--select-input-focus-border: #1976d2;
|
|
834
|
+
--select-dropdown-shadow: 0 2px 4px rgba(0,0,0,0.2), 0 4px 5px rgba(0,0,0,0.14);
|
|
835
|
+
--select-option-padding: 16px;
|
|
836
|
+
--select-option-hover-bg: rgba(0, 0, 0, 0.04);
|
|
837
|
+
--select-option-selected-bg: #e3f2fd;
|
|
838
|
+
--select-option-selected-color: #1976d2;
|
|
839
|
+
--select-badge-bg: #1976d2;
|
|
840
|
+
--select-badge-border-radius: 16px;
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
#### Dark Mode Theme
|
|
845
|
+
|
|
846
|
+
```css
|
|
847
|
+
.dark-mode {
|
|
848
|
+
--select-input-bg: #1f2937;
|
|
849
|
+
--select-input-border: 1px solid #4b5563;
|
|
850
|
+
--select-input-color: #f9fafb;
|
|
851
|
+
--select-dropdown-bg: #1f2937;
|
|
852
|
+
--select-options-bg: #1f2937;
|
|
853
|
+
--select-option-color: #f9fafb;
|
|
854
|
+
--select-option-bg: #1f2937;
|
|
855
|
+
--select-option-hover-bg: #374151;
|
|
856
|
+
--select-option-selected-bg: #3730a3;
|
|
857
|
+
--select-badge-bg: #4f46e5;
|
|
858
|
+
}
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
---
|
|
862
|
+
|
|
863
|
+
## Custom Renderers
|
|
864
|
+
|
|
865
|
+
### Custom Option Renderer
|
|
866
|
+
|
|
867
|
+
```html
|
|
868
|
+
<enhanced-select id="user-select"></enhanced-select>
|
|
869
|
+
|
|
870
|
+
<script type="module">
|
|
871
|
+
import '@smilodon/core';
|
|
872
|
+
|
|
873
|
+
const select = document.getElementById('user-select');
|
|
874
|
+
|
|
875
|
+
const users = [
|
|
876
|
+
{
|
|
877
|
+
value: '1',
|
|
878
|
+
label: 'John Doe',
|
|
879
|
+
email: 'john@example.com',
|
|
880
|
+
avatar: 'https://i.pravatar.cc/150?img=1'
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
value: '2',
|
|
884
|
+
label: 'Jane Smith',
|
|
885
|
+
email: 'jane@example.com',
|
|
886
|
+
avatar: 'https://i.pravatar.cc/150?img=2'
|
|
887
|
+
},
|
|
888
|
+
];
|
|
889
|
+
|
|
890
|
+
select.items = users;
|
|
891
|
+
select.placeholder = 'Select a user';
|
|
892
|
+
select.estimatedItemHeight = 60;
|
|
893
|
+
|
|
894
|
+
// Set custom renderer
|
|
895
|
+
select.optionTemplate = (item) => `
|
|
896
|
+
<div style="display: flex; align-items: center; gap: 12px;">
|
|
897
|
+
<img
|
|
898
|
+
src="${item.avatar}"
|
|
899
|
+
alt="${item.label}"
|
|
900
|
+
style="width: 32px; height: 32px; border-radius: 50%;"
|
|
901
|
+
/>
|
|
902
|
+
<div>
|
|
903
|
+
<div style="font-weight: 500;">${item.label}</div>
|
|
904
|
+
<div style="font-size: 12px; color: #6b7280;">${item.email}</div>
|
|
905
|
+
</div>
|
|
906
|
+
</div>
|
|
907
|
+
`;
|
|
908
|
+
</script>
|
|
909
|
+
```
|
|
910
|
+
|
|
911
|
+
---
|
|
912
|
+
|
|
913
|
+
## Performance Optimization
|
|
914
|
+
|
|
915
|
+
### Virtualization for Large Datasets
|
|
916
|
+
|
|
917
|
+
```html
|
|
918
|
+
<enhanced-select id="large-dataset"></enhanced-select>
|
|
919
|
+
|
|
920
|
+
<script type="module">
|
|
921
|
+
import '@smilodon/core';
|
|
922
|
+
|
|
923
|
+
const select = document.getElementById('large-dataset');
|
|
924
|
+
|
|
925
|
+
// Generate 100,000 items
|
|
926
|
+
const items = Array.from({ length: 100_000 }, (_, i) => ({
|
|
927
|
+
value: `item-${i}`,
|
|
928
|
+
label: `Item ${i + 1}`,
|
|
929
|
+
}));
|
|
930
|
+
|
|
931
|
+
select.items = items;
|
|
932
|
+
select.virtualization = true;
|
|
933
|
+
select.estimatedItemHeight = 48;
|
|
934
|
+
select.searchable = true;
|
|
935
|
+
select.placeholder = 'Search 100k items...';
|
|
936
|
+
</script>
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
### Debounced Search
|
|
940
|
+
|
|
941
|
+
```html
|
|
942
|
+
<enhanced-select id="debounced-search" searchable></enhanced-select>
|
|
943
|
+
|
|
944
|
+
<script type="module">
|
|
945
|
+
import '@smilodon/core';
|
|
946
|
+
|
|
947
|
+
const select = document.getElementById('debounced-search');
|
|
948
|
+
select.items = generateLargeDataset();
|
|
949
|
+
|
|
950
|
+
let searchTimeout;
|
|
951
|
+
|
|
952
|
+
select.addEventListener('search', (event) => {
|
|
953
|
+
clearTimeout(searchTimeout);
|
|
954
|
+
|
|
955
|
+
searchTimeout = setTimeout(() => {
|
|
956
|
+
const query = event.detail.query;
|
|
957
|
+
// Perform expensive search operation
|
|
958
|
+
console.log('Searching for:', query);
|
|
959
|
+
}, 300); // 300ms debounce
|
|
960
|
+
});
|
|
961
|
+
</script>
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
---
|
|
965
|
+
|
|
966
|
+
## DOM Manipulation
|
|
967
|
+
|
|
968
|
+
### Dynamic Item Updates
|
|
969
|
+
|
|
970
|
+
```html
|
|
971
|
+
<div>
|
|
972
|
+
<button id="add-item">Add Item</button>
|
|
973
|
+
<button id="remove-item">Remove Last Item</button>
|
|
974
|
+
<enhanced-select id="dynamic-select"></enhanced-select>
|
|
975
|
+
</div>
|
|
976
|
+
|
|
977
|
+
<script type="module">
|
|
978
|
+
import '@smilodon/core';
|
|
979
|
+
|
|
980
|
+
const select = document.getElementById('dynamic-select');
|
|
981
|
+
let items = ['Item 1', 'Item 2', 'Item 3'];
|
|
982
|
+
|
|
983
|
+
select.items = items;
|
|
984
|
+
|
|
985
|
+
document.getElementById('add-item').addEventListener('click', () => {
|
|
986
|
+
const newItem = `Item ${items.length + 1}`;
|
|
987
|
+
items = [...items, newItem];
|
|
988
|
+
select.items = items;
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
document.getElementById('remove-item').addEventListener('click', () => {
|
|
992
|
+
if (items.length > 0) {
|
|
993
|
+
items = items.slice(0, -1);
|
|
994
|
+
select.items = items;
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
</script>
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
### Programmatic Control
|
|
1001
|
+
|
|
1002
|
+
```html
|
|
1003
|
+
<div>
|
|
1004
|
+
<button id="open-btn">Open Dropdown</button>
|
|
1005
|
+
<button id="close-btn">Close Dropdown</button>
|
|
1006
|
+
<button id="clear-btn">Clear Selection</button>
|
|
1007
|
+
<button id="select-all-btn">Select All</button>
|
|
1008
|
+
<enhanced-select id="controlled-select" multiple></enhanced-select>
|
|
1009
|
+
</div>
|
|
1010
|
+
|
|
1011
|
+
<script type="module">
|
|
1012
|
+
import '@smilodon/core';
|
|
1013
|
+
|
|
1014
|
+
const select = document.getElementById('controlled-select');
|
|
1015
|
+
select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
|
|
1016
|
+
|
|
1017
|
+
document.getElementById('open-btn').addEventListener('click', () => {
|
|
1018
|
+
select.open();
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
document.getElementById('close-btn').addEventListener('click', () => {
|
|
1022
|
+
select.close();
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
document.getElementById('clear-btn').addEventListener('click', () => {
|
|
1026
|
+
select.clearSelection();
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
document.getElementById('select-all-btn').addEventListener('click', () => {
|
|
1030
|
+
select.selectAll();
|
|
1031
|
+
});
|
|
1032
|
+
</script>
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
---
|
|
1036
|
+
|
|
1037
|
+
## Accessibility
|
|
1038
|
+
|
|
1039
|
+
Smilodon is WCAG 2.1 AAA compliant with full keyboard support:
|
|
1040
|
+
|
|
1041
|
+
### Keyboard Navigation
|
|
1042
|
+
|
|
1043
|
+
- **Tab** - Focus the select
|
|
1044
|
+
- **Enter/Space** - Open dropdown
|
|
1045
|
+
- **↑/↓** - Navigate options
|
|
1046
|
+
- **Home/End** - Jump to first/last option
|
|
1047
|
+
- **Escape** - Close dropdown
|
|
1048
|
+
- **Type** - Search options
|
|
1049
|
+
|
|
1050
|
+
### ARIA Attributes
|
|
1051
|
+
|
|
1052
|
+
The component automatically includes:
|
|
1053
|
+
- `role="combobox"`
|
|
1054
|
+
- `aria-expanded`
|
|
1055
|
+
- `aria-haspopup`
|
|
1056
|
+
- `aria-label` / `aria-labelledby`
|
|
1057
|
+
- `aria-activedescendant`
|
|
1058
|
+
- `aria-multiselectable` (when `multiple`)
|
|
1059
|
+
|
|
1060
|
+
### Screen Reader Support
|
|
1061
|
+
|
|
1062
|
+
```html
|
|
1063
|
+
<label id="country-label">Country</label>
|
|
1064
|
+
<enhanced-select
|
|
1065
|
+
aria-labelledby="country-label"
|
|
1066
|
+
placeholder="Select your country"
|
|
1067
|
+
></enhanced-select>
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
---
|
|
1071
|
+
|
|
1072
|
+
## Advanced Patterns
|
|
1073
|
+
|
|
1074
|
+
### Dependent Selects
|
|
1075
|
+
|
|
1076
|
+
```html
|
|
1077
|
+
<div>
|
|
1078
|
+
<label>Country:</label>
|
|
1079
|
+
<enhanced-select id="country-select"></enhanced-select>
|
|
1080
|
+
|
|
1081
|
+
<label>State:</label>
|
|
1082
|
+
<enhanced-select id="state-select" disabled></enhanced-select>
|
|
1083
|
+
</div>
|
|
1084
|
+
|
|
1085
|
+
<script type="module">
|
|
1086
|
+
import '@smilodon/core';
|
|
1087
|
+
|
|
1088
|
+
const countrySelect = document.getElementById('country-select');
|
|
1089
|
+
const stateSelect = document.getElementById('state-select');
|
|
1090
|
+
|
|
1091
|
+
countrySelect.items = ['USA', 'Canada', 'Mexico'];
|
|
1092
|
+
countrySelect.placeholder = 'Select country';
|
|
1093
|
+
|
|
1094
|
+
countrySelect.addEventListener('change', (event) => {
|
|
1095
|
+
const country = event.detail.value;
|
|
1096
|
+
|
|
1097
|
+
// Reset state selection
|
|
1098
|
+
stateSelect.clearSelection();
|
|
1099
|
+
|
|
1100
|
+
// Load states for selected country
|
|
1101
|
+
if (country === 'USA') {
|
|
1102
|
+
stateSelect.items = ['California', 'Texas', 'New York', 'Florida'];
|
|
1103
|
+
stateSelect.disabled = false;
|
|
1104
|
+
stateSelect.placeholder = 'Select state';
|
|
1105
|
+
} else if (country === 'Canada') {
|
|
1106
|
+
stateSelect.items = ['Ontario', 'Quebec', 'British Columbia'];
|
|
1107
|
+
stateSelect.disabled = false;
|
|
1108
|
+
stateSelect.placeholder = 'Select state';
|
|
1109
|
+
} else if (country === 'Mexico') {
|
|
1110
|
+
stateSelect.items = ['Mexico City', 'Jalisco', 'Nuevo León'];
|
|
1111
|
+
stateSelect.disabled = false;
|
|
1112
|
+
stateSelect.placeholder = 'Select state';
|
|
1113
|
+
} else {
|
|
1114
|
+
stateSelect.items = [];
|
|
1115
|
+
stateSelect.disabled = true;
|
|
1116
|
+
stateSelect.placeholder = 'Select country first';
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
</script>
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
### Async Data Loading
|
|
1123
|
+
|
|
1124
|
+
```html
|
|
1125
|
+
<div id="loading-container">
|
|
1126
|
+
<p>Loading options...</p>
|
|
1127
|
+
</div>
|
|
1128
|
+
<enhanced-select id="async-select" style="display: none;"></enhanced-select>
|
|
1129
|
+
|
|
1130
|
+
<script type="module">
|
|
1131
|
+
import '@smilodon/core';
|
|
1132
|
+
|
|
1133
|
+
const container = document.getElementById('loading-container');
|
|
1134
|
+
const select = document.getElementById('async-select');
|
|
1135
|
+
|
|
1136
|
+
// Simulate API call
|
|
1137
|
+
async function loadData() {
|
|
1138
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1139
|
+
|
|
1140
|
+
return [
|
|
1141
|
+
{ value: '1', label: 'Option 1' },
|
|
1142
|
+
{ value: '2', label: 'Option 2' },
|
|
1143
|
+
{ value: '3', label: 'Option 3' },
|
|
1144
|
+
];
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
loadData().then(items => {
|
|
1148
|
+
select.items = items;
|
|
1149
|
+
select.placeholder = 'Select an option';
|
|
1150
|
+
container.style.display = 'none';
|
|
1151
|
+
select.style.display = 'block';
|
|
1152
|
+
});
|
|
1153
|
+
</script>
|
|
1154
|
+
```
|
|
1155
|
+
|
|
1156
|
+
### With Local Storage
|
|
1157
|
+
|
|
1158
|
+
```html
|
|
1159
|
+
<enhanced-select id="persistent-select"></enhanced-select>
|
|
1160
|
+
|
|
1161
|
+
<script type="module">
|
|
1162
|
+
import '@smilodon/core';
|
|
1163
|
+
|
|
1164
|
+
const select = document.getElementById('persistent-select');
|
|
1165
|
+
const STORAGE_KEY = 'selected-value';
|
|
1166
|
+
|
|
1167
|
+
select.items = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];
|
|
1168
|
+
|
|
1169
|
+
// Load saved value
|
|
1170
|
+
const savedValue = localStorage.getItem(STORAGE_KEY);
|
|
1171
|
+
if (savedValue) {
|
|
1172
|
+
select.value = savedValue;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// Save on change
|
|
1176
|
+
select.addEventListener('change', (event) => {
|
|
1177
|
+
localStorage.setItem(STORAGE_KEY, event.detail.value);
|
|
1178
|
+
});
|
|
1179
|
+
</script>
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
---
|
|
1183
|
+
|
|
1184
|
+
## Troubleshooting
|
|
1185
|
+
|
|
1186
|
+
### Common Issues
|
|
1187
|
+
|
|
1188
|
+
#### Issue: Items not displaying
|
|
1189
|
+
|
|
1190
|
+
```javascript
|
|
1191
|
+
// ❌ Wrong - typo in property name
|
|
1192
|
+
select.item = ['Option 1', 'Option 2'];
|
|
1193
|
+
|
|
1194
|
+
// ✅ Correct
|
|
1195
|
+
select.items = ['Option 1', 'Option 2'];
|
|
1196
|
+
```
|
|
1197
|
+
|
|
1198
|
+
#### Issue: Event handler not firing
|
|
1199
|
+
|
|
1200
|
+
```javascript
|
|
1201
|
+
// ❌ Wrong - incorrect event name
|
|
1202
|
+
select.addEventListener('onChange', handler);
|
|
1203
|
+
|
|
1204
|
+
// ✅ Correct
|
|
1205
|
+
select.addEventListener('change', handler);
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
#### Issue: Value not updating
|
|
1209
|
+
|
|
1210
|
+
```javascript
|
|
1211
|
+
// ❌ Wrong - missing value property
|
|
1212
|
+
select.selectedValue = 'apple';
|
|
1213
|
+
|
|
1214
|
+
// ✅ Correct
|
|
1215
|
+
select.value = 'apple';
|
|
1216
|
+
// or for multi-select:
|
|
1217
|
+
select.selectedValues = ['apple', 'banana'];
|
|
1218
|
+
```
|
|
1219
|
+
|
|
1220
|
+
### Performance Issues
|
|
1221
|
+
|
|
1222
|
+
If you experience slow rendering with large datasets:
|
|
1223
|
+
|
|
1224
|
+
1. Enable virtualization (enabled by default)
|
|
1225
|
+
2. Increase `estimatedItemHeight` if items are taller than 48px
|
|
1226
|
+
3. Use debouncing for search events
|
|
1227
|
+
|
|
1228
|
+
```javascript
|
|
1229
|
+
select.virtualization = true;
|
|
1230
|
+
select.estimatedItemHeight = 60;
|
|
1231
|
+
|
|
1232
|
+
// Debounce search
|
|
1233
|
+
let searchTimeout;
|
|
1234
|
+
select.addEventListener('search', (event) => {
|
|
1235
|
+
clearTimeout(searchTimeout);
|
|
1236
|
+
searchTimeout = setTimeout(() => {
|
|
1237
|
+
// Handle search
|
|
1238
|
+
}, 300);
|
|
1239
|
+
});
|
|
1240
|
+
```
|
|
1241
|
+
|
|
1242
|
+
---
|
|
1243
|
+
|
|
1244
|
+
## Additional Resources
|
|
1245
|
+
|
|
1246
|
+
- **Core Documentation**: [packages/core/README.md](../core/README.md)
|
|
1247
|
+
- **API Reference**: [docs/API-REFERENCE.md](../../docs/API-REFERENCE.md)
|
|
1248
|
+
- **Live Examples**: [Playground](../../playground)
|
|
1249
|
+
- **GitHub Issues**: [Report a bug](https://github.com/navidrezadoost/smilodon/issues)
|
|
1250
|
+
|
|
1251
|
+
---
|
|
1252
|
+
|
|
1253
|
+
**Built with ❤️ by the Smilodon team**
|
|
1254
|
+
|
|
1255
|
+
*Last updated: February 9, 2026 - v1.3.6*
|