@delacour/react-native-ui 0.7.1-alpha.20261105120531 → 0.7.1-alpha.20261105130819
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/package.json +3 -3
- package/src/components/select/AGENTS.md +6 -3
- package/src/components/select/select-trigger.tsx +4 -1
- package/src/components/select/select.render.test.tsx +69 -0
- package/src/components/select/select.tsx +17 -15
- package/src/components/select/select.variants.test.ts +3 -0
- package/src/components/select/select.variants.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.7.1-alpha.
|
|
3
|
+
"version": "0.7.1-alpha.20261105130819",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
"expo-blur": ">=15",
|
|
187
187
|
"@maplibre/maplibre-react-native": "^11.5.0",
|
|
188
188
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
189
|
-
"@delacour/react-native-bottom-sheet": "0.7.1-alpha.
|
|
190
|
-
"@delacour/react-native-charts": "0.7.1-alpha.
|
|
189
|
+
"@delacour/react-native-bottom-sheet": "0.7.1-alpha.20261105130819",
|
|
190
|
+
"@delacour/react-native-charts": "0.7.1-alpha.20261105130819",
|
|
191
191
|
"@legendapp/list": ">=3.3",
|
|
192
192
|
"react-native-skia": ">=3.9.0",
|
|
193
193
|
"expo-linear-gradient": ">=15",
|
|
@@ -74,12 +74,15 @@ engine. An app that imports no picker still never resolves it.
|
|
|
74
74
|
reached" (`limitReachedText`).
|
|
75
75
|
- **`onClose` is the sheet's, not the state's.** It is passed straight to `BottomSheet` and runs once the sheet has finished sliding down, later than `onValueChange` or the open state turning false. Move focus from here, never from the pick.
|
|
76
76
|
- **Multiple never closes on a pick.** A sticky `Done` footer closes it; every
|
|
77
|
-
close path — a pick, Done, a swipe, the overlay, the close button
|
|
78
|
-
|
|
77
|
+
close path — a pick, Done, a swipe, the overlay, the close button, or a
|
|
78
|
+
controlled `isOpen` set to false — clears the query, because the clear reads
|
|
79
|
+
the resolved open state, not the sheet's callback.
|
|
79
80
|
- **The title and search ride at the head of the list.** As
|
|
80
81
|
`ListHeaderComponent` they count towards the content height the sheet sizes
|
|
81
82
|
itself to, and the search field is a `BottomSheet.TextInput`, so the keyboard
|
|
82
|
-
it raises is the sheet's to lift for.
|
|
83
|
+
it raises is the sheet's to lift for. The close sits in a row of its own with
|
|
84
|
+
the title (`headerBar`), not in the sheet's absolute corner, so with no title
|
|
85
|
+
it still never covers the search field or the first row.
|
|
83
86
|
- **A sheet sized to its rows is capped.** `resolveSelectSheetMaxHeight` hands
|
|
84
87
|
the sheet `maxDynamicContentSize` — the lower of 85% of the window and the room
|
|
85
88
|
below the top inset less a 24pt gap — and the list scrolls inside it. Without
|
|
@@ -114,9 +114,12 @@ export function SelectTrigger({ asChild = false, className, children, ...props }
|
|
|
114
114
|
testID,
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
// Only a disabled select disables the child. An enabled one passes nothing,
|
|
118
|
+
// so a child that is disabled on its own stays disabled.
|
|
117
119
|
if (asChild) {
|
|
120
|
+
const disabled = isDisabled ? { disabled: true } : undefined;
|
|
118
121
|
return (
|
|
119
|
-
<Slot {...accessibility} disabled={
|
|
122
|
+
<Slot {...accessibility} {...disabled} className={className} onPress={open} {...props}>
|
|
120
123
|
{children}
|
|
121
124
|
</Slot>
|
|
122
125
|
);
|
|
@@ -2,6 +2,7 @@ import { describe, expect, jest, test } from "@jest/globals";
|
|
|
2
2
|
import { type ReactElement, type ReactNode, useState } from "react";
|
|
3
3
|
import { fireEvent, renderWithProviders, screen, waitFor } from "../../test/render";
|
|
4
4
|
import { BottomSheetProvider } from "../bottom-sheet";
|
|
5
|
+
import { Button } from "../button";
|
|
5
6
|
import { Field } from "../field";
|
|
6
7
|
import { Text } from "../text";
|
|
7
8
|
import { Select, type SelectProps } from "./select";
|
|
@@ -22,6 +23,11 @@ const trigger = (name = "Choose") => screen.getByRole("button", { name });
|
|
|
22
23
|
const valueText = () => trigger().props.accessibilityValue?.text;
|
|
23
24
|
const openSheet = async (name?: string) => tap(trigger(name));
|
|
24
25
|
|
|
26
|
+
/** Prints the className it receives, so a test can see what a Slot handed it. */
|
|
27
|
+
function ClassProbe({ className }: { className?: string }): ReactElement {
|
|
28
|
+
return <Text testID="probe">{className ?? ""}</Text>;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
function renderSelect(props: SelectProps = {}) {
|
|
26
32
|
return renderWithProviders(<Select options={OPTIONS} placeholder="Choose" testID="select" {...props} />, {
|
|
27
33
|
wrapper: Sheets,
|
|
@@ -89,6 +95,33 @@ describe("Select trigger", () => {
|
|
|
89
95
|
);
|
|
90
96
|
expect(screen.getByRole("button", { name: "Role picker" })).toBeOnTheScreen();
|
|
91
97
|
});
|
|
98
|
+
|
|
99
|
+
test("an enabled select leaves a disabled asChild child disabled and closed", async () => {
|
|
100
|
+
await renderWithProviders(
|
|
101
|
+
<Select options={OPTIONS} placeholder="Choose">
|
|
102
|
+
<Select.Trigger asChild>
|
|
103
|
+
<Button isDisabled>Sort</Button>
|
|
104
|
+
</Select.Trigger>
|
|
105
|
+
</Select>,
|
|
106
|
+
{ wrapper: Sheets }
|
|
107
|
+
);
|
|
108
|
+
const sort = screen.getByRole("button", { name: "Choose" });
|
|
109
|
+
expect(sort).toBeDisabled();
|
|
110
|
+
await tap(sort);
|
|
111
|
+
expect(screen.queryByRole("radio", { name: "Designer" })).not.toBeOnTheScreen();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("an asChild trigger hands its className to the child", async () => {
|
|
115
|
+
await renderWithProviders(
|
|
116
|
+
<Select options={OPTIONS} placeholder="Choose">
|
|
117
|
+
<Select.Trigger asChild className="self-start">
|
|
118
|
+
<ClassProbe />
|
|
119
|
+
</Select.Trigger>
|
|
120
|
+
</Select>,
|
|
121
|
+
{ wrapper: Sheets }
|
|
122
|
+
);
|
|
123
|
+
expect(screen.getByTestId("probe").props.children).toBe("self-start");
|
|
124
|
+
});
|
|
92
125
|
});
|
|
93
126
|
|
|
94
127
|
describe("Select single", () => {
|
|
@@ -369,6 +402,13 @@ describe("Select search", () => {
|
|
|
369
402
|
expect(screen.getByRole("radio", { name: "Österreich" })).toBeOnTheScreen();
|
|
370
403
|
});
|
|
371
404
|
|
|
405
|
+
test("without a title the close holds its own row above the search", async () => {
|
|
406
|
+
await renderSelect({ isSearchable: true, options: countries });
|
|
407
|
+
await openSheet();
|
|
408
|
+
const close = screen.getByTestId("select-close");
|
|
409
|
+
expect(close.props.className).not.toContain("absolute");
|
|
410
|
+
});
|
|
411
|
+
|
|
372
412
|
test("a non-searchable sheet has no search field", async () => {
|
|
373
413
|
await renderSelect({ options: countries });
|
|
374
414
|
await openSheet();
|
|
@@ -384,6 +424,17 @@ describe("Select search", () => {
|
|
|
384
424
|
await openSheet();
|
|
385
425
|
expect(screen.getByRole("radio", { name: "Austria" })).toBeOnTheScreen();
|
|
386
426
|
});
|
|
427
|
+
|
|
428
|
+
test("the query clears when a controlled sheet is closed by its owner", async () => {
|
|
429
|
+
const view = await renderSelect({ isOpen: true, isSearchable: true, options: countries });
|
|
430
|
+
await fireEvent.changeText(screen.getByLabelText("Search"), "zur");
|
|
431
|
+
await view.rerender(
|
|
432
|
+
<Select isOpen={false} isSearchable options={countries} placeholder="Choose" testID="select" />
|
|
433
|
+
);
|
|
434
|
+
await waitFor(() => expect(screen.queryByLabelText("Search")).not.toBeOnTheScreen());
|
|
435
|
+
await view.rerender(<Select isOpen isSearchable options={countries} placeholder="Choose" testID="select" />);
|
|
436
|
+
expect(screen.getByRole("radio", { name: "Austria" })).toBeOnTheScreen();
|
|
437
|
+
});
|
|
387
438
|
});
|
|
388
439
|
|
|
389
440
|
describe("Select states", () => {
|
|
@@ -438,6 +489,24 @@ describe("Select in a Field", () => {
|
|
|
438
489
|
expect(screen.getByRole("button", { name: "Opted out" }).props.accessibilityState.disabled).toBe(false);
|
|
439
490
|
});
|
|
440
491
|
|
|
492
|
+
test("the search field takes neither the Field's disabled nor its invalid state", async () => {
|
|
493
|
+
await renderWithProviders(
|
|
494
|
+
<Field isDisabled isInvalid>
|
|
495
|
+
<Field.Label>Role</Field.Label>
|
|
496
|
+
<Select isDisabled={false} isSearchable options={OPTIONS} placeholder="Choose" />
|
|
497
|
+
</Field>,
|
|
498
|
+
{ wrapper: Sheets }
|
|
499
|
+
);
|
|
500
|
+
await openSheet("Role");
|
|
501
|
+
const search = screen.getByLabelText("Search");
|
|
502
|
+
const group = search.parent?.parent;
|
|
503
|
+
expect(String(group?.props.className)).toContain("border");
|
|
504
|
+
expect(String(group?.props.className)).not.toContain("border-destructive");
|
|
505
|
+
// The test portal renders in place, under the Field's disabled row, so
|
|
506
|
+
// read the field's own prop rather than the tree's enabled state.
|
|
507
|
+
expect(search.props.editable).not.toBe(false);
|
|
508
|
+
});
|
|
509
|
+
|
|
441
510
|
test("the Field.Label text titles the sheet", async () => {
|
|
442
511
|
await renderWithProviders(
|
|
443
512
|
<Field>
|
|
@@ -177,16 +177,13 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
177
177
|
if (canOpen) setOpen(true);
|
|
178
178
|
}, [canOpen, setOpen]);
|
|
179
179
|
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
[setOpen]
|
|
188
|
-
);
|
|
189
|
-
const close = useCallback(() => handleOpenChange(false), [handleOpenChange]);
|
|
180
|
+
// Every close clears the search, so the next open starts whole. This reads
|
|
181
|
+
// the resolved state, not the sheet's callback, so a controlled `isOpen`
|
|
182
|
+
// that its owner sets to false clears it too.
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (!isOpen) setQuery("");
|
|
185
|
+
}, [isOpen]);
|
|
186
|
+
const close = useCallback(() => setOpen(false), [setOpen]);
|
|
190
187
|
|
|
191
188
|
const maxSelected = multiple?.maxSelected;
|
|
192
189
|
const isClearable = single?.isClearable ?? false;
|
|
@@ -281,13 +278,18 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
281
278
|
};
|
|
282
279
|
|
|
283
280
|
// The title and the search field ride at the head of the list rather than
|
|
284
|
-
// above it, so they count towards the height the sheet sizes itself to.
|
|
281
|
+
// above it, so they count towards the height the sheet sizes itself to. The
|
|
282
|
+
// close sits in the title's row, so it covers nothing when there is no title.
|
|
283
|
+
// The search group opts out of the enclosing Field's state: the sheet only
|
|
284
|
+
// opens when the select is enabled, and a query is never the invalid value.
|
|
285
285
|
const header = (
|
|
286
286
|
<View className={slots.header()}>
|
|
287
|
-
<
|
|
288
|
-
|
|
287
|
+
<View className={slots.headerBar()}>
|
|
288
|
+
{sheetTitle ? <BottomSheet.Title className={slots.headerTitle()}>{sheetTitle}</BottomSheet.Title> : null}
|
|
289
|
+
<BottomSheet.Close className={slots.headerClose()} testID={testID ? `${testID}-close` : undefined} />
|
|
290
|
+
</View>
|
|
289
291
|
{isSearchable ? (
|
|
290
|
-
<Input.Group size={size}>
|
|
292
|
+
<Input.Group isDisabled={false} isInvalid={false} size={size}>
|
|
291
293
|
<Input.Group.Prefix>
|
|
292
294
|
<Icon icon={IconMagnifyingGlass} />
|
|
293
295
|
</Input.Group.Prefix>
|
|
@@ -328,7 +330,7 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
328
330
|
keyboardLiftLimit="maxDynamicContentSize"
|
|
329
331
|
maxDynamicContentSize={sheetMaxHeight}
|
|
330
332
|
onClose={onClose}
|
|
331
|
-
onOpenChange={
|
|
333
|
+
onOpenChange={setOpen}
|
|
332
334
|
snapPoints={snapPoints}
|
|
333
335
|
>
|
|
334
336
|
<BottomSheet.Portal>
|
|
@@ -139,6 +139,17 @@ export const selectVariants = tv({
|
|
|
139
139
|
groupHeading: "pb-1.5 pt-4",
|
|
140
140
|
/** The sheet's title and search field, above the rows. */
|
|
141
141
|
header: "gap-3 pb-3",
|
|
142
|
+
/**
|
|
143
|
+
* The close and the optional title, in one row above the search.
|
|
144
|
+
*
|
|
145
|
+
* The row is always drawn, so the close has room of its own with or
|
|
146
|
+
* without a title, and never sits over the search field or a row.
|
|
147
|
+
*/
|
|
148
|
+
headerBar: "min-h-10 flex-row items-center gap-3",
|
|
149
|
+
/** The sheet's close, taken out of its absolute corner and into the bar. */
|
|
150
|
+
headerClose: "relative top-0 right-0 ml-auto",
|
|
151
|
+
/** The bar already clears the close, so the title needs no gutter. */
|
|
152
|
+
headerTitle: "flex-1 pr-0",
|
|
142
153
|
empty: "items-center justify-center py-8",
|
|
143
154
|
/** Overrides the sheet's list gutter gap: rows touch, the way a list's do. */
|
|
144
155
|
sheetBody: "gap-0",
|