@smilodon/react 1.9.2 → 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 +15 -14
- package/README.md +191 -91
- package/dist/index.cjs +184 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +184 -25
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +11 -11
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
package/COMPLETE-GUIDE.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# @smilodon/react - Complete Guide
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Select component guide for React applications**
|
|
4
4
|
|
|
5
5
|
This guide provides comprehensive documentation for using Smilodon Select in React applications, covering all features, styling options, and advanced use cases.
|
|
6
6
|
|
|
7
|
+
> Capability caveat: the public `virtualized` prop 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
|
+
> Accessibility status: selected keyboard and ARIA behaviors are implemented, but pinned cross-browser verification and manual assistive-technology assessment are pending. This guide is not a WCAG conformance statement. For the maintained public API, use the [API reference](../../docs/API-REFERENCE.md) and the adapter's exported TypeScript types.
|
|
10
|
+
|
|
7
11
|
---
|
|
8
12
|
|
|
9
13
|
## Table of Contents
|
|
@@ -139,7 +143,7 @@ interface SelectProps {
|
|
|
139
143
|
style?: React.CSSProperties;
|
|
140
144
|
|
|
141
145
|
// Advanced
|
|
142
|
-
|
|
146
|
+
virtualized?: boolean;
|
|
143
147
|
customRenderer?: (item: SelectItem, index: number) => React.ReactNode;
|
|
144
148
|
|
|
145
149
|
// Events
|
|
@@ -161,10 +165,10 @@ interface SelectProps {
|
|
|
161
165
|
| `disabled` | `boolean` | `false` | Disable the select |
|
|
162
166
|
| `placeholder` | `string` | `'Select...'` | Placeholder text |
|
|
163
167
|
| `maxHeight` | `number` | `300` | Max dropdown height (px) |
|
|
164
|
-
| `estimatedItemHeight` | `number` | `48` |
|
|
168
|
+
| `estimatedItemHeight` | `number` | `48` | Passed to core config for the guarded viewport-windowing test path; it does not affect public chunk rendering |
|
|
165
169
|
| `className` | `string` | `undefined` | CSS class name |
|
|
166
170
|
| `style` | `React.CSSProperties` | `undefined` | Inline styles (CSS variables) |
|
|
167
|
-
| `
|
|
171
|
+
| `virtualized` | `boolean` | `false` | Enable incremental chunk rendering for large flat lists; not viewport windowing |
|
|
168
172
|
| `customRenderer` | `function` | `undefined` | Custom option renderer |
|
|
169
173
|
| `onOpen` | `() => void` | `undefined` | Called when dropdown opens |
|
|
170
174
|
| `onClose` | `() => void` | `undefined` | Called when dropdown closes |
|
|
@@ -940,7 +944,6 @@ function CustomRendererSelect() {
|
|
|
940
944
|
onChange={(val) => setValue(val as string)}
|
|
941
945
|
customRenderer={customRenderer}
|
|
942
946
|
placeholder="Select a user"
|
|
943
|
-
estimatedItemHeight={60}
|
|
944
947
|
/>
|
|
945
948
|
);
|
|
946
949
|
}
|
|
@@ -973,8 +976,7 @@ function LargeDataset() {
|
|
|
973
976
|
items={items}
|
|
974
977
|
value={value}
|
|
975
978
|
onChange={(val) => setValue(val as string)}
|
|
976
|
-
|
|
977
|
-
estimatedItemHeight={48}
|
|
979
|
+
virtualized={true}
|
|
978
980
|
placeholder="Search 100k items..."
|
|
979
981
|
searchable
|
|
980
982
|
/>
|
|
@@ -1099,7 +1101,7 @@ function GenericSelect<T extends SelectItem>({
|
|
|
1099
1101
|
|
|
1100
1102
|
## Accessibility
|
|
1101
1103
|
|
|
1102
|
-
Smilodon
|
|
1104
|
+
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.
|
|
1103
1105
|
|
|
1104
1106
|
### Keyboard Navigation
|
|
1105
1107
|
|
|
@@ -1116,7 +1118,7 @@ The component automatically includes:
|
|
|
1116
1118
|
- `role="combobox"`
|
|
1117
1119
|
- `aria-expanded`
|
|
1118
1120
|
- `aria-haspopup`
|
|
1119
|
-
- `aria-label` / `aria-
|
|
1121
|
+
- `aria-label` / `aria-description` (literal host attributes are forwarded)
|
|
1120
1122
|
- `aria-activedescendant`
|
|
1121
1123
|
- `aria-multiselectable` (when `multiple={true}`)
|
|
1122
1124
|
|
|
@@ -1132,7 +1134,7 @@ function AccessibleSelect() {
|
|
|
1132
1134
|
value={value}
|
|
1133
1135
|
onChange={setValue}
|
|
1134
1136
|
placeholder="Select your country"
|
|
1135
|
-
|
|
1137
|
+
aria-label="Country"
|
|
1136
1138
|
/>
|
|
1137
1139
|
</div>
|
|
1138
1140
|
);
|
|
@@ -1325,10 +1327,10 @@ const [value, setValue] = useState<(string | number)[]>([]);
|
|
|
1325
1327
|
|
|
1326
1328
|
If you experience slow rendering with large datasets:
|
|
1327
1329
|
|
|
1328
|
-
1.
|
|
1330
|
+
1. Use `virtualized` only for incremental chunk rendering; it does not bound mounted DOM.
|
|
1329
1331
|
2. Use `useMemo` for items array
|
|
1330
1332
|
3. Use `useCallback` for event handlers
|
|
1331
|
-
4.
|
|
1333
|
+
4. Use host-controlled paging/search for datasets that should not all be loaded at once.
|
|
1332
1334
|
|
|
1333
1335
|
```tsx
|
|
1334
1336
|
const items = useMemo(() => generateLargeDataset(), []);
|
|
@@ -1338,8 +1340,7 @@ const handleChange = useCallback((val) => setValue(val), []);
|
|
|
1338
1340
|
items={items}
|
|
1339
1341
|
value={value}
|
|
1340
1342
|
onChange={handleChange}
|
|
1341
|
-
|
|
1342
|
-
estimatedItemHeight={48}
|
|
1343
|
+
virtualized={true}
|
|
1343
1344
|
/>
|
|
1344
1345
|
```
|
|
1345
1346
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @smilodon/react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Select component for React applications. The shared core has scoped automated Phase 4 browser coverage; complete React integration parity and manual assistive-technology certification remain unverified.
|
|
4
|
+
|
|
5
|
+
> Large-list status: the public `virtualized` prop enables legacy chunked rendering for large flat lists; it does not window rows to the viewport, and all results may eventually be mounted. True viewport virtualization remains guarded by a private test seam and is not a supported production mode. The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit; this does not certify every React integration, minimum browser versions, or WCAG conformance. Manual assistive-technology assessment remains pending. See the [current limitation record](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
|
|
4
6
|
|
|
5
7
|
## 📖 Documentation
|
|
6
8
|
|
|
@@ -31,13 +33,17 @@ The complete guide includes:
|
|
|
31
33
|
- ✅ **Controlled & Uncontrolled** - Works both ways, your choice
|
|
32
34
|
- ✅ **Single & Multi-select** - One prop to switch modes
|
|
33
35
|
- ✅ **Searchable** - Built-in filtering with customizable behavior
|
|
34
|
-
- ✅ **Infinite Scroll** -
|
|
35
|
-
- ✅ **
|
|
36
|
+
- ✅ **Infinite Scroll** - Emit host-managed load-more requests; this adapter does not own data transport, deduplication, or server pagination
|
|
37
|
+
- ✅ **Large-list chunk rendering** - Incrementally render large flat lists; not viewport windowing
|
|
36
38
|
- ✅ **Grouped Options** - Organize items into categories
|
|
37
39
|
- 🎨 **Dark Mode** - add `className="dark-mode"` or `data-theme="dark"` to the `<Select>` or any ancestor; styles are applied inside the shadow DOM via `:host-context`.
|
|
38
|
-
- ✅ **
|
|
40
|
+
- ✅ **Accessibility behaviors** - Shared-core scenarios passed in the scoped Chromium/Firefox/WebKit Phase 4 matrix; exhaustive React integration, manual AT, and WCAG conformance are not established
|
|
39
41
|
- ✅ **Customizable** - Custom renderers, styles, and behaviors
|
|
40
|
-
- ✅ **
|
|
42
|
+
- ✅ **Bundle guidance** - No version-specific bundle measurement is claimed; measure the published package output in your own bundler if bundle size is a release requirement
|
|
43
|
+
|
|
44
|
+
The Quick Start examples are self-contained. Longer feature snippets below are focused examples rather than one compilable module; names explicitly described as application-provided (for example, API endpoints or fetch functions) must be supplied by the host app. The package's [Complete React Guide](./COMPLETE-GUIDE.md) provides broader patterns and should be read with the same public-API and limitation notes above.
|
|
45
|
+
|
|
46
|
+
In focused JSX examples, `items`, `groups`, `bigItems`, and similar values are component-local application data unless the snippet declares them; imports and hook state should be added in the containing component as needed.
|
|
41
47
|
|
|
42
48
|
## Infinite Render Loop: Root-Cause Review (No External Dependencies)
|
|
43
49
|
|
|
@@ -105,7 +111,7 @@ pnpm add @smilodon/react @smilodon/core
|
|
|
105
111
|
1. Put the consuming component behind `'use client';`.
|
|
106
112
|
2. Import `Select` directly from `@smilodon/react`.
|
|
107
113
|
3. Keep large `items` arrays memoized.
|
|
108
|
-
4.
|
|
114
|
+
4. `virtualized` enables incremental chunk rendering for large flat lists; it does not provide bounded DOM or viewport windowing.
|
|
109
115
|
|
|
110
116
|
```tsx
|
|
111
117
|
'use client';
|
|
@@ -194,7 +200,7 @@ Use the built-in clear control in the input area and style it freely:
|
|
|
194
200
|
|
|
195
201
|
Available parts for advanced styling: `::part(clear-button)`, `::part(clear-icon)`.
|
|
196
202
|
|
|
197
|
-
By default, an empty clearable select does not reserve clear-button space. The button and adjusted input/arrow layout appear after a value is selected or, when search clearing is enabled, after search text is entered. They disappear again when both targets are empty. This
|
|
203
|
+
By default, an empty clearable select does not reserve clear-button space. The button and adjusted input/arrow layout appear after a value is selected or, when search clearing is enabled, after search text is entered. They disappear again when both targets are empty. This describes intended shared-runtime behavior across single/multi-select and LTR/RTL configurations; it is not exhaustive React integration certification.
|
|
198
204
|
|
|
199
205
|
For a permanently visible disabled-when-empty control, use the full core configuration:
|
|
200
206
|
|
|
@@ -308,10 +314,16 @@ function MultiSelectExample() {
|
|
|
308
314
|
### Searchable Select
|
|
309
315
|
|
|
310
316
|
```tsx
|
|
317
|
+
import { useState } from 'react';
|
|
311
318
|
import { Select } from '@smilodon/react';
|
|
312
319
|
|
|
313
320
|
function SearchableExample() {
|
|
314
321
|
const [value, setValue] = useState('');
|
|
322
|
+
const countries = [
|
|
323
|
+
{ value: 'us', label: 'United States' },
|
|
324
|
+
{ value: 'ca', label: 'Canada' },
|
|
325
|
+
{ value: 'mx', label: 'Mexico' },
|
|
326
|
+
];
|
|
315
327
|
|
|
316
328
|
return (
|
|
317
329
|
<Select
|
|
@@ -383,30 +395,64 @@ You can supply a `groupHeaderRenderer` to render arbitrary React content for the
|
|
|
383
395
|
### Infinite Scroll
|
|
384
396
|
|
|
385
397
|
```tsx
|
|
398
|
+
import { useRef, useState } from 'react';
|
|
386
399
|
import { Select } from '@smilodon/react';
|
|
387
400
|
|
|
388
401
|
function InfiniteScrollExample() {
|
|
389
|
-
const
|
|
402
|
+
const pageSize = 20;
|
|
403
|
+
// Page 1 is already loaded; the component's first load-more event requests page 2.
|
|
404
|
+
const [items, setItems] = useState(
|
|
405
|
+
Array.from({ length: pageSize }, (_, index) => ({
|
|
406
|
+
value: String(index + 1),
|
|
407
|
+
label: `Item ${index + 1}`,
|
|
408
|
+
}))
|
|
409
|
+
);
|
|
390
410
|
const [value, setValue] = useState('');
|
|
411
|
+
const [error, setError] = useState('');
|
|
412
|
+
const [loadingPages, setLoadingPages] = useState<number[]>([]);
|
|
413
|
+
const [hasMore, setHasMore] = useState(true);
|
|
414
|
+
const inFlight = useRef(new Set<number>());
|
|
415
|
+
const loadedPages = useRef(new Set<number>());
|
|
391
416
|
|
|
392
417
|
const handleLoadMore = async (page: number) => {
|
|
393
|
-
|
|
394
|
-
|
|
418
|
+
if (!hasMore || inFlight.current.has(page) || loadedPages.current.has(page)) return;
|
|
419
|
+
inFlight.current.add(page);
|
|
420
|
+
setLoadingPages((previous) => [...previous, page]);
|
|
421
|
+
try {
|
|
422
|
+
const response = await fetch(`/api/items?page=${page}`);
|
|
423
|
+
if (!response.ok) throw new Error(`Page request failed: ${response.status}`);
|
|
424
|
+
const newItems = await response.json() as Array<{ value: string; label: string }>;
|
|
425
|
+
setItems((previous) => [...previous, ...newItems]);
|
|
426
|
+
loadedPages.current.add(page);
|
|
427
|
+
if (newItems.length < pageSize) setHasMore(false);
|
|
428
|
+
setError('');
|
|
429
|
+
} catch (reason) {
|
|
430
|
+
setError(String(reason));
|
|
431
|
+
} finally {
|
|
432
|
+
inFlight.current.delete(page);
|
|
433
|
+
setLoadingPages((previous) => previous.filter((entry) => entry !== page));
|
|
434
|
+
}
|
|
395
435
|
};
|
|
396
436
|
|
|
397
437
|
return (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
438
|
+
<>
|
|
439
|
+
<Select
|
|
440
|
+
items={items}
|
|
441
|
+
value={value}
|
|
442
|
+
onChange={(val) => setValue(val as string)}
|
|
443
|
+
infiniteScroll
|
|
444
|
+
pageSize={pageSize}
|
|
445
|
+
onLoadMore={handleLoadMore}
|
|
446
|
+
/>
|
|
447
|
+
{loadingPages.length > 0 && <p role="status">Loading more options…</p>}
|
|
448
|
+
{error && <p role="alert">{error}</p>}
|
|
449
|
+
</>
|
|
406
450
|
);
|
|
407
451
|
}
|
|
408
452
|
```
|
|
409
453
|
|
|
454
|
+
The adapter calls `onLoadMore(page)` but does not await the returned Promise. The application owns transport, duplicate-page guards, loading/error UI, and server end-of-data detection; keep that logic in the host component even if the callback is declared `async`.
|
|
455
|
+
|
|
410
456
|
### Large Lists (Performance Baseline)
|
|
411
457
|
|
|
412
458
|
For high-volume datasets, start with the built-in lightweight option rendering and then add custom renderers only if needed for UX.
|
|
@@ -415,43 +461,57 @@ For high-volume datasets, start with the built-in lightweight option rendering a
|
|
|
415
461
|
<Select
|
|
416
462
|
items={bigItems}
|
|
417
463
|
virtualized
|
|
418
|
-
estimatedItemHeight={40}
|
|
419
464
|
searchable
|
|
420
465
|
/>
|
|
421
466
|
```
|
|
422
467
|
|
|
423
468
|
Notes:
|
|
424
|
-
-
|
|
469
|
+
- `estimatedItemHeight` is an exposed prop for the guarded viewport-windowing test path; it is not a production tuning control while viewport-windowing remains private.
|
|
425
470
|
- Complex `optionRenderer` DOM can add interaction cost on large lists; profile before shipping.
|
|
426
471
|
|
|
427
472
|
### With Validation
|
|
428
473
|
|
|
429
474
|
```tsx
|
|
430
475
|
import { Select } from '@smilodon/react';
|
|
476
|
+
import { useState } from 'react';
|
|
477
|
+
import type { FormEvent } from 'react';
|
|
431
478
|
|
|
432
479
|
function ValidationExample() {
|
|
433
480
|
const [value, setValue] = useState('');
|
|
481
|
+
const [submitted, setSubmitted] = useState(false);
|
|
434
482
|
const [error, setError] = useState('');
|
|
483
|
+
const items = [
|
|
484
|
+
{ value: 'small', label: 'Small' },
|
|
485
|
+
{ value: 'medium', label: 'Medium' },
|
|
486
|
+
{ value: 'large', label: 'Large' },
|
|
487
|
+
];
|
|
435
488
|
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
489
|
+
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
|
|
490
|
+
event.preventDefault();
|
|
491
|
+
setSubmitted(true);
|
|
492
|
+
const message = value ? '' : 'This field is required';
|
|
493
|
+
setError(message);
|
|
494
|
+
if (!message) console.log('Submit value:', value);
|
|
443
495
|
};
|
|
444
496
|
|
|
445
497
|
return (
|
|
446
|
-
<
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
498
|
+
<form onSubmit={handleSubmit} noValidate>
|
|
499
|
+
<Select
|
|
500
|
+
items={items}
|
|
501
|
+
value={value}
|
|
502
|
+
onChange={(next) => {
|
|
503
|
+
const selected = Array.isArray(next) ? next[0] : next;
|
|
504
|
+
setValue(selected == null ? '' : String(selected));
|
|
505
|
+
if (submitted) setError(selected == null ? 'This field is required' : '');
|
|
506
|
+
}}
|
|
507
|
+
required
|
|
508
|
+
error={!!error}
|
|
509
|
+
errorMessage={error}
|
|
510
|
+
placeholder="Required field"
|
|
511
|
+
/>
|
|
512
|
+
{error && <p role="alert">{error}</p>}
|
|
513
|
+
<button type="submit">Submit</button>
|
|
514
|
+
</form>
|
|
455
515
|
);
|
|
456
516
|
}
|
|
457
517
|
```
|
|
@@ -459,10 +519,14 @@ function ValidationExample() {
|
|
|
459
519
|
### Using Ref for Imperative Actions
|
|
460
520
|
|
|
461
521
|
```tsx
|
|
462
|
-
import { Select, SelectHandle } from '@smilodon/react';
|
|
463
|
-
import { useRef } from 'react';
|
|
522
|
+
import { Select, type SelectHandle } from '@smilodon/react';
|
|
523
|
+
import { useRef, useState } from 'react';
|
|
464
524
|
|
|
465
525
|
function RefExample() {
|
|
526
|
+
const items = [
|
|
527
|
+
{ value: 'alpha', label: 'Alpha' },
|
|
528
|
+
{ value: 'beta', label: 'Beta' },
|
|
529
|
+
];
|
|
466
530
|
const selectRef = useRef<SelectHandle>(null);
|
|
467
531
|
const [value, setValue] = useState('');
|
|
468
532
|
|
|
@@ -504,7 +568,7 @@ Smilodon React provides **two powerful approaches** for defining select options,
|
|
|
504
568
|
- ✅ Auto-conversion from strings/numbers
|
|
505
569
|
- ✅ Perfect for basic dropdowns
|
|
506
570
|
- ✅ Works seamlessly with React state
|
|
507
|
-
- ✅
|
|
571
|
+
- ✅ Can render the datasets exercised in your application; no millions-of-items or constant-DOM guarantee is made
|
|
508
572
|
- ✅ Built-in search and filtering
|
|
509
573
|
- ✅ Full TypeScript type safety
|
|
510
574
|
|
|
@@ -625,7 +689,7 @@ function LargeDatasetExample() {
|
|
|
625
689
|
items={items}
|
|
626
690
|
value={id}
|
|
627
691
|
onChange={(val) => setId(val as string)}
|
|
628
|
-
virtualized // Enable
|
|
692
|
+
virtualized // Enable incremental chunk rendering; not viewport windowing
|
|
629
693
|
placeholder="Select from 100K items..."
|
|
630
694
|
/>
|
|
631
695
|
);
|
|
@@ -637,51 +701,72 @@ function LargeDatasetExample() {
|
|
|
637
701
|
Now also supports the native `optionRenderer` hook (Option B) that returns an `HTMLElement` for maximum control (e.g., non-React DOM fragments). Pass `optionRenderer={(item, index, helpers) => { const el = document.createElement('div'); el.textContent = item.label; return el; }}` to mirror the Web Component API.
|
|
638
702
|
|
|
639
703
|
#### Advanced scenarios (React)
|
|
640
|
-
- **
|
|
704
|
+
- **Accessibility labels**: use a literal `aria-label` for the internal combobox; host IDREF attributes are not forwarded across the shadow boundary:
|
|
641
705
|
```tsx
|
|
642
|
-
<
|
|
643
|
-
<Select id="user-picker" aria-
|
|
706
|
+
<span>Pick a user</span>
|
|
707
|
+
<Select id="user-picker" aria-label="Pick a user" onChange={(v, items) => {
|
|
644
708
|
console.log('Selected', items);
|
|
645
709
|
}}/>
|
|
646
710
|
```
|
|
647
|
-
- **Server-side lookup**:
|
|
711
|
+
- **Server-side lookup**: cancellation and request sequencing prevent an old response from overwriting newer results; the host also handles HTTP and transport errors:
|
|
648
712
|
```tsx
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
713
|
+
import { useEffect, useRef, useState } from 'react';
|
|
714
|
+
import { Select, type SelectItem } from '@smilodon/react';
|
|
715
|
+
|
|
716
|
+
function RemoteSearchExample() {
|
|
717
|
+
const [items, setItems] = useState<SelectItem[]>([]);
|
|
718
|
+
const [error, setError] = useState('');
|
|
719
|
+
const [loading, setLoading] = useState(false);
|
|
720
|
+
const requestId = useRef(0);
|
|
721
|
+
const controller = useRef<AbortController | null>(null);
|
|
722
|
+
useEffect(() => () => controller.current?.abort(), []);
|
|
723
|
+
async function handleSearch(query: string) {
|
|
724
|
+
const id = ++requestId.current;
|
|
725
|
+
controller.current?.abort();
|
|
726
|
+
if (!query) { setItems([]); setError(''); setLoading(false); return; }
|
|
727
|
+
const current = new AbortController(); controller.current = current;
|
|
728
|
+
setLoading(true);
|
|
729
|
+
setError('');
|
|
730
|
+
try {
|
|
731
|
+
const response = await fetch(`/api/users?q=${encodeURIComponent(query)}`, { signal: current.signal });
|
|
732
|
+
if (!response.ok) throw new Error(`Search failed: ${response.status}`);
|
|
733
|
+
const next = await response.json() as SelectItem[];
|
|
734
|
+
if (id === requestId.current) { setItems(next); setError(''); }
|
|
735
|
+
} catch (reason) {
|
|
736
|
+
if (!(reason instanceof DOMException && reason.name === 'AbortError') && id === requestId.current) setError(String(reason));
|
|
737
|
+
} finally {
|
|
738
|
+
if (id === requestId.current) setLoading(false);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return <><Select items={items} searchable onSearch={handleSearch} />{loading && <p role="status">Searching…</p>}{error && <p role="alert">{error}</p>}</>;
|
|
742
|
+
}
|
|
660
743
|
```
|
|
661
|
-
- **Heavy lists (100k+)**:
|
|
744
|
+
- **Heavy lists (100k+)**: `virtualized` does not guarantee bounded DOM; true viewport windowing is not a public production mode:
|
|
662
745
|
```tsx
|
|
663
746
|
const big = useMemo(() => Array.from({ length: 100_000 }, (_, i) => ({ value: i, label: `Row ${i}` })), []);
|
|
664
|
-
<Select items={big} virtualized
|
|
747
|
+
<Select items={big} virtualized />
|
|
665
748
|
```
|
|
666
749
|
|
|
667
|
-
**Use when**: You need rich
|
|
750
|
+
**Use when**: You need rich option content composed with React. Each rendered row remains one listbox option; arbitrary nested buttons, links, or other separately interactive controls are not a supported assumption.
|
|
668
751
|
|
|
669
752
|
**Advantages**:
|
|
670
753
|
- ✅ Full control over option rendering
|
|
671
|
-
- ✅ Render
|
|
754
|
+
- ✅ Render React-node content through the adapter's custom renderer
|
|
672
755
|
- ✅ Rich content (images, icons, badges, multi-line text)
|
|
673
756
|
- ✅ Custom styling with CSS-in-JS or Tailwind
|
|
674
|
-
- ✅
|
|
757
|
+
- ✅ Rich non-interactive option content; keep selection and keyboard interaction on the option itself
|
|
675
758
|
- ✅ Conditional rendering based on item data
|
|
676
|
-
- ✅
|
|
759
|
+
- ✅ Renderer lifecycle and context boundaries are documented below
|
|
677
760
|
- ✅ Perfect for complex UIs (user cards, product listings, etc.)
|
|
678
761
|
|
|
679
762
|
**How it works**: Provide a `customRenderer` function that returns `React.ReactNode` for each option.
|
|
680
763
|
|
|
764
|
+
The adapter renders returned content in separate React roots and schedules cleanup when renderer content is replaced or the adapter unmounts. The `customRenderer` callback itself is not a React component and must not call hooks. A component returned by the callback may use its own hooks, but it does not inherit context providers above `<Select>` because its root is separate.
|
|
765
|
+
|
|
681
766
|
**Examples**:
|
|
682
767
|
|
|
683
768
|
```tsx
|
|
684
|
-
import { Select, SelectItem } from '@smilodon/react';
|
|
769
|
+
import { Select, type SelectItem } from '@smilodon/react';
|
|
685
770
|
import { useState } from 'react';
|
|
686
771
|
|
|
687
772
|
// Example 1: Simple custom template with icons
|
|
@@ -973,6 +1058,7 @@ function TaskSelect() {
|
|
|
973
1058
|
|
|
974
1059
|
// Example 5: Using Tailwind CSS (if available)
|
|
975
1060
|
// Note: Tailwind/CSS classes in customRenderer are supported inside Select options.
|
|
1061
|
+
// Map dynamic values to literal class names so Tailwind's static scanner can include them.
|
|
976
1062
|
// Core mirrors document stylesheets into shadow DOM for custom option rendering.
|
|
977
1063
|
interface Tag extends SelectItem {
|
|
978
1064
|
color: string;
|
|
@@ -982,6 +1068,12 @@ interface Tag extends SelectItem {
|
|
|
982
1068
|
function TailwindExample() {
|
|
983
1069
|
const [tag, setTag] = useState('');
|
|
984
1070
|
|
|
1071
|
+
const colorClasses: Record<string, string> = {
|
|
1072
|
+
blue: 'bg-blue-500',
|
|
1073
|
+
green: 'bg-green-500',
|
|
1074
|
+
red: 'bg-red-500',
|
|
1075
|
+
} as const;
|
|
1076
|
+
|
|
985
1077
|
const tags: Tag[] = [
|
|
986
1078
|
{ value: 'react', label: 'React', color: 'blue', count: 1250 },
|
|
987
1079
|
{ value: 'vue', label: 'Vue', color: 'green', count: 850 },
|
|
@@ -996,7 +1088,7 @@ function TailwindExample() {
|
|
|
996
1088
|
customRenderer={(item: Tag) => (
|
|
997
1089
|
<div className="flex items-center justify-between p-2">
|
|
998
1090
|
<div className="flex items-center gap-2">
|
|
999
|
-
<span className={`w-3 h-3 rounded-full
|
|
1091
|
+
<span className={`w-3 h-3 rounded-full ${colorClasses[item.color]}`} />
|
|
1000
1092
|
<span className="font-semibold text-gray-900">{item.label}</span>
|
|
1001
1093
|
</div>
|
|
1002
1094
|
<span className="text-sm text-gray-500">{item.count} posts</span>
|
|
@@ -1039,20 +1131,20 @@ function ComponentExample() {
|
|
|
1039
1131
|
|
|
1040
1132
|
| Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
|
|
1041
1133
|
|---------|------------------------|---------------------------|
|
|
1042
|
-
| **Setup
|
|
1043
|
-
| **Rendering
|
|
1044
|
-
| **
|
|
1045
|
-
| **React
|
|
1046
|
-
| **Component
|
|
1047
|
-
| **TypeScript
|
|
1048
|
-
| **
|
|
1049
|
-
| **
|
|
1134
|
+
| **Setup** | Pass an array of option data | Provide a renderer callback |
|
|
1135
|
+
| **Rendering behavior** | Shared runtime renders option labels | Adapter renders React-node option content |
|
|
1136
|
+
| **Customization** | Data-driven labels and state | Custom non-interactive content; nested controls are not promised |
|
|
1137
|
+
| **React integration** | Controlled/uncontrolled values and callbacks | Same adapter API with custom-rendered content |
|
|
1138
|
+
| **Component reuse** | Reuse data definitions | Return components; separate-root context limits apply |
|
|
1139
|
+
| **TypeScript** | Typed item data and props | Typed renderer callback and props |
|
|
1140
|
+
| **Very large datasets** | No 1M-item certification or performance comparison is claimed | No 1M-item certification or performance comparison is claimed |
|
|
1141
|
+
| **Choosing a method** | Direct for simple options | Use when custom content is required |
|
|
1050
1142
|
|
|
1051
1143
|
**Best Practices**:
|
|
1052
1144
|
|
|
1053
1145
|
✅ **Use Method 1 (Object Arrays) when**:
|
|
1054
1146
|
- You need simple text-based options
|
|
1055
|
-
-
|
|
1147
|
+
- You have a large dataset and will profile the workload and use host-managed search or pagination where appropriate; no millions-of-items guarantee is made
|
|
1056
1148
|
- You want minimal code
|
|
1057
1149
|
- Built-in search/filter is sufficient
|
|
1058
1150
|
- Working with external APIs returning plain data
|
|
@@ -1100,7 +1192,7 @@ function EvolvingComponent() {
|
|
|
1100
1192
|
|
|
1101
1193
|
**For Method 1**:
|
|
1102
1194
|
- Use `useMemo` to memoize large item arrays
|
|
1103
|
-
-
|
|
1195
|
+
- The `virtualized` prop enables incremental chunk rendering, not viewport-windowed rendering.
|
|
1104
1196
|
- Enable `infiniteScroll` for dynamic loading
|
|
1105
1197
|
|
|
1106
1198
|
**For Method 2**:
|
|
@@ -1141,8 +1233,7 @@ function OptimizedExample() {
|
|
|
1141
1233
|
value={value}
|
|
1142
1234
|
onChange={(val) => setValue(val as string)}
|
|
1143
1235
|
customRenderer={renderer}
|
|
1144
|
-
virtualized // Enable
|
|
1145
|
-
estimatedItemHeight={60}
|
|
1236
|
+
virtualized // Enable incremental chunk rendering, not viewport windowing
|
|
1146
1237
|
/>
|
|
1147
1238
|
);
|
|
1148
1239
|
}
|
|
@@ -1169,13 +1260,21 @@ function OptimizedExample() {
|
|
|
1169
1260
|
| `errorMessage` | `string` | - | Error message to display |
|
|
1170
1261
|
| `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
|
|
1171
1262
|
| `pageSize` | `number` | `20` | Items per page (infinite scroll) |
|
|
1172
|
-
| `virtualized` | `boolean` | `false` | Enable
|
|
1173
|
-
| `estimatedItemHeight` | `number` | `48` |
|
|
1263
|
+
| `virtualized` | `boolean` | `false` | Enable legacy chunked rendering for large flat lists; not viewport windowing |
|
|
1264
|
+
| `estimatedItemHeight` | `number` | `48` | Exposed estimate used only by the guarded viewport-windowing test path; not a production tuning control |
|
|
1174
1265
|
| `maxSelections` | `number` | - | Max selections (multi-select) |
|
|
1175
1266
|
| `toggleOnTriggerClick` | `boolean` | `true` | Allow repeated trigger clicks to toggle the dropdown |
|
|
1176
1267
|
| `placement` | `string` | `"bottom-start"` | Dropdown placement |
|
|
1177
1268
|
| `className` | `string` | - | Custom CSS class |
|
|
1178
1269
|
| `style` | `CSSProperties` | - | Inline styles |
|
|
1270
|
+
| `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config` | core configuration types | - | Shared runtime configuration groups |
|
|
1271
|
+
| `optionRenderer` | `(item, index, helpers) => HTMLElement` | - | DOM renderer; return safe DOM nodes and retain the single-option interaction model |
|
|
1272
|
+
| `customRenderer` | `(item, index) => React.ReactNode` | - | React-node option content; nested interactive controls are not promised |
|
|
1273
|
+
| `groupHeaderRenderer` | `(group, index) => React.ReactNode` | - | React-node grouped-header content |
|
|
1274
|
+
| `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, `clearIcon` | booleans / strings | - | Clear-control configuration |
|
|
1275
|
+
| `onClear` | `(detail) => void` | - | Reports which selection/search state was cleared |
|
|
1276
|
+
| `onDiagnostic` | `(detail) => void` | - | Runtime diagnostic callback |
|
|
1277
|
+
| `trackingEnabled`, `trackEvents`, `trackStyling`, `trackLimitations`, `emitDiagnostics`, `trackingMaxEntries`, `limitationPolicies`, `autoMitigateRuntimeModeSwitch` | documented tracking/limitation types | - | Runtime tracking and limitation-policy configuration |
|
|
1179
1278
|
| `onChange` | `(value, items) => void` | - | Selection change callback |
|
|
1180
1279
|
| `onSelect` | `(item, index) => void` | - | Item select callback |
|
|
1181
1280
|
| `onOpen` | `() => void` | - | Dropdown open callback |
|
|
@@ -1481,6 +1580,11 @@ interface SelectHandle {
|
|
|
1481
1580
|
clearError: () => void;
|
|
1482
1581
|
setRequired: (required: boolean) => void;
|
|
1483
1582
|
validate: () => boolean;
|
|
1583
|
+
getCapabilities: () => SelectCapabilitiesReport | undefined;
|
|
1584
|
+
getKnownLimitations: () => LimitationState[];
|
|
1585
|
+
getTrackingSnapshot: () => TrackingSnapshot;
|
|
1586
|
+
clearTracking: (source?: 'event' | 'style' | 'limitation' | 'all') => void;
|
|
1587
|
+
setLimitationPolicies: (policies: LimitationPolicyMap) => void;
|
|
1484
1588
|
}
|
|
1485
1589
|
```
|
|
1486
1590
|
|
|
@@ -1509,15 +1613,15 @@ enhanced-select {
|
|
|
1509
1613
|
|
|
1510
1614
|
## Accessibility
|
|
1511
1615
|
|
|
1512
|
-
|
|
1616
|
+
Implemented keyboard and ARIA behaviors include:
|
|
1513
1617
|
|
|
1514
|
-
- ✅
|
|
1515
|
-
- ✅
|
|
1618
|
+
- ✅ Tested keyboard paths include Arrow keys, Enter, Escape, and Tab; this is not an exhaustive interaction certification
|
|
1619
|
+
- ✅ ARIA attributes and selected live-region announcements
|
|
1516
1620
|
- ✅ Focus management
|
|
1517
1621
|
- ✅ High contrast mode support
|
|
1518
1622
|
- ✅ Reduced motion support
|
|
1519
|
-
-
|
|
1520
|
-
-
|
|
1623
|
+
- Touch-target sizing is themeable; WCAG touch-target conformance has not been certified.
|
|
1624
|
+
- The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit. This does not establish every React integration pattern, minimum-browser-version compatibility, or WCAG conformance. Manual Windows/NVDA and macOS/VoiceOver assessments remain pending.
|
|
1521
1625
|
|
|
1522
1626
|
### Important: Passing inline functions as renderers
|
|
1523
1627
|
|
|
@@ -1535,26 +1639,22 @@ Adapters are designed to not loop even without memoization, but memoization stil
|
|
|
1535
1639
|
|
|
1536
1640
|
## Performance
|
|
1537
1641
|
|
|
1538
|
-
-
|
|
1642
|
+
- Incremental chunk rendering for large flat datasets; viewport windowing is not public/production-activated
|
|
1539
1643
|
- Lazy loading with infinite scroll
|
|
1540
|
-
-
|
|
1644
|
+
- React state and renderer stability guidance; the adapter does not promise an internal `React.memo` wrapper
|
|
1541
1645
|
- Tree-shakeable exports
|
|
1542
|
-
-
|
|
1646
|
+
- Bundle output depends on the consuming app and bundler; no version-specific size claim is made here
|
|
1543
1647
|
|
|
1544
1648
|
## Browser Support
|
|
1545
1649
|
|
|
1546
|
-
|
|
1547
|
-
- Firefox 88+
|
|
1548
|
-
- Safari 14+
|
|
1549
|
-
- iOS Safari 14+
|
|
1550
|
-
- Samsung Internet 14+
|
|
1650
|
+
The minimum versions listed by repository policy are compatibility targets, not versions proven by the current Phase 4 matrix. The completed automated matrix uses current pinned Chromium, Firefox, and WebKit builds; consult the [browser support policy](../../docs/compliance/BROWSER-SUPPORT.md) for declared compatibility details.
|
|
1551
1651
|
|
|
1552
1652
|
## TypeScript
|
|
1553
1653
|
|
|
1554
1654
|
Full TypeScript support with comprehensive type definitions included.
|
|
1555
1655
|
|
|
1556
1656
|
```tsx
|
|
1557
|
-
import { Select, SelectProps, SelectHandle, SelectItem } from '@smilodon/react';
|
|
1657
|
+
import { Select, type SelectProps, type SelectHandle, type SelectItem, type GroupedItem, type GlobalSelectConfig, type SelectCapabilitiesReport, type LimitationState, type TrackingSnapshot, type LimitationPolicyMap } from '@smilodon/react';
|
|
1558
1658
|
```
|
|
1559
1659
|
|
|
1560
1660
|
## License
|