@smilodon/react 1.10.1 → 1.12.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 +69 -0
- package/README.md +160 -0
- package/dist/index.cjs +158 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -41
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +15 -3
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/COMPLETE-GUIDE.md
CHANGED
|
@@ -141,6 +141,7 @@ interface SelectProps {
|
|
|
141
141
|
// Styling
|
|
142
142
|
className?: string;
|
|
143
143
|
style?: React.CSSProperties;
|
|
144
|
+
arrowIcon?: React.ReactNode;
|
|
144
145
|
|
|
145
146
|
// Advanced
|
|
146
147
|
virtualized?: boolean;
|
|
@@ -168,6 +169,7 @@ interface SelectProps {
|
|
|
168
169
|
| `estimatedItemHeight` | `number` | `48` | Passed to core config for the guarded viewport-windowing test path; it does not affect public chunk rendering |
|
|
169
170
|
| `className` | `string` | `undefined` | CSS class name |
|
|
170
171
|
| `style` | `React.CSSProperties` | `undefined` | Inline styles (CSS variables) |
|
|
172
|
+
| `arrowIcon` | `React.ReactNode` | `undefined` | Decorative content for the native arrow slot; custom content does not rotate automatically |
|
|
171
173
|
| `virtualized` | `boolean` | `false` | Enable incremental chunk rendering for large flat lists; not viewport windowing |
|
|
172
174
|
| `customRenderer` | `function` | `undefined` | Custom option renderer |
|
|
173
175
|
| `onOpen` | `() => void` | `undefined` | Called when dropdown opens |
|
|
@@ -677,6 +679,41 @@ function EventHandling() {
|
|
|
677
679
|
|
|
678
680
|
## Styling & Theming
|
|
679
681
|
|
|
682
|
+
### Active class mapping for custom-rendered options (Core #82)
|
|
683
|
+
|
|
684
|
+
Use `classMap.active` to supply application-specific active styles when using `customRenderer`. Core removes stale built-in aliases and old mapped classes when active focus changes:
|
|
685
|
+
|
|
686
|
+
```tsx
|
|
687
|
+
<Select
|
|
688
|
+
items={items}
|
|
689
|
+
customRenderer={(item) => <span>{item.label}</span>}
|
|
690
|
+
classMap={{ active: "my-active-option", selected: "my-selected-option" }}
|
|
691
|
+
/>
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
Active and selected are distinct states; use `data-sm-state` or the mapped classes when styling. The correction is in Core. See the [Core rendering contract](../core/README.md#active-state-on-custom-option-roots).
|
|
695
|
+
|
|
696
|
+
### Dropdown enter and exit animations (Core 1.12.0)
|
|
697
|
+
|
|
698
|
+
The shared Core supports independent animations controlled through inherited CSS variables:
|
|
699
|
+
|
|
700
|
+
```css
|
|
701
|
+
enhanced-select {
|
|
702
|
+
--select-dropdown-animation: dropdownEnter 220ms ease-out forwards;
|
|
703
|
+
--select-dropdown-exit-animation: dropdownExit 160ms ease-in forwards;
|
|
704
|
+
--select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
|
|
705
|
+
--select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
|
|
706
|
+
}
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
Exit updates `aria-expanded` and `close` synchronously while an inert visual panel finishes animating. Set `--select-dropdown-exit-animation: none` to disable exit. Reduced-motion preferences are honored. Core `1.12.0` is available from npm.
|
|
710
|
+
|
|
711
|
+
### Acknowledged pagination and rerender ownership (#85 — pending React release)
|
|
712
|
+
|
|
713
|
+
The locally prepared React fix synchronizes `items`/`groupedItems` only for actual input identity changes; presentation config changes must not overwrite accepted cumulative pages. Keep initial item references stable and use `completeDataRequest()` for acknowledged page results with the request ID and query generation. That fix is **not merged or released**; the public React 1.11.0 package cannot be assumed to contain it.
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
680
717
|
### Inline Styles with CSS Variables
|
|
681
718
|
|
|
682
719
|
```tsx
|
|
@@ -1240,6 +1277,38 @@ function AsyncSelect() {
|
|
|
1240
1277
|
}
|
|
1241
1278
|
```
|
|
1242
1279
|
|
|
1280
|
+
### Customizing the Core busy bucket
|
|
1281
|
+
|
|
1282
|
+
`loadingIcon` and `loadingContent` provide React nodes to Core's native `loading-icon` and `loading-content` slots. The adapter keeps these nodes in the custom element's light DOM and React owns their lifecycle; Core controls when the slot projection is visible.
|
|
1283
|
+
|
|
1284
|
+
```tsx
|
|
1285
|
+
<Select
|
|
1286
|
+
items={items}
|
|
1287
|
+
infiniteScroll
|
|
1288
|
+
config={{
|
|
1289
|
+
busyBucket: {
|
|
1290
|
+
enabled: true,
|
|
1291
|
+
showSpinner: false,
|
|
1292
|
+
showMessage: true,
|
|
1293
|
+
message: 'Loading…',
|
|
1294
|
+
minDisplayTime: 200,
|
|
1295
|
+
contentMode: 'replace',
|
|
1296
|
+
},
|
|
1297
|
+
}}
|
|
1298
|
+
loadingIcon={<MyLoadingIcon />}
|
|
1299
|
+
loadingContent={(
|
|
1300
|
+
<div>
|
|
1301
|
+
<strong>Loading more options…</strong>
|
|
1302
|
+
<span>Additional results will appear shortly.</span>
|
|
1303
|
+
</div>
|
|
1304
|
+
)}
|
|
1305
|
+
/>
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
`append` is the default `contentMode` and shows the built-in UI alongside custom content. `replace` shows only accessible custom content and hides the icon and message regions; otherwise Core retains its “Loading…” fallback. Keep meaningful text in replacement content so assistive technology has a status to announce. In append mode, the icon is decorative and separate from `arrowIcon`.
|
|
1309
|
+
|
|
1310
|
+
The busy bucket is presentation only. `minDisplayTime` may keep it visible briefly after completion, but never delays the data coordinator, page advancement, or `aria-busy`. Custom nodes remain mounted while the bucket is hidden; gate animation or expensive work through application state. The existing `Searching...` state has its own rendering path.
|
|
1311
|
+
|
|
1243
1312
|
### With React Hook Form
|
|
1244
1313
|
|
|
1245
1314
|
```tsx
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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
4
|
|
|
5
|
+
> **Upcoming web release:** React `1.12.0` and Core `1.17.0` are release candidates, not yet available from npm. Their cumulative changes and qualification limits are tracked in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md).
|
|
6
|
+
|
|
5
7
|
> 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).
|
|
6
8
|
|
|
7
9
|
## 📖 Documentation
|
|
@@ -176,6 +178,7 @@ The coordinator rejects stale responses by request ID and query generation; the
|
|
|
176
178
|
|
|
177
179
|
### Other useful scenarios
|
|
178
180
|
|
|
181
|
+
- **Terminal empty remote search (#92):** When the host completes the matching acknowledged request with `status: 'exhausted'`, `items: []`, and `hasMore: false`, Core displays the query-specific no-results message after successful projection. React consumers do not need a manual rerender, popup toggle, or `setItems([])` workaround. Wait for `onDataProjection` with `status: 'complete'` before relying on the projected DOM; `completeDataRequest()` returning `accepted` reports response acceptance, not DOM settlement. An empty page with `status: 'empty'` and `hasMore: true` is nonterminal. This guidance does not include the separate React #85 fix.
|
|
179
182
|
- **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
183
|
- **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
184
|
- **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.
|
|
@@ -184,6 +187,75 @@ The coordinator rejects stale responses by request ID and query generation; the
|
|
|
184
187
|
- **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
188
|
- **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.
|
|
186
189
|
|
|
190
|
+
### Custom busy bucket (React 1.12.0; requires Core 1.13.0)
|
|
191
|
+
|
|
192
|
+
Introduced in `@smilodon/react@1.12.0`, `loadingIcon` and `loadingContent` expose Core's native loading slots. Use `@smilodon/core@^1.13.0`. These are React-owned light-DOM children; Core projects them into its Shadow DOM busy bucket without creating another React root.
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
<Select
|
|
196
|
+
items={items}
|
|
197
|
+
infiniteScroll
|
|
198
|
+
config={{
|
|
199
|
+
busyBucket: {
|
|
200
|
+
enabled: true,
|
|
201
|
+
showSpinner: false,
|
|
202
|
+
showMessage: true,
|
|
203
|
+
message: 'Loading…',
|
|
204
|
+
minDisplayTime: 200,
|
|
205
|
+
contentMode: 'append',
|
|
206
|
+
},
|
|
207
|
+
}}
|
|
208
|
+
loadingIcon={<MyLoadingIcon />}
|
|
209
|
+
loadingContent={(
|
|
210
|
+
<div>
|
|
211
|
+
<strong>Loading more products…</strong>
|
|
212
|
+
<span>Please wait.</span>
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
/>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Use `contentMode: 'replace'` when accessible `loadingContent` should be the only visible bucket content; Core hides the icon and message regions. If no accessible replacement is supplied, Core retains a “Loading…” fallback. In append mode, `loadingIcon` is decorative and does not affect `arrowIcon`; `loadingContent` is independent of `items`. React keeps both custom nodes mounted in the light DOM while busy UI is hidden, so start expensive work only from the request callback or explicit application state.
|
|
219
|
+
|
|
220
|
+
`minDisplayTime` is a presentation policy for the busy bucket, not a request delay. Request acceptance, pagination state, and `aria-busy` update as soon as the request completes. The dedicated `Searching...` view remains unchanged and is not replaced by these props.
|
|
221
|
+
|
|
222
|
+
### Latest-chip auto-scroll (React 1.12.0 candidate; Issue #100)
|
|
223
|
+
|
|
224
|
+
In horizontal multi-select mode, `multiSelectDisplay.scrollToLatestChip` reveals a newly selected chip. It is opt-in and respects reduced-motion preferences. This behavior requires the pending Core `1.17.0` release; the adapter versions listed in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md) are not yet on npm.
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
<Select
|
|
228
|
+
items={items}
|
|
229
|
+
multiple
|
|
230
|
+
multiSelectDisplay={{
|
|
231
|
+
mode: 'horizontal',
|
|
232
|
+
overflowX: 'auto',
|
|
233
|
+
scrollToLatestChip: true,
|
|
234
|
+
scrollToLatestChipBehavior: 'smooth',
|
|
235
|
+
}}
|
|
236
|
+
/>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Custom empty-state renderer (React 1.12.0 candidate; Issue #93)
|
|
240
|
+
|
|
241
|
+
`emptyStateRenderer` receives Core's readonly `{ query, reason }` context only while a terminal empty state is active. React renders its result in Core's native `empty-state` slot; omit the prop to keep the built-in fallback. `onEmptyStateChange` receives the new context and receives `null` when the empty state clears. The imperative handle also exposes `getEmptyStateContext()`.
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<Select
|
|
245
|
+
items={items}
|
|
246
|
+
searchable
|
|
247
|
+
emptyStateRenderer={({ query, reason }) => (
|
|
248
|
+
<div role="status">
|
|
249
|
+
<EmptyResultsIcon aria-hidden="true" />
|
|
250
|
+
<span>{reason === 'no-options' ? 'No options yet' : `No results for “${query}”`}</span>
|
|
251
|
+
</div>
|
|
252
|
+
)}
|
|
253
|
+
onEmptyStateChange={(context) => console.log('Empty state:', context)}
|
|
254
|
+
/>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
This is a presentation API; it does not change the behavior of `items`, acknowledged request completion, or selection.
|
|
258
|
+
|
|
187
259
|
## Infinite Render Loop: Root-Cause Review (No External Dependencies)
|
|
188
260
|
|
|
189
261
|
If you see `Maximum update depth exceeded`, follow this checklist before shipping:
|
|
@@ -1403,6 +1475,7 @@ function OptimizedExample() {
|
|
|
1403
1475
|
| `estimatedItemHeight` | `number` | `48` | Exposed estimate used only by the guarded viewport-windowing test path; not a production tuning control |
|
|
1404
1476
|
| `maxSelections` | `number` | - | Max selections (multi-select) |
|
|
1405
1477
|
| `toggleOnTriggerClick` | `boolean` | `true` | Allow repeated trigger clicks to toggle the dropdown |
|
|
1478
|
+
| `arrowIcon` | `React.ReactNode` | - | Decorative custom arrow content; defaults to the built-in chevron and does not rotate automatically |
|
|
1406
1479
|
| `placement` | `string` | `"bottom-start"` | Dropdown placement |
|
|
1407
1480
|
| `className` | `string` | - | Custom CSS class |
|
|
1408
1481
|
| `style` | `CSSProperties` | - | Inline styles |
|
|
@@ -1423,6 +1496,31 @@ function OptimizedExample() {
|
|
|
1423
1496
|
| `creatable` | `boolean` | `false` | Allow creating new options |
|
|
1424
1497
|
| `onCreate` | `(label) => void` | - | Create option callback |
|
|
1425
1498
|
|
|
1499
|
+
### Custom arrow icon
|
|
1500
|
+
|
|
1501
|
+
Available in `@smilodon/react@1.11.0` with `@smilodon/core@1.11.0`, pass any React node as `arrowIcon`. It is rendered in the native `arrow` slot and marked decorative; Core continues to own pointer and open/close behavior. The built-in SVG remains the fallback when the prop is omitted or `null`. Custom content is not automatically rotated; use the host's `data-open` attribute if it should rotate:
|
|
1502
|
+
|
|
1503
|
+
```tsx
|
|
1504
|
+
<Select
|
|
1505
|
+
className="custom-arrow-select"
|
|
1506
|
+
items={items}
|
|
1507
|
+
arrowIcon={<MyChevron />}
|
|
1508
|
+
/>
|
|
1509
|
+
```
|
|
1510
|
+
|
|
1511
|
+
```css
|
|
1512
|
+
.custom-arrow-select > .smilodon-custom-arrow {
|
|
1513
|
+
display: inline-flex;
|
|
1514
|
+
transition: transform 180ms ease;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
.custom-arrow-select[data-open="true"] > .smilodon-custom-arrow {
|
|
1518
|
+
transform: rotate(180deg);
|
|
1519
|
+
}
|
|
1520
|
+
```
|
|
1521
|
+
|
|
1522
|
+
The default arrow hover background is suppressed while custom arrow content is assigned. Custom icon color and transform are not set by Core.
|
|
1523
|
+
|
|
1426
1524
|
### Multi-select chip styling
|
|
1427
1525
|
|
|
1428
1526
|
Selected chips in multi-select mode use softer default pill styles and remain fully customizable. Target them with `::part(chip)`, `::part(chip-label)`, `::part(chip-remove)`, and `::part(chip-remove-icon)`, or override CSS variables such as `--select-badge-bg`, `--select-badge-border`, `--select-badge-color`, `--select-badge-shadow`, `--select-badge-width`, `--select-badge-height`, `--select-badge-remove-size`, `--select-badge-remove-icon-size`, and `--select-multi-input-min-width`.
|
|
@@ -1511,6 +1609,28 @@ You can replace the default chip remove icon with the `removeButtonIcon` prop:
|
|
|
1511
1609
|
|
|
1512
1610
|
Markup strings are supported too, so inline SVG icons work.
|
|
1513
1611
|
|
|
1612
|
+
React components are also supported, including generated icon components:
|
|
1613
|
+
|
|
1614
|
+
```tsx
|
|
1615
|
+
import TrashIcon from '@/generated/icons/Trash.icon';
|
|
1616
|
+
|
|
1617
|
+
<Select
|
|
1618
|
+
items={items}
|
|
1619
|
+
multiple
|
|
1620
|
+
defaultValue={['one']}
|
|
1621
|
+
removeButtonIcon={<TrashIcon />}
|
|
1622
|
+
/>
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
The React node is displayed inside Core's existing remove buttons in selected
|
|
1626
|
+
chips and selected dropdown options. Remove behavior, accessibility labels, and
|
|
1627
|
+
`chip-remove` / `chip-remove-icon` parts remain Core-owned. Strings still
|
|
1628
|
+
render as the legacy text or inline SVG markup. The prop supports React nodes,
|
|
1629
|
+
**not** a component function passed directly: use `<TrashIcon />`, not
|
|
1630
|
+
`TrashIcon`. When `config.selection.removeButtonIcon` is explicitly
|
|
1631
|
+
supplied, that Core string configuration takes precedence. React nodes are
|
|
1632
|
+
supported by the React adapter only, not Core or other framework adapters.
|
|
1633
|
+
|
|
1514
1634
|
To style the icon separately from the round remove button, use the host `style` prop with these tokens:
|
|
1515
1635
|
|
|
1516
1636
|
- `--select-badge-remove-icon-size`
|
|
@@ -1727,6 +1847,46 @@ interface SelectHandle {
|
|
|
1727
1847
|
}
|
|
1728
1848
|
```
|
|
1729
1849
|
|
|
1850
|
+
## Dropdown animation controls (Core 1.12.0)
|
|
1851
|
+
|
|
1852
|
+
React consumers can customize entry and exit animations through inherited Core CSS variables, without a new React prop:
|
|
1853
|
+
|
|
1854
|
+
```tsx
|
|
1855
|
+
<Select items={items} className="animated-select" />
|
|
1856
|
+
```
|
|
1857
|
+
|
|
1858
|
+
```css
|
|
1859
|
+
enhanced-select.animated-select {
|
|
1860
|
+
--select-dropdown-animation: dropdownEnter 250ms ease-out forwards;
|
|
1861
|
+
--select-dropdown-exit-animation: dropdownExit 180ms ease-in forwards;
|
|
1862
|
+
--select-dropdown-exit-to-opacity: 0;
|
|
1863
|
+
--select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
|
|
1864
|
+
--select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
|
|
1865
|
+
}
|
|
1866
|
+
```
|
|
1867
|
+
|
|
1868
|
+
Set either animation to `none` to disable it. The close event and ARIA close immediately, while the visual dropdown becomes inert and exits. Reopening cancels an unfinished exit; reduced-motion preferences are respected. Core `1.12.0` is available on npm, and React `1.11.0` declares `@smilodon/core: ^1.11.0`, which accepts it. See [engineering notes](../../docs/architecture/DROPDOWN-EXIT-ANIMATION.md).
|
|
1869
|
+
|
|
1870
|
+
### Custom active classes — Issue #82 (Core)
|
|
1871
|
+
|
|
1872
|
+
When rendering custom option content, set `classMap.active` to the class names used by your application's active-state styles. Core now removes both legacy `active`/`sm-active` aliases and previously configured active classes as focus moves; an inactive option no longer matches `.option.active` accidentally.
|
|
1873
|
+
|
|
1874
|
+
```tsx
|
|
1875
|
+
<Select
|
|
1876
|
+
items={items}
|
|
1877
|
+
customRenderer={(item) => <span>{item.label}</span>}
|
|
1878
|
+
classMap={{ active: "my-option-active", selected: "my-option-selected" }}
|
|
1879
|
+
/>
|
|
1880
|
+
```
|
|
1881
|
+
|
|
1882
|
+
The option's `data-sm-state`, `aria-selected`, and classes reflect independent active/selected semantics. The fix is in Core, not in React's renderer. See [Issue #82](https://github.com/navidrezadoost/Smilodon/issues/82) and the [Core rendering guide](../core/README.md#active-state-on-custom-option-roots).
|
|
1883
|
+
|
|
1884
|
+
### Acknowledged pagination on React rerenders — Issue #85 (unreleased)
|
|
1885
|
+
|
|
1886
|
+
The reported local fix for [Issue #85](https://github.com/navidrezadoost/Smilodon/issues/85) is qualified **but not yet pushed, merged, or published**. In acknowledged loading, React's `items` prop can supply the initial page while Core accepts cumulative pages using `completeDataRequest()`. Equivalent or newly allocated `config`, `multiSelectDisplay`, and `disabledOptionBehavior` objects must not force Core to revert its accepted cumulative snapshot to the initial `items`.
|
|
1887
|
+
|
|
1888
|
+
The pending fix moves `items`/`groupedItems` synchronization into one identity-guarded effect, independent of presentation configuration, and applies uncontrolled `defaultValue` after item registration. New `items` or `groupedItems` identities still represent deliberate updates; `setItems()` alone is not an acknowledged coordinator reset. Keep input references stable where the input is unchanged, complete requests with their exact request IDs and generations, and consult the final release notes before expecting this fix in published packages.
|
|
1889
|
+
|
|
1730
1890
|
## Styling
|
|
1731
1891
|
|
|
1732
1892
|
The component uses Shadow DOM for style encapsulation. You can customize it using CSS custom properties:
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
26
26
|
const jsxRuntime = require("react/jsx-runtime");
|
|
27
27
|
const React = require("react");
|
|
28
28
|
const client = require("react-dom/client");
|
|
29
|
+
const reactDom = require("react-dom");
|
|
29
30
|
const core = require("@smilodon/core");
|
|
30
31
|
const DEFAULT_DATA_LOADING_CONFIG = {
|
|
31
32
|
protocol: "legacy",
|
|
@@ -49,7 +50,7 @@ function composeBusyToken(consumerValue, externalBusy) {
|
|
|
49
50
|
return consumerValue;
|
|
50
51
|
}
|
|
51
52
|
const Select = React.forwardRef((props, ref) => {
|
|
52
|
-
var _a, _b;
|
|
53
|
+
var _a, _b, _c;
|
|
53
54
|
const {
|
|
54
55
|
items = [],
|
|
55
56
|
groupedItems,
|
|
@@ -73,6 +74,10 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
73
74
|
styles: stylesConfig,
|
|
74
75
|
config: coreConfig,
|
|
75
76
|
removeButtonIcon,
|
|
77
|
+
arrowIcon,
|
|
78
|
+
loadingIcon,
|
|
79
|
+
loadingContent,
|
|
80
|
+
emptyStateRenderer,
|
|
76
81
|
disabledOptionBehavior,
|
|
77
82
|
showSelectedIndicator = true,
|
|
78
83
|
toggleOnTriggerClick = true,
|
|
@@ -100,6 +105,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
100
105
|
onDataRequestCancel,
|
|
101
106
|
onDataProjection,
|
|
102
107
|
onDataLoadingConfigError,
|
|
108
|
+
onEmptyStateChange,
|
|
103
109
|
trackingEnabled = false,
|
|
104
110
|
trackEvents = true,
|
|
105
111
|
trackStyling = true,
|
|
@@ -141,6 +147,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
141
147
|
onDataRequestCancel,
|
|
142
148
|
onDataProjection,
|
|
143
149
|
onDataLoadingConfigError,
|
|
150
|
+
onEmptyStateChange,
|
|
144
151
|
isControlled,
|
|
145
152
|
multiple
|
|
146
153
|
});
|
|
@@ -156,6 +163,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
156
163
|
onDataRequestCancel,
|
|
157
164
|
onDataProjection,
|
|
158
165
|
onDataLoadingConfigError,
|
|
166
|
+
onEmptyStateChange,
|
|
159
167
|
isControlled,
|
|
160
168
|
multiple
|
|
161
169
|
};
|
|
@@ -302,7 +310,10 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
302
310
|
reactRendererCache.current.clear();
|
|
303
311
|
}, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
|
|
304
312
|
const [isElementReady, setIsElementReady] = React.useState(false);
|
|
305
|
-
const
|
|
313
|
+
const [emptyStateContext, setEmptyStateContext] = React.useState(null);
|
|
314
|
+
const [removeIconTargets, setRemoveIconTargets] = React.useState([]);
|
|
315
|
+
const shouldPortalRemoveIcon = multiple && removeButtonIcon != null && typeof removeButtonIcon !== "string" && typeof removeButtonIcon !== "boolean" && ((_a = coreConfig == null ? void 0 : coreConfig.selection) == null ? void 0 : _a.removeButtonIcon) === void 0;
|
|
316
|
+
const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
|
|
306
317
|
const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
|
|
307
318
|
const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
|
|
308
319
|
const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
|
|
@@ -409,7 +420,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
409
420
|
},
|
|
410
421
|
[markUnusable, syncHostBusy]
|
|
411
422
|
);
|
|
412
|
-
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((
|
|
423
|
+
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_c = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _c.protocol) === "acknowledged";
|
|
413
424
|
const qualifyAcknowledgedElement = React.useCallback(() => {
|
|
414
425
|
const element = elementRef.current;
|
|
415
426
|
const module2 = coreModuleRef.current;
|
|
@@ -427,16 +438,17 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
427
438
|
return true;
|
|
428
439
|
}, [markUnusable]);
|
|
429
440
|
const subscribeToCoreEvents = React.useCallback((element) => {
|
|
441
|
+
var _a2;
|
|
430
442
|
const currentSubscription = activeListenersRef.current;
|
|
431
443
|
if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
|
|
432
444
|
currentSubscription == null ? void 0 : currentSubscription.dispose();
|
|
433
445
|
const handleSelect = (event) => {
|
|
434
|
-
var
|
|
446
|
+
var _a3, _b2;
|
|
435
447
|
const detail = event.detail;
|
|
436
|
-
(_b2 = (
|
|
448
|
+
(_b2 = (_a3 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a3, detail.item, detail.index);
|
|
437
449
|
};
|
|
438
450
|
const handleChange = (event) => {
|
|
439
|
-
var
|
|
451
|
+
var _a3;
|
|
440
452
|
const { selectedItems, selectedValues } = event.detail;
|
|
441
453
|
const callbacks = callbackStateRef.current;
|
|
442
454
|
const values = selectedValues;
|
|
@@ -445,19 +457,19 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
445
457
|
if (!callbacks.isControlled) {
|
|
446
458
|
setInternalValue(callbacks.multiple ? values : nextSingleValue);
|
|
447
459
|
}
|
|
448
|
-
(
|
|
460
|
+
(_a3 = callbacks.onChange) == null ? void 0 : _a3.call(
|
|
449
461
|
callbacks,
|
|
450
462
|
callbacks.multiple ? values : nextSingleValue,
|
|
451
463
|
selectedItems
|
|
452
464
|
);
|
|
453
465
|
};
|
|
454
466
|
const handleOpen = () => {
|
|
455
|
-
var
|
|
456
|
-
return (_b2 = (
|
|
467
|
+
var _a3, _b2;
|
|
468
|
+
return (_b2 = (_a3 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a3);
|
|
457
469
|
};
|
|
458
470
|
const handleClose = () => {
|
|
459
|
-
var
|
|
460
|
-
return (_b2 = (
|
|
471
|
+
var _a3, _b2;
|
|
472
|
+
return (_b2 = (_a3 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a3);
|
|
461
473
|
};
|
|
462
474
|
const handleSearch = (event) => {
|
|
463
475
|
const { query, results, count, request } = event.detail;
|
|
@@ -474,40 +486,46 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
474
486
|
else callback(page);
|
|
475
487
|
};
|
|
476
488
|
const handleClear = (event) => {
|
|
477
|
-
var
|
|
489
|
+
var _a3, _b2;
|
|
478
490
|
const { clearedSelection, clearedSearch } = event.detail;
|
|
479
|
-
(_b2 = (
|
|
491
|
+
(_b2 = (_a3 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a3, { clearedSelection, clearedSearch });
|
|
480
492
|
};
|
|
481
493
|
const handleDiagnostic = (event) => {
|
|
482
|
-
var
|
|
483
|
-
(_b2 = (
|
|
484
|
-
|
|
494
|
+
var _a3, _b2;
|
|
495
|
+
(_b2 = (_a3 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
|
|
496
|
+
_a3,
|
|
485
497
|
event.detail
|
|
486
498
|
);
|
|
487
499
|
};
|
|
488
500
|
const handleDataRequestCancel = (event) => {
|
|
489
|
-
var
|
|
490
|
-
(_b2 = (
|
|
491
|
-
|
|
501
|
+
var _a3, _b2;
|
|
502
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
|
|
503
|
+
_a3,
|
|
492
504
|
event.detail
|
|
493
505
|
);
|
|
494
506
|
};
|
|
495
507
|
const handleDataProjection = (event) => {
|
|
496
|
-
var
|
|
497
|
-
(_b2 = (
|
|
498
|
-
|
|
508
|
+
var _a3, _b2;
|
|
509
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
|
|
510
|
+
_a3,
|
|
499
511
|
event.detail
|
|
500
512
|
);
|
|
501
513
|
};
|
|
502
514
|
const handleDataLoadingConfigError = (event) => {
|
|
503
|
-
var
|
|
515
|
+
var _a3, _b2;
|
|
504
516
|
const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
|
|
505
517
|
if (activeUpdate) activeUpdate.sawConfigError = true;
|
|
506
|
-
(_b2 = (
|
|
507
|
-
|
|
518
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
|
|
519
|
+
_a3,
|
|
508
520
|
event.detail
|
|
509
521
|
);
|
|
510
522
|
};
|
|
523
|
+
const handleEmptyStateChange = (event) => {
|
|
524
|
+
var _a3, _b2;
|
|
525
|
+
const context = event.detail.context;
|
|
526
|
+
setEmptyStateContext(context);
|
|
527
|
+
(_b2 = (_a3 = callbackStateRef.current).onEmptyStateChange) == null ? void 0 : _b2.call(_a3, context);
|
|
528
|
+
};
|
|
511
529
|
const listeners = [
|
|
512
530
|
["select", handleSelect],
|
|
513
531
|
["change", handleChange],
|
|
@@ -519,14 +537,18 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
519
537
|
["diagnostic", handleDiagnostic],
|
|
520
538
|
["dataRequestCancel", handleDataRequestCancel],
|
|
521
539
|
["dataProjection", handleDataProjection],
|
|
522
|
-
["dataLoadingConfigError", handleDataLoadingConfigError]
|
|
540
|
+
["dataLoadingConfigError", handleDataLoadingConfigError],
|
|
541
|
+
["emptyStateChange", handleEmptyStateChange]
|
|
523
542
|
];
|
|
524
543
|
for (const [name, listener] of listeners) {
|
|
525
544
|
element.addEventListener(name, listener);
|
|
526
545
|
}
|
|
546
|
+
setEmptyStateContext(
|
|
547
|
+
((_a2 = element.getEmptyStateContext) == null ? void 0 : _a2.call(element)) ?? null
|
|
548
|
+
);
|
|
527
549
|
const dispose = () => {
|
|
528
|
-
var
|
|
529
|
-
if (((
|
|
550
|
+
var _a3;
|
|
551
|
+
if (((_a3 = activeListenersRef.current) == null ? void 0 : _a3.dispose) === dispose) {
|
|
530
552
|
activeListenersRef.current = null;
|
|
531
553
|
}
|
|
532
554
|
for (const [name, listener] of listeners) {
|
|
@@ -643,7 +665,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
643
665
|
...selectionConfig,
|
|
644
666
|
mode: multiple ? "multi" : "single",
|
|
645
667
|
maxSelections,
|
|
646
|
-
removeButtonIcon,
|
|
668
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
647
669
|
disabledOptionBehavior,
|
|
648
670
|
showSelectedIndicator,
|
|
649
671
|
toggleOnTriggerClick
|
|
@@ -796,7 +818,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
796
818
|
...selectionConfig,
|
|
797
819
|
mode: multiple ? "multi" : "single",
|
|
798
820
|
maxSelections,
|
|
799
|
-
removeButtonIcon,
|
|
821
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
800
822
|
disabledOptionBehavior,
|
|
801
823
|
showSelectedIndicator,
|
|
802
824
|
toggleOnTriggerClick
|
|
@@ -873,6 +895,48 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
873
895
|
isElementUsable,
|
|
874
896
|
applyInstanceConfig
|
|
875
897
|
]);
|
|
898
|
+
React.useEffect(() => {
|
|
899
|
+
const element = elementRef.current;
|
|
900
|
+
const shadow = element == null ? void 0 : element.shadowRoot;
|
|
901
|
+
if (!isElementUsable || !shouldPortalRemoveIcon || !shadow) {
|
|
902
|
+
setRemoveIconTargets((previous) => previous.length ? [] : previous);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const observed = /* @__PURE__ */ new Set();
|
|
906
|
+
let currentTargets = [];
|
|
907
|
+
let disposed = false;
|
|
908
|
+
const observer = new MutationObserver(() => refresh());
|
|
909
|
+
const refresh = () => {
|
|
910
|
+
if (disposed) return;
|
|
911
|
+
const optionRoots = Array.from(shadow.querySelectorAll("select-option")).map((option) => option.shadowRoot).filter((root) => root !== null);
|
|
912
|
+
const roots = [shadow, ...optionRoots];
|
|
913
|
+
if (roots.length !== observed.size || roots.some((root) => !observed.has(root))) {
|
|
914
|
+
observer.disconnect();
|
|
915
|
+
observed.clear();
|
|
916
|
+
for (const root of roots) {
|
|
917
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
918
|
+
observed.add(root);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const targets = [
|
|
922
|
+
...Array.from(shadow.querySelectorAll('[part="chip-remove-icon"]')),
|
|
923
|
+
...optionRoots.flatMap(
|
|
924
|
+
(root) => Array.from(root.querySelectorAll('[part="chip-remove-icon"]'))
|
|
925
|
+
)
|
|
926
|
+
];
|
|
927
|
+
if (targets.length === currentTargets.length && targets.every((target, index) => target === currentTargets[index])) return;
|
|
928
|
+
for (const target of targets) {
|
|
929
|
+
if (!currentTargets.includes(target)) target.replaceChildren();
|
|
930
|
+
}
|
|
931
|
+
currentTargets = targets;
|
|
932
|
+
setRemoveIconTargets(targets);
|
|
933
|
+
};
|
|
934
|
+
refresh();
|
|
935
|
+
return () => {
|
|
936
|
+
disposed = true;
|
|
937
|
+
observer.disconnect();
|
|
938
|
+
};
|
|
939
|
+
}, [isElementUsable, shouldPortalRemoveIcon]);
|
|
876
940
|
React.useEffect(() => {
|
|
877
941
|
const element = elementRef.current;
|
|
878
942
|
if (!element || !isElementUsable) return;
|
|
@@ -940,7 +1004,13 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
940
1004
|
React.useImperativeHandle(ref, () => ({
|
|
941
1005
|
focus: () => {
|
|
942
1006
|
var _a2;
|
|
943
|
-
|
|
1007
|
+
const element = elementRef.current;
|
|
1008
|
+
const input = (_a2 = element == null ? void 0 : element.shadowRoot) == null ? void 0 : _a2.querySelector("input");
|
|
1009
|
+
if (input instanceof HTMLElement) {
|
|
1010
|
+
input.focus();
|
|
1011
|
+
} else {
|
|
1012
|
+
element == null ? void 0 : element.focus();
|
|
1013
|
+
}
|
|
944
1014
|
},
|
|
945
1015
|
open: () => {
|
|
946
1016
|
var _a2;
|
|
@@ -958,6 +1028,10 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
958
1028
|
var _a2;
|
|
959
1029
|
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
|
|
960
1030
|
},
|
|
1031
|
+
getEmptyStateContext: () => {
|
|
1032
|
+
var _a2, _b2;
|
|
1033
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getEmptyStateContext) == null ? void 0 : _b2.call(_a2)) ?? null;
|
|
1034
|
+
},
|
|
961
1035
|
setItems: (items2) => {
|
|
962
1036
|
var _a2;
|
|
963
1037
|
(_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
|
|
@@ -994,12 +1068,12 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
994
1068
|
applyInstanceConfig(element, config);
|
|
995
1069
|
},
|
|
996
1070
|
getDataLoadingState: () => {
|
|
997
|
-
var _a2, _b2,
|
|
1071
|
+
var _a2, _b2, _c2;
|
|
998
1072
|
const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
|
|
999
1073
|
if (snapshot) return snapshot;
|
|
1000
1074
|
return {
|
|
1001
1075
|
status: "idle",
|
|
1002
|
-
connected: Boolean((
|
|
1076
|
+
connected: Boolean((_c2 = elementRef.current) == null ? void 0 : _c2.isConnected),
|
|
1003
1077
|
busy: false,
|
|
1004
1078
|
projectionPending: false,
|
|
1005
1079
|
queryGeneration: 0,
|
|
@@ -1069,14 +1143,57 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
1069
1143
|
onChange
|
|
1070
1144
|
]);
|
|
1071
1145
|
const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1146
|
+
const renderedEmptyState = emptyStateContext && emptyStateRenderer ? emptyStateRenderer(emptyStateContext) : null;
|
|
1147
|
+
return React.createElement(
|
|
1148
|
+
"enhanced-select",
|
|
1149
|
+
{
|
|
1150
|
+
ref: elementRef,
|
|
1151
|
+
...hostProps,
|
|
1152
|
+
"aria-busy": renderedAriaBusy,
|
|
1153
|
+
"data-custom-arrow": arrowIcon != null ? "true" : void 0,
|
|
1154
|
+
class: className,
|
|
1155
|
+
dir: direction,
|
|
1156
|
+
style
|
|
1157
|
+
},
|
|
1158
|
+
arrowIcon != null ? React.createElement(
|
|
1159
|
+
"span",
|
|
1160
|
+
{
|
|
1161
|
+
slot: "arrow",
|
|
1162
|
+
className: "smilodon-custom-arrow",
|
|
1163
|
+
"aria-hidden": "true"
|
|
1164
|
+
},
|
|
1165
|
+
arrowIcon
|
|
1166
|
+
) : null,
|
|
1167
|
+
loadingIcon != null ? React.createElement(
|
|
1168
|
+
"span",
|
|
1169
|
+
{
|
|
1170
|
+
slot: "loading-icon",
|
|
1171
|
+
className: "smilodon-loading-icon",
|
|
1172
|
+
"aria-hidden": "true"
|
|
1173
|
+
},
|
|
1174
|
+
loadingIcon
|
|
1175
|
+
) : null,
|
|
1176
|
+
loadingContent != null ? React.createElement(
|
|
1177
|
+
"div",
|
|
1178
|
+
{
|
|
1179
|
+
slot: "loading-content",
|
|
1180
|
+
className: "smilodon-loading-content"
|
|
1181
|
+
},
|
|
1182
|
+
loadingContent
|
|
1183
|
+
) : null,
|
|
1184
|
+
renderedEmptyState != null && typeof renderedEmptyState !== "boolean" ? React.createElement(
|
|
1185
|
+
"div",
|
|
1186
|
+
{ slot: "empty-state", className: "smilodon-empty-state" },
|
|
1187
|
+
renderedEmptyState
|
|
1188
|
+
) : null,
|
|
1189
|
+
shouldPortalRemoveIcon ? removeIconTargets.map(
|
|
1190
|
+
(target, index) => reactDom.createPortal(
|
|
1191
|
+
React.createElement("span", { "aria-hidden": "true" }, removeButtonIcon),
|
|
1192
|
+
target,
|
|
1193
|
+
index
|
|
1194
|
+
)
|
|
1195
|
+
) : null
|
|
1196
|
+
);
|
|
1080
1197
|
});
|
|
1081
1198
|
Select.displayName = "Select";
|
|
1082
1199
|
Object.defineProperty(exports, "configureSelect", {
|