@smilodon/react 1.9.3 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPLETE-GUIDE.md +15 -14
- package/README.md +330 -91
- package/dist/index.cjs +682 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +683 -152
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +27 -17
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
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,156 @@ 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.
|
|
47
|
+
|
|
48
|
+
## Acknowledged data loading (Phase 2F-D development candidate)
|
|
49
|
+
|
|
50
|
+
The current local Phase 2F-D candidate integrates the core acknowledged-loading facade with the React adapter. It is not part of the published `1.10.0` package, and Firefox/WebKit certification, independent review, and remaining contract coverage are pending. Treat the following as implementation guidance for this candidate, not a release-readiness or cross-browser compatibility claim.
|
|
51
|
+
|
|
52
|
+
Acknowledged loading is opt-in through per-instance `config.dataLoading`; there is no global acknowledged-loading default. If the config is omitted, the adapter keeps the legacy protocol and existing callback behavior. The host owns fetch, cancellation, and retry policy; the core owns request identity, stale-completion rejection, canonical acceptance, and subsequent DOM projection.
|
|
53
|
+
|
|
54
|
+
### Remote cursor search with cancellation and failures
|
|
55
|
+
|
|
56
|
+
This illustrative component handles remote search and load-more requests through one host function. It sends the exact query (including an empty string), passes page/cursor position and fetch limit to the server, echoes request identity on completion, aborts cancelled requests, and reports failures without an automatic retry.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { useEffect, useRef } from 'react'
|
|
60
|
+
import {
|
|
61
|
+
Select,
|
|
62
|
+
type DataRequest,
|
|
63
|
+
type DataRequestCompletion,
|
|
64
|
+
type SelectHandle,
|
|
65
|
+
type SelectItem,
|
|
66
|
+
} from '@smilodon/react'
|
|
67
|
+
|
|
68
|
+
type SearchPage = {
|
|
69
|
+
items: SelectItem[]
|
|
70
|
+
hasMore: boolean
|
|
71
|
+
nextCursor?: string | number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function RemoteSelect() {
|
|
75
|
+
const selectRef = useRef<SelectHandle>(null)
|
|
76
|
+
const controllers = useRef(new Map<string, AbortController>())
|
|
77
|
+
|
|
78
|
+
useEffect(() => () => {
|
|
79
|
+
for (const controller of controllers.current.values()) controller.abort()
|
|
80
|
+
controllers.current.clear()
|
|
81
|
+
}, [])
|
|
82
|
+
|
|
83
|
+
async function load(request: DataRequest) {
|
|
84
|
+
const controller = new AbortController()
|
|
85
|
+
controllers.current.set(request.requestId, controller)
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const params = new URLSearchParams({ q: request.query, limit: String(request.fetchLimit) })
|
|
89
|
+
if (request.position.mode === 'page') {
|
|
90
|
+
params.set('page', String(request.position.page))
|
|
91
|
+
} else if (request.position.cursor !== undefined) {
|
|
92
|
+
params.set('cursor', String(request.position.cursor))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const response = await fetch(`/api/options?${params}`, { signal: controller.signal })
|
|
96
|
+
if (!response.ok) throw new Error(`Search failed: ${response.status}`)
|
|
97
|
+
|
|
98
|
+
const page = await response.json() as SearchPage
|
|
99
|
+
if (!Array.isArray(page.items) || typeof page.hasMore !== 'boolean') {
|
|
100
|
+
throw new Error('The options endpoint returned an invalid page.')
|
|
101
|
+
}
|
|
102
|
+
if (request.position.mode === 'cursor' && page.hasMore && page.nextCursor === undefined) {
|
|
103
|
+
throw new Error('A non-terminal cursor page must include nextCursor.')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const completion: DataRequestCompletion = page.hasMore
|
|
107
|
+
? {
|
|
108
|
+
requestId: request.requestId,
|
|
109
|
+
queryGeneration: request.queryGeneration,
|
|
110
|
+
status: 'succeeded',
|
|
111
|
+
items: page.items,
|
|
112
|
+
hasMore: true,
|
|
113
|
+
...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
116
|
+
requestId: request.requestId,
|
|
117
|
+
queryGeneration: request.queryGeneration,
|
|
118
|
+
status: 'exhausted',
|
|
119
|
+
items: page.items,
|
|
120
|
+
hasMore: false,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const result = selectRef.current?.completeDataRequest(completion)
|
|
124
|
+
if (result !== 'accepted') {
|
|
125
|
+
// Stale, unknown, invalid, or resource-limited completions are not projected.
|
|
126
|
+
console.info('Response not accepted:', result)
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (!controller.signal.aborted) {
|
|
130
|
+
selectRef.current?.completeDataRequest({
|
|
131
|
+
requestId: request.requestId,
|
|
132
|
+
queryGeneration: request.queryGeneration,
|
|
133
|
+
status: 'failed',
|
|
134
|
+
error: { message: error instanceof Error ? error.message : String(error), retryable: true },
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
} finally {
|
|
138
|
+
controllers.current.delete(request.requestId)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Select
|
|
144
|
+
ref={selectRef}
|
|
145
|
+
searchable
|
|
146
|
+
config={{
|
|
147
|
+
dataLoading: {
|
|
148
|
+
protocol: 'acknowledged',
|
|
149
|
+
searchMode: 'remote',
|
|
150
|
+
paginationMode: 'cursor',
|
|
151
|
+
fetchLimit: 25,
|
|
152
|
+
},
|
|
153
|
+
}}
|
|
154
|
+
onSearch={(_query, _results, _count, request) => {
|
|
155
|
+
if (request) void load(request)
|
|
156
|
+
}}
|
|
157
|
+
onLoadMore={(_page, request) => {
|
|
158
|
+
if (request) void load(request)
|
|
159
|
+
}}
|
|
160
|
+
onDataRequestCancel={({ requestId }) => {
|
|
161
|
+
controllers.current.get(requestId)?.abort()
|
|
162
|
+
controllers.current.delete(requestId)
|
|
163
|
+
}}
|
|
164
|
+
onDataProjection={(detail) => {
|
|
165
|
+
if (detail.status === 'failed') console.error(detail.error.message)
|
|
166
|
+
}}
|
|
167
|
+
onDataLoadingConfigError={({ issues }) => {
|
|
168
|
+
console.error('Rejected data-loading config:', issues)
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The coordinator rejects stale responses by request ID and query generation; the host should still abort cancelled network work to save resources. An accepted response does not mean projection is finished: observe `onDataProjection` for the projection result. A failed request remains failed until a new explicit request is made; the sample deliberately does not retry automatically.
|
|
176
|
+
|
|
177
|
+
### Other useful scenarios
|
|
178
|
+
|
|
179
|
+
- **Empty query:** clearing search still invokes `onSearch` with `request.query === ''`. `URLSearchParams` serializes it as an explicit empty `q` parameter; do not omit it if the endpoint treats an empty query specially.
|
|
180
|
+
- **Page-based pagination:** change `paginationMode` to `'page'`; the request's `position.page` is the page to request. Keep the API's page numbering consistent with `firstPage`.
|
|
181
|
+
- **Hybrid search:** use `searchMode: 'hybrid'` only when the host intends the runtime's hybrid search behavior; the host still answers the remote request with its identity and generation.
|
|
182
|
+
- **React Strict Mode:** the adapter owns readiness and initial request setup. Do not call a second manual request from an effect; keep each host response keyed by the request ID supplied in the callback. Browser certification for this scenario remains pending outside the reported Chromium run.
|
|
183
|
+
- **External busy state:** the React `loading` prop and consumer `aria-busy` remain presentation inputs. The adapter composes them with core busy state; the acknowledged request snapshot's `busy` does not include external presentation loading.
|
|
184
|
+
- **Legacy compatibility:** omit `config.dataLoading` to retain the legacy protocol. Existing `onSearch(query, results, count)` and `onLoadMore(page)` calls remain usable; the new request argument is optional in those callback signatures.
|
|
185
|
+
- **Controlled selection:** keep `value` in application state and update it through `onChange`. Replacing remote result pages does not transfer ownership of the selected value from the application to the transport layer.
|
|
41
186
|
|
|
42
187
|
## Infinite Render Loop: Root-Cause Review (No External Dependencies)
|
|
43
188
|
|
|
@@ -105,7 +250,7 @@ pnpm add @smilodon/react @smilodon/core
|
|
|
105
250
|
1. Put the consuming component behind `'use client';`.
|
|
106
251
|
2. Import `Select` directly from `@smilodon/react`.
|
|
107
252
|
3. Keep large `items` arrays memoized.
|
|
108
|
-
4.
|
|
253
|
+
4. `virtualized` enables incremental chunk rendering for large flat lists; it does not provide bounded DOM or viewport windowing.
|
|
109
254
|
|
|
110
255
|
```tsx
|
|
111
256
|
'use client';
|
|
@@ -194,7 +339,7 @@ Use the built-in clear control in the input area and style it freely:
|
|
|
194
339
|
|
|
195
340
|
Available parts for advanced styling: `::part(clear-button)`, `::part(clear-icon)`.
|
|
196
341
|
|
|
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
|
|
342
|
+
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
343
|
|
|
199
344
|
For a permanently visible disabled-when-empty control, use the full core configuration:
|
|
200
345
|
|
|
@@ -308,10 +453,16 @@ function MultiSelectExample() {
|
|
|
308
453
|
### Searchable Select
|
|
309
454
|
|
|
310
455
|
```tsx
|
|
456
|
+
import { useState } from 'react';
|
|
311
457
|
import { Select } from '@smilodon/react';
|
|
312
458
|
|
|
313
459
|
function SearchableExample() {
|
|
314
460
|
const [value, setValue] = useState('');
|
|
461
|
+
const countries = [
|
|
462
|
+
{ value: 'us', label: 'United States' },
|
|
463
|
+
{ value: 'ca', label: 'Canada' },
|
|
464
|
+
{ value: 'mx', label: 'Mexico' },
|
|
465
|
+
];
|
|
315
466
|
|
|
316
467
|
return (
|
|
317
468
|
<Select
|
|
@@ -383,30 +534,64 @@ You can supply a `groupHeaderRenderer` to render arbitrary React content for the
|
|
|
383
534
|
### Infinite Scroll
|
|
384
535
|
|
|
385
536
|
```tsx
|
|
537
|
+
import { useRef, useState } from 'react';
|
|
386
538
|
import { Select } from '@smilodon/react';
|
|
387
539
|
|
|
388
540
|
function InfiniteScrollExample() {
|
|
389
|
-
const
|
|
541
|
+
const pageSize = 20;
|
|
542
|
+
// Page 1 is already loaded; the component's first load-more event requests page 2.
|
|
543
|
+
const [items, setItems] = useState(
|
|
544
|
+
Array.from({ length: pageSize }, (_, index) => ({
|
|
545
|
+
value: String(index + 1),
|
|
546
|
+
label: `Item ${index + 1}`,
|
|
547
|
+
}))
|
|
548
|
+
);
|
|
390
549
|
const [value, setValue] = useState('');
|
|
550
|
+
const [error, setError] = useState('');
|
|
551
|
+
const [loadingPages, setLoadingPages] = useState<number[]>([]);
|
|
552
|
+
const [hasMore, setHasMore] = useState(true);
|
|
553
|
+
const inFlight = useRef(new Set<number>());
|
|
554
|
+
const loadedPages = useRef(new Set<number>());
|
|
391
555
|
|
|
392
556
|
const handleLoadMore = async (page: number) => {
|
|
393
|
-
|
|
394
|
-
|
|
557
|
+
if (!hasMore || inFlight.current.has(page) || loadedPages.current.has(page)) return;
|
|
558
|
+
inFlight.current.add(page);
|
|
559
|
+
setLoadingPages((previous) => [...previous, page]);
|
|
560
|
+
try {
|
|
561
|
+
const response = await fetch(`/api/items?page=${page}`);
|
|
562
|
+
if (!response.ok) throw new Error(`Page request failed: ${response.status}`);
|
|
563
|
+
const newItems = await response.json() as Array<{ value: string; label: string }>;
|
|
564
|
+
setItems((previous) => [...previous, ...newItems]);
|
|
565
|
+
loadedPages.current.add(page);
|
|
566
|
+
if (newItems.length < pageSize) setHasMore(false);
|
|
567
|
+
setError('');
|
|
568
|
+
} catch (reason) {
|
|
569
|
+
setError(String(reason));
|
|
570
|
+
} finally {
|
|
571
|
+
inFlight.current.delete(page);
|
|
572
|
+
setLoadingPages((previous) => previous.filter((entry) => entry !== page));
|
|
573
|
+
}
|
|
395
574
|
};
|
|
396
575
|
|
|
397
576
|
return (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
577
|
+
<>
|
|
578
|
+
<Select
|
|
579
|
+
items={items}
|
|
580
|
+
value={value}
|
|
581
|
+
onChange={(val) => setValue(val as string)}
|
|
582
|
+
infiniteScroll
|
|
583
|
+
pageSize={pageSize}
|
|
584
|
+
onLoadMore={handleLoadMore}
|
|
585
|
+
/>
|
|
586
|
+
{loadingPages.length > 0 && <p role="status">Loading more options…</p>}
|
|
587
|
+
{error && <p role="alert">{error}</p>}
|
|
588
|
+
</>
|
|
406
589
|
);
|
|
407
590
|
}
|
|
408
591
|
```
|
|
409
592
|
|
|
593
|
+
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`.
|
|
594
|
+
|
|
410
595
|
### Large Lists (Performance Baseline)
|
|
411
596
|
|
|
412
597
|
For high-volume datasets, start with the built-in lightweight option rendering and then add custom renderers only if needed for UX.
|
|
@@ -415,43 +600,57 @@ For high-volume datasets, start with the built-in lightweight option rendering a
|
|
|
415
600
|
<Select
|
|
416
601
|
items={bigItems}
|
|
417
602
|
virtualized
|
|
418
|
-
estimatedItemHeight={40}
|
|
419
603
|
searchable
|
|
420
604
|
/>
|
|
421
605
|
```
|
|
422
606
|
|
|
423
607
|
Notes:
|
|
424
|
-
-
|
|
608
|
+
- `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
609
|
- Complex `optionRenderer` DOM can add interaction cost on large lists; profile before shipping.
|
|
426
610
|
|
|
427
611
|
### With Validation
|
|
428
612
|
|
|
429
613
|
```tsx
|
|
430
614
|
import { Select } from '@smilodon/react';
|
|
615
|
+
import { useState } from 'react';
|
|
616
|
+
import type { FormEvent } from 'react';
|
|
431
617
|
|
|
432
618
|
function ValidationExample() {
|
|
433
619
|
const [value, setValue] = useState('');
|
|
620
|
+
const [submitted, setSubmitted] = useState(false);
|
|
434
621
|
const [error, setError] = useState('');
|
|
622
|
+
const items = [
|
|
623
|
+
{ value: 'small', label: 'Small' },
|
|
624
|
+
{ value: 'medium', label: 'Medium' },
|
|
625
|
+
{ value: 'large', label: 'Large' },
|
|
626
|
+
];
|
|
435
627
|
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
628
|
+
const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
|
|
629
|
+
event.preventDefault();
|
|
630
|
+
setSubmitted(true);
|
|
631
|
+
const message = value ? '' : 'This field is required';
|
|
632
|
+
setError(message);
|
|
633
|
+
if (!message) console.log('Submit value:', value);
|
|
443
634
|
};
|
|
444
635
|
|
|
445
636
|
return (
|
|
446
|
-
<
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
637
|
+
<form onSubmit={handleSubmit} noValidate>
|
|
638
|
+
<Select
|
|
639
|
+
items={items}
|
|
640
|
+
value={value}
|
|
641
|
+
onChange={(next) => {
|
|
642
|
+
const selected = Array.isArray(next) ? next[0] : next;
|
|
643
|
+
setValue(selected == null ? '' : String(selected));
|
|
644
|
+
if (submitted) setError(selected == null ? 'This field is required' : '');
|
|
645
|
+
}}
|
|
646
|
+
required
|
|
647
|
+
error={!!error}
|
|
648
|
+
errorMessage={error}
|
|
649
|
+
placeholder="Required field"
|
|
650
|
+
/>
|
|
651
|
+
{error && <p role="alert">{error}</p>}
|
|
652
|
+
<button type="submit">Submit</button>
|
|
653
|
+
</form>
|
|
455
654
|
);
|
|
456
655
|
}
|
|
457
656
|
```
|
|
@@ -459,10 +658,14 @@ function ValidationExample() {
|
|
|
459
658
|
### Using Ref for Imperative Actions
|
|
460
659
|
|
|
461
660
|
```tsx
|
|
462
|
-
import { Select, SelectHandle } from '@smilodon/react';
|
|
463
|
-
import { useRef } from 'react';
|
|
661
|
+
import { Select, type SelectHandle } from '@smilodon/react';
|
|
662
|
+
import { useRef, useState } from 'react';
|
|
464
663
|
|
|
465
664
|
function RefExample() {
|
|
665
|
+
const items = [
|
|
666
|
+
{ value: 'alpha', label: 'Alpha' },
|
|
667
|
+
{ value: 'beta', label: 'Beta' },
|
|
668
|
+
];
|
|
466
669
|
const selectRef = useRef<SelectHandle>(null);
|
|
467
670
|
const [value, setValue] = useState('');
|
|
468
671
|
|
|
@@ -504,7 +707,7 @@ Smilodon React provides **two powerful approaches** for defining select options,
|
|
|
504
707
|
- ✅ Auto-conversion from strings/numbers
|
|
505
708
|
- ✅ Perfect for basic dropdowns
|
|
506
709
|
- ✅ Works seamlessly with React state
|
|
507
|
-
- ✅
|
|
710
|
+
- ✅ Can render the datasets exercised in your application; no millions-of-items or constant-DOM guarantee is made
|
|
508
711
|
- ✅ Built-in search and filtering
|
|
509
712
|
- ✅ Full TypeScript type safety
|
|
510
713
|
|
|
@@ -625,7 +828,7 @@ function LargeDatasetExample() {
|
|
|
625
828
|
items={items}
|
|
626
829
|
value={id}
|
|
627
830
|
onChange={(val) => setId(val as string)}
|
|
628
|
-
virtualized // Enable
|
|
831
|
+
virtualized // Enable incremental chunk rendering; not viewport windowing
|
|
629
832
|
placeholder="Select from 100K items..."
|
|
630
833
|
/>
|
|
631
834
|
);
|
|
@@ -637,51 +840,72 @@ function LargeDatasetExample() {
|
|
|
637
840
|
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
841
|
|
|
639
842
|
#### Advanced scenarios (React)
|
|
640
|
-
- **
|
|
843
|
+
- **Accessibility labels**: use a literal `aria-label` for the internal combobox; host IDREF attributes are not forwarded across the shadow boundary:
|
|
641
844
|
```tsx
|
|
642
|
-
<
|
|
643
|
-
<Select id="user-picker" aria-
|
|
845
|
+
<span>Pick a user</span>
|
|
846
|
+
<Select id="user-picker" aria-label="Pick a user" onChange={(v, items) => {
|
|
644
847
|
console.log('Selected', items);
|
|
645
848
|
}}/>
|
|
646
849
|
```
|
|
647
|
-
- **Server-side lookup**:
|
|
850
|
+
- **Server-side lookup**: cancellation and request sequencing prevent an old response from overwriting newer results; the host also handles HTTP and transport errors:
|
|
648
851
|
```tsx
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
852
|
+
import { useEffect, useRef, useState } from 'react';
|
|
853
|
+
import { Select, type SelectItem } from '@smilodon/react';
|
|
854
|
+
|
|
855
|
+
function RemoteSearchExample() {
|
|
856
|
+
const [items, setItems] = useState<SelectItem[]>([]);
|
|
857
|
+
const [error, setError] = useState('');
|
|
858
|
+
const [loading, setLoading] = useState(false);
|
|
859
|
+
const requestId = useRef(0);
|
|
860
|
+
const controller = useRef<AbortController | null>(null);
|
|
861
|
+
useEffect(() => () => controller.current?.abort(), []);
|
|
862
|
+
async function handleSearch(query: string) {
|
|
863
|
+
const id = ++requestId.current;
|
|
864
|
+
controller.current?.abort();
|
|
865
|
+
if (!query) { setItems([]); setError(''); setLoading(false); return; }
|
|
866
|
+
const current = new AbortController(); controller.current = current;
|
|
867
|
+
setLoading(true);
|
|
868
|
+
setError('');
|
|
869
|
+
try {
|
|
870
|
+
const response = await fetch(`/api/users?q=${encodeURIComponent(query)}`, { signal: current.signal });
|
|
871
|
+
if (!response.ok) throw new Error(`Search failed: ${response.status}`);
|
|
872
|
+
const next = await response.json() as SelectItem[];
|
|
873
|
+
if (id === requestId.current) { setItems(next); setError(''); }
|
|
874
|
+
} catch (reason) {
|
|
875
|
+
if (!(reason instanceof DOMException && reason.name === 'AbortError') && id === requestId.current) setError(String(reason));
|
|
876
|
+
} finally {
|
|
877
|
+
if (id === requestId.current) setLoading(false);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return <><Select items={items} searchable onSearch={handleSearch} />{loading && <p role="status">Searching…</p>}{error && <p role="alert">{error}</p>}</>;
|
|
881
|
+
}
|
|
660
882
|
```
|
|
661
|
-
- **Heavy lists (100k+)**:
|
|
883
|
+
- **Heavy lists (100k+)**: `virtualized` does not guarantee bounded DOM; true viewport windowing is not a public production mode:
|
|
662
884
|
```tsx
|
|
663
885
|
const big = useMemo(() => Array.from({ length: 100_000 }, (_, i) => ({ value: i, label: `Row ${i}` })), []);
|
|
664
|
-
<Select items={big} virtualized
|
|
886
|
+
<Select items={big} virtualized />
|
|
665
887
|
```
|
|
666
888
|
|
|
667
|
-
**Use when**: You need rich
|
|
889
|
+
**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
890
|
|
|
669
891
|
**Advantages**:
|
|
670
892
|
- ✅ Full control over option rendering
|
|
671
|
-
- ✅ Render
|
|
893
|
+
- ✅ Render React-node content through the adapter's custom renderer
|
|
672
894
|
- ✅ Rich content (images, icons, badges, multi-line text)
|
|
673
895
|
- ✅ Custom styling with CSS-in-JS or Tailwind
|
|
674
|
-
- ✅
|
|
896
|
+
- ✅ Rich non-interactive option content; keep selection and keyboard interaction on the option itself
|
|
675
897
|
- ✅ Conditional rendering based on item data
|
|
676
|
-
- ✅
|
|
898
|
+
- ✅ Renderer lifecycle and context boundaries are documented below
|
|
677
899
|
- ✅ Perfect for complex UIs (user cards, product listings, etc.)
|
|
678
900
|
|
|
679
901
|
**How it works**: Provide a `customRenderer` function that returns `React.ReactNode` for each option.
|
|
680
902
|
|
|
903
|
+
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.
|
|
904
|
+
|
|
681
905
|
**Examples**:
|
|
682
906
|
|
|
683
907
|
```tsx
|
|
684
|
-
import { Select, SelectItem } from '@smilodon/react';
|
|
908
|
+
import { Select, type SelectItem } from '@smilodon/react';
|
|
685
909
|
import { useState } from 'react';
|
|
686
910
|
|
|
687
911
|
// Example 1: Simple custom template with icons
|
|
@@ -973,6 +1197,7 @@ function TaskSelect() {
|
|
|
973
1197
|
|
|
974
1198
|
// Example 5: Using Tailwind CSS (if available)
|
|
975
1199
|
// Note: Tailwind/CSS classes in customRenderer are supported inside Select options.
|
|
1200
|
+
// Map dynamic values to literal class names so Tailwind's static scanner can include them.
|
|
976
1201
|
// Core mirrors document stylesheets into shadow DOM for custom option rendering.
|
|
977
1202
|
interface Tag extends SelectItem {
|
|
978
1203
|
color: string;
|
|
@@ -982,6 +1207,12 @@ interface Tag extends SelectItem {
|
|
|
982
1207
|
function TailwindExample() {
|
|
983
1208
|
const [tag, setTag] = useState('');
|
|
984
1209
|
|
|
1210
|
+
const colorClasses: Record<string, string> = {
|
|
1211
|
+
blue: 'bg-blue-500',
|
|
1212
|
+
green: 'bg-green-500',
|
|
1213
|
+
red: 'bg-red-500',
|
|
1214
|
+
} as const;
|
|
1215
|
+
|
|
985
1216
|
const tags: Tag[] = [
|
|
986
1217
|
{ value: 'react', label: 'React', color: 'blue', count: 1250 },
|
|
987
1218
|
{ value: 'vue', label: 'Vue', color: 'green', count: 850 },
|
|
@@ -996,7 +1227,7 @@ function TailwindExample() {
|
|
|
996
1227
|
customRenderer={(item: Tag) => (
|
|
997
1228
|
<div className="flex items-center justify-between p-2">
|
|
998
1229
|
<div className="flex items-center gap-2">
|
|
999
|
-
<span className={`w-3 h-3 rounded-full
|
|
1230
|
+
<span className={`w-3 h-3 rounded-full ${colorClasses[item.color]}`} />
|
|
1000
1231
|
<span className="font-semibold text-gray-900">{item.label}</span>
|
|
1001
1232
|
</div>
|
|
1002
1233
|
<span className="text-sm text-gray-500">{item.count} posts</span>
|
|
@@ -1039,20 +1270,20 @@ function ComponentExample() {
|
|
|
1039
1270
|
|
|
1040
1271
|
| Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
|
|
1041
1272
|
|---------|------------------------|---------------------------|
|
|
1042
|
-
| **Setup
|
|
1043
|
-
| **Rendering
|
|
1044
|
-
| **
|
|
1045
|
-
| **React
|
|
1046
|
-
| **Component
|
|
1047
|
-
| **TypeScript
|
|
1048
|
-
| **
|
|
1049
|
-
| **
|
|
1273
|
+
| **Setup** | Pass an array of option data | Provide a renderer callback |
|
|
1274
|
+
| **Rendering behavior** | Shared runtime renders option labels | Adapter renders React-node option content |
|
|
1275
|
+
| **Customization** | Data-driven labels and state | Custom non-interactive content; nested controls are not promised |
|
|
1276
|
+
| **React integration** | Controlled/uncontrolled values and callbacks | Same adapter API with custom-rendered content |
|
|
1277
|
+
| **Component reuse** | Reuse data definitions | Return components; separate-root context limits apply |
|
|
1278
|
+
| **TypeScript** | Typed item data and props | Typed renderer callback and props |
|
|
1279
|
+
| **Very large datasets** | No 1M-item certification or performance comparison is claimed | No 1M-item certification or performance comparison is claimed |
|
|
1280
|
+
| **Choosing a method** | Direct for simple options | Use when custom content is required |
|
|
1050
1281
|
|
|
1051
1282
|
**Best Practices**:
|
|
1052
1283
|
|
|
1053
1284
|
✅ **Use Method 1 (Object Arrays) when**:
|
|
1054
1285
|
- You need simple text-based options
|
|
1055
|
-
-
|
|
1286
|
+
- 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
1287
|
- You want minimal code
|
|
1057
1288
|
- Built-in search/filter is sufficient
|
|
1058
1289
|
- Working with external APIs returning plain data
|
|
@@ -1100,7 +1331,7 @@ function EvolvingComponent() {
|
|
|
1100
1331
|
|
|
1101
1332
|
**For Method 1**:
|
|
1102
1333
|
- Use `useMemo` to memoize large item arrays
|
|
1103
|
-
-
|
|
1334
|
+
- The `virtualized` prop enables incremental chunk rendering, not viewport-windowed rendering.
|
|
1104
1335
|
- Enable `infiniteScroll` for dynamic loading
|
|
1105
1336
|
|
|
1106
1337
|
**For Method 2**:
|
|
@@ -1141,8 +1372,7 @@ function OptimizedExample() {
|
|
|
1141
1372
|
value={value}
|
|
1142
1373
|
onChange={(val) => setValue(val as string)}
|
|
1143
1374
|
customRenderer={renderer}
|
|
1144
|
-
virtualized // Enable
|
|
1145
|
-
estimatedItemHeight={60}
|
|
1375
|
+
virtualized // Enable incremental chunk rendering, not viewport windowing
|
|
1146
1376
|
/>
|
|
1147
1377
|
);
|
|
1148
1378
|
}
|
|
@@ -1169,13 +1399,21 @@ function OptimizedExample() {
|
|
|
1169
1399
|
| `errorMessage` | `string` | - | Error message to display |
|
|
1170
1400
|
| `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
|
|
1171
1401
|
| `pageSize` | `number` | `20` | Items per page (infinite scroll) |
|
|
1172
|
-
| `virtualized` | `boolean` | `false` | Enable
|
|
1173
|
-
| `estimatedItemHeight` | `number` | `48` |
|
|
1402
|
+
| `virtualized` | `boolean` | `false` | Enable legacy chunked rendering for large flat lists; not viewport windowing |
|
|
1403
|
+
| `estimatedItemHeight` | `number` | `48` | Exposed estimate used only by the guarded viewport-windowing test path; not a production tuning control |
|
|
1174
1404
|
| `maxSelections` | `number` | - | Max selections (multi-select) |
|
|
1175
1405
|
| `toggleOnTriggerClick` | `boolean` | `true` | Allow repeated trigger clicks to toggle the dropdown |
|
|
1176
1406
|
| `placement` | `string` | `"bottom-start"` | Dropdown placement |
|
|
1177
1407
|
| `className` | `string` | - | Custom CSS class |
|
|
1178
1408
|
| `style` | `CSSProperties` | - | Inline styles |
|
|
1409
|
+
| `selectionConfig`, `multiSelectDisplay`, `scrollToSelected`, `styles`, `config` | core configuration types | - | Shared runtime configuration groups |
|
|
1410
|
+
| `optionRenderer` | `(item, index, helpers) => HTMLElement` | - | DOM renderer; return safe DOM nodes and retain the single-option interaction model |
|
|
1411
|
+
| `customRenderer` | `(item, index) => React.ReactNode` | - | React-node option content; nested interactive controls are not promised |
|
|
1412
|
+
| `groupHeaderRenderer` | `(group, index) => React.ReactNode` | - | React-node grouped-header content |
|
|
1413
|
+
| `clearable`, `clearSelectionOnClear`, `clearSearchOnClear`, `clearAriaLabel`, `clearIcon` | booleans / strings | - | Clear-control configuration |
|
|
1414
|
+
| `onClear` | `(detail) => void` | - | Reports which selection/search state was cleared |
|
|
1415
|
+
| `onDiagnostic` | `(detail) => void` | - | Runtime diagnostic callback |
|
|
1416
|
+
| `trackingEnabled`, `trackEvents`, `trackStyling`, `trackLimitations`, `emitDiagnostics`, `trackingMaxEntries`, `limitationPolicies`, `autoMitigateRuntimeModeSwitch` | documented tracking/limitation types | - | Runtime tracking and limitation-policy configuration |
|
|
1179
1417
|
| `onChange` | `(value, items) => void` | - | Selection change callback |
|
|
1180
1418
|
| `onSelect` | `(item, index) => void` | - | Item select callback |
|
|
1181
1419
|
| `onOpen` | `() => void` | - | Dropdown open callback |
|
|
@@ -1481,6 +1719,11 @@ interface SelectHandle {
|
|
|
1481
1719
|
clearError: () => void;
|
|
1482
1720
|
setRequired: (required: boolean) => void;
|
|
1483
1721
|
validate: () => boolean;
|
|
1722
|
+
getCapabilities: () => SelectCapabilitiesReport | undefined;
|
|
1723
|
+
getKnownLimitations: () => LimitationState[];
|
|
1724
|
+
getTrackingSnapshot: () => TrackingSnapshot;
|
|
1725
|
+
clearTracking: (source?: 'event' | 'style' | 'limitation' | 'all') => void;
|
|
1726
|
+
setLimitationPolicies: (policies: LimitationPolicyMap) => void;
|
|
1484
1727
|
}
|
|
1485
1728
|
```
|
|
1486
1729
|
|
|
@@ -1509,15 +1752,15 @@ enhanced-select {
|
|
|
1509
1752
|
|
|
1510
1753
|
## Accessibility
|
|
1511
1754
|
|
|
1512
|
-
|
|
1755
|
+
Implemented keyboard and ARIA behaviors include:
|
|
1513
1756
|
|
|
1514
|
-
- ✅
|
|
1515
|
-
- ✅
|
|
1757
|
+
- ✅ Tested keyboard paths include Arrow keys, Enter, Escape, and Tab; this is not an exhaustive interaction certification
|
|
1758
|
+
- ✅ ARIA attributes and selected live-region announcements
|
|
1516
1759
|
- ✅ Focus management
|
|
1517
1760
|
- ✅ High contrast mode support
|
|
1518
1761
|
- ✅ Reduced motion support
|
|
1519
|
-
-
|
|
1520
|
-
-
|
|
1762
|
+
- Touch-target sizing is themeable; WCAG touch-target conformance has not been certified.
|
|
1763
|
+
- 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
1764
|
|
|
1522
1765
|
### Important: Passing inline functions as renderers
|
|
1523
1766
|
|
|
@@ -1535,26 +1778,22 @@ Adapters are designed to not loop even without memoization, but memoization stil
|
|
|
1535
1778
|
|
|
1536
1779
|
## Performance
|
|
1537
1780
|
|
|
1538
|
-
-
|
|
1781
|
+
- Incremental chunk rendering for large flat datasets; viewport windowing is not public/production-activated
|
|
1539
1782
|
- Lazy loading with infinite scroll
|
|
1540
|
-
-
|
|
1783
|
+
- React state and renderer stability guidance; the adapter does not promise an internal `React.memo` wrapper
|
|
1541
1784
|
- Tree-shakeable exports
|
|
1542
|
-
-
|
|
1785
|
+
- Bundle output depends on the consuming app and bundler; no version-specific size claim is made here
|
|
1543
1786
|
|
|
1544
1787
|
## Browser Support
|
|
1545
1788
|
|
|
1546
|
-
|
|
1547
|
-
- Firefox 88+
|
|
1548
|
-
- Safari 14+
|
|
1549
|
-
- iOS Safari 14+
|
|
1550
|
-
- Samsung Internet 14+
|
|
1789
|
+
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
1790
|
|
|
1552
1791
|
## TypeScript
|
|
1553
1792
|
|
|
1554
1793
|
Full TypeScript support with comprehensive type definitions included.
|
|
1555
1794
|
|
|
1556
1795
|
```tsx
|
|
1557
|
-
import { Select, SelectProps, SelectHandle, SelectItem } from '@smilodon/react';
|
|
1796
|
+
import { Select, type SelectProps, type SelectHandle, type SelectItem, type GroupedItem, type GlobalSelectConfig, type SelectCapabilitiesReport, type LimitationState, type TrackingSnapshot, type LimitationPolicyMap } from '@smilodon/react';
|
|
1558
1797
|
```
|
|
1559
1798
|
|
|
1560
1799
|
## License
|