@pickle-ui/react 1.0.0-beta.14 → 1.0.0-beta.15
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/README.md +22 -12
- package/dist/components/Alert.d.ts +1 -1
- package/dist/components/Alert.d.ts.map +1 -1
- package/dist/components/Alert.js.map +1 -1
- package/dist/components/AlertDialog.d.ts.map +1 -1
- package/dist/components/AlertDialog.js +3 -3
- package/dist/components/AlertDialog.js.map +1 -1
- package/dist/components/Avatar.d.ts +1 -1
- package/dist/components/Avatar.d.ts.map +1 -1
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/Badge.d.ts +2 -2
- package/dist/components/Badge.d.ts.map +1 -1
- package/dist/components/Badge.js.map +1 -1
- package/dist/components/Button.d.ts +2 -2
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +1 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.d.ts +1 -1
- package/dist/components/Card.d.ts.map +1 -1
- package/dist/components/Card.js +1 -1
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog.js.map +1 -1
- package/dist/components/Drawer.d.ts +2 -2
- package/dist/components/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer.js.map +1 -1
- package/dist/components/Flex.d.ts +7 -7
- package/dist/components/Flex.d.ts.map +1 -1
- package/dist/components/Grid.d.ts +42 -42
- package/dist/components/Grid.d.ts.map +1 -1
- package/dist/components/Grid.js +4 -3
- package/dist/components/Grid.js.map +1 -1
- package/dist/components/Group.d.ts.map +1 -1
- package/dist/components/Group.js.map +1 -1
- package/dist/components/Menu.d.ts +1 -1
- package/dist/components/Menu.d.ts.map +1 -1
- package/dist/components/Menu.js +1 -1
- package/dist/components/Menu.js.map +1 -1
- package/dist/components/Popover.d.ts.map +1 -1
- package/dist/components/Popover.js.map +1 -1
- package/dist/components/Progress.d.ts +1 -1
- package/dist/components/Progress.d.ts.map +1 -1
- package/dist/components/Progress.js +1 -1
- package/dist/components/Progress.js.map +1 -1
- package/dist/components/ScrollArea.d.ts.map +1 -1
- package/dist/components/ScrollArea.js +1 -1
- package/dist/components/ScrollArea.js.map +1 -1
- package/dist/components/Separator.d.ts.map +1 -1
- package/dist/components/Separator.js.map +1 -1
- package/dist/components/Sidebar.d.ts.map +1 -1
- package/dist/components/Sidebar.js +1 -1
- package/dist/components/Sidebar.js.map +1 -1
- package/dist/components/Spinner.d.ts.map +1 -1
- package/dist/components/Spinner.js.map +1 -1
- package/dist/components/Table.d.ts +1 -1
- package/dist/components/Table.d.ts.map +1 -1
- package/dist/components/Table.js +2 -2
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js.map +1 -1
- package/dist/components/Toast.d.ts.map +1 -1
- package/dist/components/Toast.js +1 -1
- package/dist/components/Toast.js.map +1 -1
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip.d.ts.map +1 -1
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/components/XStack.d.ts.map +1 -1
- package/dist/components/XStack.js.map +1 -1
- package/dist/components/YStack.d.ts.map +1 -1
- package/dist/components/YStack.js.map +1 -1
- package/dist/components/_internal/VisuallyHiddenInput.d.ts.map +1 -1
- package/dist/components/_internal/VisuallyHiddenInput.js +2 -4
- package/dist/components/_internal/VisuallyHiddenInput.js.map +1 -1
- package/dist/components/_internal/dialog-styles.d.ts +1 -1
- package/dist/components/_internal/dialog-styles.d.ts.map +1 -1
- package/dist/components/_internal/dialog-styles.js.map +1 -1
- package/dist/components/_internal/layout.d.ts +27 -27
- package/dist/components/_internal/layout.d.ts.map +1 -1
- package/dist/components/_internal/layout.js +1 -1
- package/dist/components/_internal/layout.js.map +1 -1
- package/dist/components/_internal/separate.d.ts +1 -1
- package/dist/components/_internal/separate.d.ts.map +1 -1
- package/dist/components/_internal/separate.js.map +1 -1
- package/dist/components/form/Checkbox.d.ts.map +1 -1
- package/dist/components/form/Checkbox.js.map +1 -1
- package/dist/components/form/ColorPicker.d.ts.map +1 -1
- package/dist/components/form/ColorPicker.js.map +1 -1
- package/dist/components/form/ColorPickerPrimitive.d.ts.map +1 -1
- package/dist/components/form/ColorPickerPrimitive.js +9 -14
- package/dist/components/form/ColorPickerPrimitive.js.map +1 -1
- package/dist/components/form/Combobox.d.ts.map +1 -1
- package/dist/components/form/Combobox.js +11 -12
- package/dist/components/form/Combobox.js.map +1 -1
- package/dist/components/form/Form.context.d.ts.map +1 -1
- package/dist/components/form/Form.context.js +2 -4
- package/dist/components/form/Form.context.js.map +1 -1
- package/dist/components/form/Form.d.ts +1 -1
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/form/FormCheckbox.d.ts.map +1 -1
- package/dist/components/form/FormCheckbox.js.map +1 -1
- package/dist/components/form/FormCombobox.d.ts +1 -1
- package/dist/components/form/FormCombobox.d.ts.map +1 -1
- package/dist/components/form/FormCombobox.js +1 -1
- package/dist/components/form/FormCombobox.js.map +1 -1
- package/dist/components/form/FormField.d.ts.map +1 -1
- package/dist/components/form/FormField.js +1 -1
- package/dist/components/form/FormField.js.map +1 -1
- package/dist/components/form/FormInput.d.ts.map +1 -1
- package/dist/components/form/FormInput.js +1 -1
- package/dist/components/form/FormInput.js.map +1 -1
- package/dist/components/form/FormInputGroup.d.ts.map +1 -1
- package/dist/components/form/FormInputGroup.js +2 -6
- package/dist/components/form/FormInputGroup.js.map +1 -1
- package/dist/components/form/FormRadioGroup.d.ts +1 -1
- package/dist/components/form/FormRadioGroup.d.ts.map +1 -1
- package/dist/components/form/FormSwitch.d.ts.map +1 -1
- package/dist/components/form/FormSwitch.js.map +1 -1
- package/dist/components/form/FormTextarea.d.ts.map +1 -1
- package/dist/components/form/FormTextarea.js +1 -1
- package/dist/components/form/FormTextarea.js.map +1 -1
- package/dist/components/form/Input.d.ts.map +1 -1
- package/dist/components/form/Input.js.map +1 -1
- package/dist/components/form/InputGroup.d.ts +1 -1
- package/dist/components/form/InputGroup.d.ts.map +1 -1
- package/dist/components/form/InputGroup.js.map +1 -1
- package/dist/components/form/RadioGroup.d.ts.map +1 -1
- package/dist/components/form/RadioGroup.js.map +1 -1
- package/dist/components/form/Select.d.ts.map +1 -1
- package/dist/components/form/Select.js +1 -1
- package/dist/components/form/Select.js.map +1 -1
- package/dist/components/form/Slider.d.ts +1 -1
- package/dist/components/form/Slider.d.ts.map +1 -1
- package/dist/components/form/Slider.js.map +1 -1
- package/dist/components/form/Switch.d.ts.map +1 -1
- package/dist/components/form/Switch.js.map +1 -1
- package/dist/components/form/Textarea.d.ts.map +1 -1
- package/dist/components/form/Textarea.js.map +1 -1
- package/dist/entries/checkbox.d.ts +1 -1
- package/dist/entries/checkbox.d.ts.map +1 -1
- package/dist/entries/group.d.ts +1 -1
- package/dist/entries/group.d.ts.map +1 -1
- package/dist/entries/radio-group.d.ts +1 -1
- package/dist/entries/radio-group.d.ts.map +1 -1
- package/dist/lib/color.d.ts +1 -1
- package/dist/lib/color.d.ts.map +1 -1
- package/dist/lib/color.js +1 -3
- package/dist/lib/color.js.map +1 -1
- package/dist/lib/compose-refs.js +1 -1
- package/dist/lib/compose-refs.js.map +1 -1
- package/package.json +35 -34
- package/skills/pickle-ui-react/SKILL.md +38 -0
- package/src/agent-skill.test.ts +30 -0
- package/src/components/Alert.test.tsx +3 -12
- package/src/components/Alert.tsx +2 -4
- package/src/components/AlertDialog.stories.tsx +10 -35
- package/src/components/AlertDialog.test.tsx +6 -23
- package/src/components/AlertDialog.tsx +12 -40
- package/src/components/Avatar.stories.tsx +3 -8
- package/src/components/Avatar.tsx +4 -18
- package/src/components/Badge.stories.tsx +1 -5
- package/src/components/Badge.test.tsx +1 -4
- package/src/components/Badge.tsx +5 -14
- package/src/components/Button.stories.tsx +4 -16
- package/src/components/Button.test.tsx +8 -9
- package/src/components/Button.tsx +2 -7
- package/src/components/Card.stories.tsx +1 -3
- package/src/components/Card.test.tsx +1 -3
- package/src/components/Card.tsx +1 -9
- package/src/components/Dialog.stories.tsx +9 -23
- package/src/components/Dialog.test.tsx +6 -23
- package/src/components/Dialog.tsx +4 -17
- package/src/components/Drawer.stories.tsx +9 -34
- package/src/components/Drawer.test.tsx +8 -29
- package/src/components/Drawer.tsx +4 -15
- package/src/components/Grid.stories.tsx +1 -4
- package/src/components/Grid.test.tsx +1 -3
- package/src/components/Grid.tsx +4 -4
- package/src/components/Group.stories.tsx +4 -20
- package/src/components/Group.test.tsx +2 -9
- package/src/components/Group.tsx +3 -12
- package/src/components/Menu.stories.tsx +5 -18
- package/src/components/Menu.test.tsx +11 -17
- package/src/components/Menu.tsx +7 -27
- package/src/components/Popover.stories.tsx +4 -10
- package/src/components/Popover.tsx +3 -13
- package/src/components/Progress.tsx +5 -24
- package/src/components/ScrollArea.test.tsx +4 -6
- package/src/components/ScrollArea.tsx +10 -28
- package/src/components/Separator.test.tsx +2 -8
- package/src/components/Separator.tsx +1 -5
- package/src/components/Sidebar.stories.tsx +1 -5
- package/src/components/Sidebar.tsx +4 -22
- package/src/components/Spinner.tsx +1 -5
- package/src/components/Table.stories.tsx +1 -3
- package/src/components/Table.tsx +5 -30
- package/src/components/Text.stories.tsx +8 -13
- package/src/components/Text.tsx +1 -4
- package/src/components/Toast.test.tsx +6 -17
- package/src/components/Toast.tsx +4 -17
- package/src/components/Tooltip.stories.tsx +6 -28
- package/src/components/Tooltip.test.tsx +2 -8
- package/src/components/Tooltip.tsx +3 -12
- package/src/components/XStack.stories.tsx +4 -8
- package/src/components/XStack.test.tsx +9 -20
- package/src/components/XStack.tsx +2 -13
- package/src/components/YStack.stories.tsx +2 -8
- package/src/components/YStack.tsx +2 -13
- package/src/components/_internal/Story.tsx +6 -23
- package/src/components/_internal/VisuallyHiddenInput.tsx +4 -9
- package/src/components/_internal/dialog-styles.ts +1 -2
- package/src/components/_internal/layout.ts +1 -7
- package/src/components/_internal/separate.tsx +6 -9
- package/src/components/form/Checkbox.test.tsx +5 -16
- package/src/components/form/Checkbox.tsx +1 -4
- package/src/components/form/ColorPicker.stories.tsx +3 -10
- package/src/components/form/ColorPicker.test.tsx +1 -3
- package/src/components/form/ColorPicker.tsx +2 -6
- package/src/components/form/ColorPickerPrimitive.tsx +40 -151
- package/src/components/form/Combobox.stories.tsx +7 -31
- package/src/components/form/Combobox.test.tsx +10 -27
- package/src/components/form/Combobox.tsx +31 -89
- package/src/components/form/Form.context.ts +5 -19
- package/src/components/form/Form.stories.tsx +6 -28
- package/src/components/form/Form.test.tsx +21 -38
- package/src/components/form/FormCheckbox.tsx +1 -5
- package/src/components/form/FormCombobox.tsx +4 -10
- package/src/components/form/FormField.tsx +4 -15
- package/src/components/form/FormInput.tsx +2 -12
- package/src/components/form/FormInputGroup.tsx +3 -11
- package/src/components/form/FormSwitch.tsx +1 -5
- package/src/components/form/FormTextarea.tsx +3 -11
- package/src/components/form/Input.stories.tsx +1 -5
- package/src/components/form/Input.test.tsx +20 -31
- package/src/components/form/Input.tsx +1 -4
- package/src/components/form/InputGroup.stories.tsx +4 -23
- package/src/components/form/InputGroup.tsx +5 -10
- package/src/components/form/RadioGroup.test.tsx +14 -28
- package/src/components/form/RadioGroup.tsx +1 -5
- package/src/components/form/Select.stories.tsx +2 -10
- package/src/components/form/Select.test.tsx +4 -14
- package/src/components/form/Select.tsx +9 -38
- package/src/components/form/Slider.stories.tsx +7 -17
- package/src/components/form/Slider.test.tsx +4 -12
- package/src/components/form/Slider.tsx +4 -20
- package/src/components/form/Switch.test.tsx +3 -9
- package/src/components/form/Switch.tsx +2 -9
- package/src/components/form/Textarea.test.tsx +2 -6
- package/src/components/form/Textarea.tsx +1 -6
- package/src/entries/checkbox.ts +1 -4
- package/src/entries/group.ts +1 -5
- package/src/entries/radio-group.ts +1 -4
- package/src/lib/color.test.ts +2 -6
- package/src/lib/color.ts +3 -11
- package/src/lib/compose-refs.ts +1 -1
- package/src/public-api.test.ts +7 -8
|
@@ -11,14 +11,10 @@ type ComboboxChipProps = React.ComponentProps<typeof ComboboxPrimitive.Chip> & {
|
|
|
11
11
|
classNames?: SlotClassNames<'remove'>;
|
|
12
12
|
removeLabel?: string;
|
|
13
13
|
};
|
|
14
|
-
type ComboboxChipsInputProps = React.ComponentProps<
|
|
15
|
-
typeof ComboboxPrimitive.Input
|
|
16
|
-
>;
|
|
14
|
+
type ComboboxChipsInputProps = React.ComponentProps<typeof ComboboxPrimitive.Input>;
|
|
17
15
|
type ComboboxChipsProps = React.ComponentProps<typeof ComboboxPrimitive.Chips>;
|
|
18
16
|
type ComboboxClearProps = React.ComponentProps<typeof ComboboxPrimitive.Clear>;
|
|
19
|
-
type ComboboxCollectionProps = React.ComponentProps<
|
|
20
|
-
typeof ComboboxPrimitive.Collection
|
|
21
|
-
>;
|
|
17
|
+
type ComboboxCollectionProps = React.ComponentProps<typeof ComboboxPrimitive.Collection>;
|
|
22
18
|
type ComboboxContentProps = Pick<
|
|
23
19
|
React.ComponentProps<typeof ComboboxPrimitive.Positioner>,
|
|
24
20
|
'align' | 'anchor' | 'side' | 'sideOffset'
|
|
@@ -35,14 +31,9 @@ type ComboboxCreateItem = {
|
|
|
35
31
|
value: string;
|
|
36
32
|
};
|
|
37
33
|
type ComboboxEmptyProps = React.ComponentProps<typeof ComboboxPrimitive.Empty>;
|
|
38
|
-
type ComboboxGroupLabelProps = React.ComponentProps<
|
|
39
|
-
typeof ComboboxPrimitive.GroupLabel
|
|
40
|
-
>;
|
|
34
|
+
type ComboboxGroupLabelProps = React.ComponentProps<typeof ComboboxPrimitive.GroupLabel>;
|
|
41
35
|
type ComboboxGroupProps = React.ComponentProps<typeof ComboboxPrimitive.Group>;
|
|
42
|
-
type ComboboxInputProps = Omit<
|
|
43
|
-
React.ComponentProps<typeof ComboboxPrimitive.Input>,
|
|
44
|
-
'size'
|
|
45
|
-
> &
|
|
36
|
+
type ComboboxInputProps = Omit<React.ComponentProps<typeof ComboboxPrimitive.Input>, 'size'> &
|
|
46
37
|
Pick<InputProps, 'size'> & {
|
|
47
38
|
showClear?: boolean;
|
|
48
39
|
showTrigger?: boolean;
|
|
@@ -74,15 +65,9 @@ type ComboboxProps<
|
|
|
74
65
|
*/
|
|
75
66
|
onCreate?: (inputValue: string) => undefined | Value;
|
|
76
67
|
};
|
|
77
|
-
type ComboboxSeparatorProps = React.ComponentProps<
|
|
78
|
-
|
|
79
|
-
>;
|
|
80
|
-
type ComboboxStatusProps = React.ComponentProps<
|
|
81
|
-
typeof ComboboxPrimitive.Status
|
|
82
|
-
>;
|
|
83
|
-
type ComboboxTriggerProps = React.ComponentProps<
|
|
84
|
-
typeof ComboboxPrimitive.Trigger
|
|
85
|
-
>;
|
|
68
|
+
type ComboboxSeparatorProps = React.ComponentProps<typeof ComboboxPrimitive.Separator>;
|
|
69
|
+
type ComboboxStatusProps = React.ComponentProps<typeof ComboboxPrimitive.Status>;
|
|
70
|
+
type ComboboxTriggerProps = React.ComponentProps<typeof ComboboxPrimitive.Trigger>;
|
|
86
71
|
type ComboboxValueProps = React.ComponentProps<typeof ComboboxPrimitive.Value>;
|
|
87
72
|
|
|
88
73
|
const CREATE_ITEM = Symbol('pickle-ui.combobox.create');
|
|
@@ -90,9 +75,7 @@ const CREATE_ITEM = Symbol('pickle-ui.combobox.create');
|
|
|
90
75
|
const EMPTY_VALUE: never[] = [];
|
|
91
76
|
|
|
92
77
|
const ComboboxCreateLabelContext =
|
|
93
|
-
React.createContext<(inputValue: string) => React.ReactNode>(
|
|
94
|
-
defaultCreateLabel,
|
|
95
|
-
);
|
|
78
|
+
React.createContext<(inputValue: string) => React.ReactNode>(defaultCreateLabel);
|
|
96
79
|
|
|
97
80
|
const comboboxItemClassName =
|
|
98
81
|
"data-highlighted:bg-accent data-highlighted:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
|
|
@@ -209,10 +192,7 @@ function ComboboxContent({
|
|
|
209
192
|
);
|
|
210
193
|
}
|
|
211
194
|
|
|
212
|
-
function ComboboxCreatableRoot<
|
|
213
|
-
Value,
|
|
214
|
-
Multiple extends boolean | undefined = false,
|
|
215
|
-
>({
|
|
195
|
+
function ComboboxCreatableRoot<Value, Multiple extends boolean | undefined = false>({
|
|
216
196
|
createLabel = defaultCreateLabel,
|
|
217
197
|
defaultValue,
|
|
218
198
|
filter,
|
|
@@ -234,8 +214,7 @@ function ComboboxCreatableRoot<
|
|
|
234
214
|
const [uncontrolledInputValue, setUncontrolledInputValue] = React.useState(
|
|
235
215
|
String(props.defaultInputValue ?? ''),
|
|
236
216
|
);
|
|
237
|
-
const [uncontrolledValue, setUncontrolledValue] =
|
|
238
|
-
React.useState(defaultValue);
|
|
217
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
|
|
239
218
|
const query = String(inputValueProp ?? uncontrolledInputValue).trim();
|
|
240
219
|
const value =
|
|
241
220
|
valueProp !== undefined
|
|
@@ -243,7 +222,9 @@ function ComboboxCreatableRoot<
|
|
|
243
222
|
: (uncontrolledValue ?? (props.multiple ? EMPTY_VALUE : null));
|
|
244
223
|
|
|
245
224
|
const itemsWithCreate = React.useMemo(() => {
|
|
246
|
-
|
|
225
|
+
// shortcut: a createItems() collection is opaque, so it gets no create
|
|
226
|
+
// item; support it if consumers pass one to a creatable Combobox.
|
|
227
|
+
if (!Array.isArray(items) || !query || hasItemLabel(items, query, itemToStringLabel)) {
|
|
247
228
|
return items;
|
|
248
229
|
}
|
|
249
230
|
|
|
@@ -276,10 +257,7 @@ function ComboboxCreatableRoot<
|
|
|
276
257
|
return created === undefined ? [] : [created];
|
|
277
258
|
};
|
|
278
259
|
|
|
279
|
-
const handleValueChange: RootProps['onValueChange'] = (
|
|
280
|
-
nextValue,
|
|
281
|
-
eventDetails,
|
|
282
|
-
) => {
|
|
260
|
+
const handleValueChange: RootProps['onValueChange'] = (nextValue, eventDetails) => {
|
|
283
261
|
let resolvedValue: unknown = nextValue;
|
|
284
262
|
|
|
285
263
|
if (Array.isArray(nextValue)) {
|
|
@@ -294,11 +272,9 @@ function ComboboxCreatableRoot<
|
|
|
294
272
|
resolvedValue = created;
|
|
295
273
|
}
|
|
296
274
|
|
|
297
|
-
const typedValue = resolvedValue as Parameters<
|
|
298
|
-
NonNullable<RootProps['onValueChange']>
|
|
299
|
-
>[0];
|
|
275
|
+
const typedValue = resolvedValue as Parameters<NonNullable<RootProps['onValueChange']>>[0];
|
|
300
276
|
|
|
301
|
-
setUncontrolledValue(typedValue
|
|
277
|
+
setUncontrolledValue(typedValue);
|
|
302
278
|
onValueChange?.(typedValue, eventDetails);
|
|
303
279
|
};
|
|
304
280
|
|
|
@@ -308,8 +284,7 @@ function ComboboxCreatableRoot<
|
|
|
308
284
|
{...props}
|
|
309
285
|
filter={
|
|
310
286
|
filter &&
|
|
311
|
-
((item, filterQuery, toLabel) =>
|
|
312
|
-
isCreateItem(item) || filter(item, filterQuery, toLabel))
|
|
287
|
+
((item, filterQuery, toLabel) => isCreateItem(item) || filter(item, filterQuery, toLabel))
|
|
313
288
|
}
|
|
314
289
|
inputValue={inputValueProp}
|
|
315
290
|
isItemEqualToValue={
|
|
@@ -322,13 +297,11 @@ function ComboboxCreatableRoot<
|
|
|
322
297
|
items={itemsWithCreate}
|
|
323
298
|
itemToStringLabel={
|
|
324
299
|
itemToStringLabel &&
|
|
325
|
-
((item) =>
|
|
326
|
-
isCreateItem(item) ? item.label : itemToStringLabel(item))
|
|
300
|
+
((item) => (isCreateItem(item) ? item.label : itemToStringLabel(item)))
|
|
327
301
|
}
|
|
328
302
|
itemToStringValue={
|
|
329
303
|
itemToStringValue &&
|
|
330
|
-
((item) =>
|
|
331
|
-
isCreateItem(item) ? item.value : itemToStringValue(item))
|
|
304
|
+
((item) => (isCreateItem(item) ? item.value : itemToStringValue(item)))
|
|
332
305
|
}
|
|
333
306
|
onInputValueChange={(nextInputValue, eventDetails) => {
|
|
334
307
|
setUncontrolledInputValue(nextInputValue);
|
|
@@ -411,9 +384,7 @@ function ComboboxInput({
|
|
|
411
384
|
<Input
|
|
412
385
|
className={cn(
|
|
413
386
|
showClear && showTrigger && '*:data-[slot=input]:pe-14',
|
|
414
|
-
hasActions &&
|
|
415
|
-
!(showClear && showTrigger) &&
|
|
416
|
-
'*:data-[slot=input]:pe-8',
|
|
387
|
+
hasActions && !(showClear && showTrigger) && '*:data-[slot=input]:pe-8',
|
|
417
388
|
)}
|
|
418
389
|
nativeInput
|
|
419
390
|
size={size}
|
|
@@ -434,12 +405,7 @@ function ComboboxInput({
|
|
|
434
405
|
);
|
|
435
406
|
}
|
|
436
407
|
|
|
437
|
-
function ComboboxItem({
|
|
438
|
-
children,
|
|
439
|
-
className,
|
|
440
|
-
classNames,
|
|
441
|
-
...props
|
|
442
|
-
}: ComboboxItemProps) {
|
|
408
|
+
function ComboboxItem({ children, className, classNames, ...props }: ComboboxItemProps) {
|
|
443
409
|
return (
|
|
444
410
|
<ComboboxPrimitive.Item
|
|
445
411
|
className={cn(comboboxItemClassName, className)}
|
|
@@ -479,10 +445,7 @@ function ComboboxList({ children, className, ...props }: ComboboxListProps) {
|
|
|
479
445
|
{index > 0 ? <ComboboxSeparator /> : null}
|
|
480
446
|
<ComboboxPrimitive.Collection>
|
|
481
447
|
{(createItem: ComboboxCreateItem) => (
|
|
482
|
-
<ComboboxCreateOption
|
|
483
|
-
item={createItem}
|
|
484
|
-
key={createItem.value}
|
|
485
|
-
/>
|
|
448
|
+
<ComboboxCreateOption item={createItem} key={createItem.value} />
|
|
486
449
|
)}
|
|
487
450
|
</ComboboxPrimitive.Collection>
|
|
488
451
|
</ComboboxPrimitive.Group>
|
|
@@ -505,22 +468,13 @@ function ComboboxRoot<Value, Multiple extends boolean | undefined = false>({
|
|
|
505
468
|
return <ComboboxPrimitive.Root {...props} />;
|
|
506
469
|
}
|
|
507
470
|
|
|
508
|
-
return
|
|
509
|
-
<ComboboxCreatableRoot
|
|
510
|
-
createLabel={createLabel}
|
|
511
|
-
onCreate={onCreate}
|
|
512
|
-
{...props}
|
|
513
|
-
/>
|
|
514
|
-
);
|
|
471
|
+
return <ComboboxCreatableRoot createLabel={createLabel} onCreate={onCreate} {...props} />;
|
|
515
472
|
}
|
|
516
473
|
|
|
517
474
|
function ComboboxSeparator({ className, ...props }: ComboboxSeparatorProps) {
|
|
518
475
|
return (
|
|
519
476
|
<ComboboxPrimitive.Separator
|
|
520
|
-
className={cn(
|
|
521
|
-
'bg-border/50 pointer-events-none -mx-1 my-1 h-px',
|
|
522
|
-
className,
|
|
523
|
-
)}
|
|
477
|
+
className={cn('bg-border/50 pointer-events-none -mx-1 my-1 h-px', className)}
|
|
524
478
|
data-slot="combobox-separator"
|
|
525
479
|
{...props}
|
|
526
480
|
/>
|
|
@@ -530,21 +484,14 @@ function ComboboxSeparator({ className, ...props }: ComboboxSeparatorProps) {
|
|
|
530
484
|
function ComboboxStatus({ className, ...props }: ComboboxStatusProps) {
|
|
531
485
|
return (
|
|
532
486
|
<ComboboxPrimitive.Status
|
|
533
|
-
className={cn(
|
|
534
|
-
'text-muted-foreground px-3 py-2 text-sm empty:hidden',
|
|
535
|
-
className,
|
|
536
|
-
)}
|
|
487
|
+
className={cn('text-muted-foreground px-3 py-2 text-sm empty:hidden', className)}
|
|
537
488
|
data-slot="combobox-status"
|
|
538
489
|
{...props}
|
|
539
490
|
/>
|
|
540
491
|
);
|
|
541
492
|
}
|
|
542
493
|
|
|
543
|
-
function ComboboxTrigger({
|
|
544
|
-
children,
|
|
545
|
-
className,
|
|
546
|
-
...props
|
|
547
|
-
}: ComboboxTriggerProps) {
|
|
494
|
+
function ComboboxTrigger({ children, className, ...props }: ComboboxTriggerProps) {
|
|
548
495
|
return (
|
|
549
496
|
<ComboboxPrimitive.Trigger
|
|
550
497
|
aria-label="Open popup"
|
|
@@ -567,16 +514,14 @@ function defaultCreateLabel(inputValue: string) {
|
|
|
567
514
|
|
|
568
515
|
// Mirrors Base UI's label resolution so the create option only appears when
|
|
569
516
|
// the typed text matches no existing item.
|
|
570
|
-
function getItemLabel(
|
|
571
|
-
item: unknown,
|
|
572
|
-
itemToStringLabel?: (item: never) => string,
|
|
573
|
-
): string {
|
|
517
|
+
function getItemLabel(item: unknown, itemToStringLabel?: (item: never) => string): string {
|
|
574
518
|
if (itemToStringLabel && item != null) {
|
|
575
519
|
return itemToStringLabel(item as never) ?? '';
|
|
576
520
|
}
|
|
577
521
|
|
|
578
522
|
if (item && typeof item === 'object') {
|
|
579
523
|
if ('label' in item && item.label != null) {
|
|
524
|
+
// eslint-disable-next-line typescript/no-base-to-string -- an item's label is a string or a number
|
|
580
525
|
return String(item.label);
|
|
581
526
|
}
|
|
582
527
|
|
|
@@ -585,6 +530,7 @@ function getItemLabel(
|
|
|
585
530
|
}
|
|
586
531
|
}
|
|
587
532
|
|
|
533
|
+
// eslint-disable-next-line typescript/no-base-to-string -- a primitive item, or an object without label or value
|
|
588
534
|
return item == null ? '' : String(item);
|
|
589
535
|
}
|
|
590
536
|
|
|
@@ -594,14 +540,10 @@ function hasItemLabel(
|
|
|
594
540
|
itemToStringLabel?: (item: never) => string,
|
|
595
541
|
) {
|
|
596
542
|
const normalizedQuery = query.toLocaleLowerCase();
|
|
597
|
-
const flatItems = isGroupedItems(items)
|
|
598
|
-
? items.flatMap((group) => group.items)
|
|
599
|
-
: items;
|
|
543
|
+
const flatItems = isGroupedItems(items) ? items.flatMap((group) => group.items) : items;
|
|
600
544
|
|
|
601
545
|
return flatItems.some(
|
|
602
|
-
(item) =>
|
|
603
|
-
getItemLabel(item, itemToStringLabel).trim().toLocaleLowerCase() ===
|
|
604
|
-
normalizedQuery,
|
|
546
|
+
(item) => getItemLabel(item, itemToStringLabel).trim().toLocaleLowerCase() === normalizedQuery,
|
|
605
547
|
);
|
|
606
548
|
}
|
|
607
549
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useFormContext,
|
|
4
|
-
type UseFormReturn,
|
|
5
|
-
useFormState,
|
|
6
|
-
} from 'react-hook-form';
|
|
2
|
+
import { useFormContext, type UseFormReturn, useFormState } from 'react-hook-form';
|
|
7
3
|
|
|
8
4
|
type FormControlProps = {
|
|
9
5
|
id?: string;
|
|
@@ -19,9 +15,7 @@ type WithoutAriaInvalid<Props> = Omit<Props, 'aria-invalid'> & {
|
|
|
19
15
|
'aria-invalid'?: never;
|
|
20
16
|
};
|
|
21
17
|
|
|
22
|
-
const FormFieldContext = React.createContext<FormFieldContextValue | null>(
|
|
23
|
-
null,
|
|
24
|
-
);
|
|
18
|
+
const FormFieldContext = React.createContext<FormFieldContextValue | null>(null);
|
|
25
19
|
const FormInputGroupContext = React.createContext(false);
|
|
26
20
|
|
|
27
21
|
function getErrorMessage(error: unknown): React.ReactNode {
|
|
@@ -31,11 +25,7 @@ function getErrorMessage(error: unknown): React.ReactNode {
|
|
|
31
25
|
|
|
32
26
|
const message = (error as { message?: unknown }).message;
|
|
33
27
|
|
|
34
|
-
if (
|
|
35
|
-
React.isValidElement(message) ||
|
|
36
|
-
typeof message === 'string' ||
|
|
37
|
-
typeof message === 'number'
|
|
38
|
-
) {
|
|
28
|
+
if (React.isValidElement(message) || typeof message === 'string' || typeof message === 'number') {
|
|
39
29
|
return message;
|
|
40
30
|
}
|
|
41
31
|
|
|
@@ -76,9 +66,7 @@ function useFormMethods() {
|
|
|
76
66
|
const methods = useFormContext() as null | UseFormReturn;
|
|
77
67
|
|
|
78
68
|
if (!methods) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
'Form components must be rendered inside <Form form={form}>.',
|
|
81
|
-
);
|
|
69
|
+
throw new Error('Form components must be rendered inside <Form form={form}>.');
|
|
82
70
|
}
|
|
83
71
|
|
|
84
72
|
return methods;
|
|
@@ -88,9 +76,7 @@ function useRequiredFieldName(name: string | undefined, componentName: string) {
|
|
|
88
76
|
const fieldName = useFieldName(name);
|
|
89
77
|
|
|
90
78
|
if (!fieldName) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`${componentName} requires a name prop or a parent <Form.Field name="...">.`,
|
|
93
|
-
);
|
|
79
|
+
throw new Error(`${componentName} requires a name prop or a parent <Form.Field name="...">.`);
|
|
94
80
|
}
|
|
95
81
|
|
|
96
82
|
return fieldName;
|
|
@@ -97,26 +97,14 @@ function SignUpForm() {
|
|
|
97
97
|
<Form.Input autoComplete="username" />
|
|
98
98
|
</Form.Field>
|
|
99
99
|
|
|
100
|
-
<Form.Field
|
|
101
|
-
description="At least 8 characters."
|
|
102
|
-
label="Password"
|
|
103
|
-
name="password"
|
|
104
|
-
>
|
|
100
|
+
<Form.Field description="At least 8 characters." label="Password" name="password">
|
|
105
101
|
<Form.Input autoComplete="new-password" type="password" />
|
|
106
102
|
</Form.Field>
|
|
107
103
|
|
|
108
104
|
<Form.Field controlId="full-name" label="Full name">
|
|
109
105
|
<Form.InputGroup>
|
|
110
|
-
<Form.Input
|
|
111
|
-
|
|
112
|
-
name="firstName"
|
|
113
|
-
placeholder="First"
|
|
114
|
-
/>
|
|
115
|
-
<Form.Input
|
|
116
|
-
aria-label="Last name"
|
|
117
|
-
name="lastName"
|
|
118
|
-
placeholder="Last"
|
|
119
|
-
/>
|
|
106
|
+
<Form.Input aria-label="First name" name="firstName" placeholder="First" />
|
|
107
|
+
<Form.Input aria-label="Last name" name="lastName" placeholder="Last" />
|
|
120
108
|
</Form.InputGroup>
|
|
121
109
|
</Form.Field>
|
|
122
110
|
|
|
@@ -155,9 +143,7 @@ function SignUpForm() {
|
|
|
155
143
|
{(value: Interest[]) => (
|
|
156
144
|
<>
|
|
157
145
|
{value.map((interest) => (
|
|
158
|
-
<Form.Combobox.Chip key={interest.value}>
|
|
159
|
-
{interest.label}
|
|
160
|
-
</Form.Combobox.Chip>
|
|
146
|
+
<Form.Combobox.Chip key={interest.value}>{interest.label}</Form.Combobox.Chip>
|
|
161
147
|
))}
|
|
162
148
|
<Form.Combobox.ChipsInput
|
|
163
149
|
placeholder={value.length > 0 ? '' : 'Add interests…'}
|
|
@@ -178,11 +164,7 @@ function SignUpForm() {
|
|
|
178
164
|
</Form.Combobox>
|
|
179
165
|
</Form.Field>
|
|
180
166
|
|
|
181
|
-
<Form.Field
|
|
182
|
-
description="A sentence or two for your public profile."
|
|
183
|
-
label="Bio"
|
|
184
|
-
name="bio"
|
|
185
|
-
>
|
|
167
|
+
<Form.Field description="A sentence or two for your public profile." label="Bio" name="bio">
|
|
186
168
|
<Form.Textarea placeholder="Tell us about yourself" />
|
|
187
169
|
</Form.Field>
|
|
188
170
|
|
|
@@ -233,11 +215,7 @@ function GroupFieldForm() {
|
|
|
233
215
|
|
|
234
216
|
return (
|
|
235
217
|
<Form form={form} onSubmit={() => {}}>
|
|
236
|
-
<Form.GroupField
|
|
237
|
-
description="Each row keeps its own label."
|
|
238
|
-
label="Grocery list"
|
|
239
|
-
name="list"
|
|
240
|
-
>
|
|
218
|
+
<Form.GroupField description="Each row keeps its own label." label="Grocery list" name="list">
|
|
241
219
|
{groceries.map((name) => (
|
|
242
220
|
<Form.GroupField.Item key={name}>
|
|
243
221
|
<Checkbox label={name} />
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fireEvent,
|
|
3
|
-
render,
|
|
4
|
-
screen,
|
|
5
|
-
waitFor,
|
|
6
|
-
within,
|
|
7
|
-
} from '@testing-library/react';
|
|
1
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
8
2
|
import * as React from 'react';
|
|
9
3
|
import { useForm } from 'react-hook-form';
|
|
10
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
@@ -137,13 +131,8 @@ describe('Form', () => {
|
|
|
137
131
|
it('displays field errors from React Hook Form state', async () => {
|
|
138
132
|
render(<TestForm onSubmit={vi.fn()} withEmailError />);
|
|
139
133
|
|
|
140
|
-
expect(
|
|
141
|
-
|
|
142
|
-
).toBeInTheDocument();
|
|
143
|
-
expect(screen.getByRole('textbox', { name: 'Email' })).toHaveAttribute(
|
|
144
|
-
'aria-invalid',
|
|
145
|
-
'true',
|
|
146
|
-
);
|
|
134
|
+
expect(await screen.findByText('Enter a valid email address.')).toBeInTheDocument();
|
|
135
|
+
expect(screen.getByRole('textbox', { name: 'Email' })).toHaveAttribute('aria-invalid', 'true');
|
|
147
136
|
});
|
|
148
137
|
|
|
149
138
|
it('marks controlled boolean fields invalid from React Hook Form state', async () => {
|
|
@@ -157,15 +146,15 @@ describe('Form', () => {
|
|
|
157
146
|
/>,
|
|
158
147
|
);
|
|
159
148
|
|
|
160
|
-
expect(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
149
|
+
expect(await screen.findByText('Choose a product update preference.')).toBeInTheDocument();
|
|
150
|
+
expect(screen.getByRole('switch', { name: 'Product updates' })).toHaveAttribute(
|
|
151
|
+
'aria-invalid',
|
|
152
|
+
'true',
|
|
153
|
+
);
|
|
154
|
+
expect(screen.getByRole('checkbox', { name: 'Accept terms' })).toHaveAttribute(
|
|
155
|
+
'aria-invalid',
|
|
156
|
+
'true',
|
|
157
|
+
);
|
|
169
158
|
});
|
|
170
159
|
|
|
171
160
|
describe('group fields', () => {
|
|
@@ -240,9 +229,7 @@ describe('Form', () => {
|
|
|
240
229
|
const group = screen.getByRole('group', { name: 'Choices' });
|
|
241
230
|
|
|
242
231
|
for (const name of ['Butter or margarine', 'Milk or cream']) {
|
|
243
|
-
expect(
|
|
244
|
-
within(group).getByRole('radiogroup', { name }),
|
|
245
|
-
).toBeInTheDocument();
|
|
232
|
+
expect(within(group).getByRole('radiogroup', { name })).toBeInTheDocument();
|
|
246
233
|
}
|
|
247
234
|
});
|
|
248
235
|
|
|
@@ -250,12 +237,12 @@ describe('Form', () => {
|
|
|
250
237
|
render(<ListForm withErrors />);
|
|
251
238
|
|
|
252
239
|
expect(await screen.findByText('Pick one.')).toBeInTheDocument();
|
|
253
|
-
expect(
|
|
254
|
-
|
|
255
|
-
)
|
|
256
|
-
expect(
|
|
257
|
-
|
|
258
|
-
)
|
|
240
|
+
expect(screen.getByRole('checkbox', { name: 'Flour' })).toHaveAccessibleDescription(
|
|
241
|
+
'Pick one.',
|
|
242
|
+
);
|
|
243
|
+
expect(screen.getByRole('radiogroup', { name: 'Milk or cream' })).toHaveAccessibleDescription(
|
|
244
|
+
'Choose.',
|
|
245
|
+
);
|
|
259
246
|
});
|
|
260
247
|
});
|
|
261
248
|
|
|
@@ -319,9 +306,7 @@ describe('Form', () => {
|
|
|
319
306
|
{(value: Fruit[]) => (
|
|
320
307
|
<>
|
|
321
308
|
{value.map((tag) => (
|
|
322
|
-
<Form.Combobox.Chip key={tag.value}>
|
|
323
|
-
{tag.label}
|
|
324
|
-
</Form.Combobox.Chip>
|
|
309
|
+
<Form.Combobox.Chip key={tag.value}>{tag.label}</Form.Combobox.Chip>
|
|
325
310
|
))}
|
|
326
311
|
<Form.Combobox.ChipsInput />
|
|
327
312
|
</>
|
|
@@ -362,9 +347,7 @@ describe('Form', () => {
|
|
|
362
347
|
fireEvent.click(await screen.findByRole('option', { name: 'Banana' }));
|
|
363
348
|
|
|
364
349
|
type('Tags', 'Kiwi');
|
|
365
|
-
fireEvent.click(
|
|
366
|
-
await screen.findByRole('option', { name: 'Create "Kiwi"' }),
|
|
367
|
-
);
|
|
350
|
+
fireEvent.click(await screen.findByRole('option', { name: 'Create "Kiwi"' }));
|
|
368
351
|
|
|
369
352
|
fireEvent.click(screen.getByRole('button', { name: 'Submit' }));
|
|
370
353
|
|
|
@@ -12,11 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
type FormCheckboxProps = WithoutAriaInvalid<CheckboxProps>;
|
|
14
14
|
|
|
15
|
-
function FormCheckboxRoot({
|
|
16
|
-
id: idProp,
|
|
17
|
-
name: nameProp,
|
|
18
|
-
...props
|
|
19
|
-
}: FormCheckboxProps) {
|
|
15
|
+
function FormCheckboxRoot({ id: idProp, name: nameProp, ...props }: FormCheckboxProps) {
|
|
20
16
|
const { control } = useFormMethods();
|
|
21
17
|
const name = useRequiredFieldName(nameProp, 'Form.Checkbox');
|
|
22
18
|
const { field } = useController({
|
|
@@ -14,10 +14,9 @@ import {
|
|
|
14
14
|
// Stable fallback so an unset multiple value keeps the same identity.
|
|
15
15
|
const EMPTY_VALUE: never[] = [];
|
|
16
16
|
|
|
17
|
-
type FormComboboxProps<
|
|
18
|
-
Value,
|
|
19
|
-
|
|
20
|
-
> = WithoutAriaInvalid<ComboboxProps<Value, Multiple>>;
|
|
17
|
+
type FormComboboxProps<Value, Multiple extends boolean | undefined = false> = WithoutAriaInvalid<
|
|
18
|
+
ComboboxProps<Value, Multiple>
|
|
19
|
+
>;
|
|
21
20
|
|
|
22
21
|
function FormComboboxChipsInput({
|
|
23
22
|
id: idProp,
|
|
@@ -83,10 +82,5 @@ const FormCombobox = Object.assign(FormComboboxRoot, {
|
|
|
83
82
|
Value: Combobox.Value,
|
|
84
83
|
});
|
|
85
84
|
|
|
86
|
-
export {
|
|
87
|
-
FormCombobox,
|
|
88
|
-
FormComboboxChipsInput,
|
|
89
|
-
FormComboboxInput,
|
|
90
|
-
FormComboboxRoot,
|
|
91
|
-
};
|
|
85
|
+
export { FormCombobox, FormComboboxChipsInput, FormComboboxInput, FormComboboxRoot };
|
|
92
86
|
export type { FormComboboxProps };
|
|
@@ -5,21 +5,14 @@ import * as React from 'react';
|
|
|
5
5
|
import { useFormState } from 'react-hook-form';
|
|
6
6
|
|
|
7
7
|
import { cn } from '../../lib/utils';
|
|
8
|
-
import {
|
|
9
|
-
FormFieldContext,
|
|
10
|
-
getErrorMessage,
|
|
11
|
-
useFormMethods,
|
|
12
|
-
} from './Form.context';
|
|
8
|
+
import { FormFieldContext, getErrorMessage, useFormMethods } from './Form.context';
|
|
13
9
|
import { FormDescription } from './FormDescription';
|
|
14
10
|
import { FormError } from './FormError';
|
|
15
11
|
import { FormLabel } from './FormLabel';
|
|
16
12
|
import { type FormRadioGroupProps, FormRadioGroupRoot } from './FormRadioGroup';
|
|
17
13
|
import { type FormSelectProps, FormSelectRoot } from './FormSelect';
|
|
18
14
|
|
|
19
|
-
type FormFieldProps = Omit<
|
|
20
|
-
React.ComponentProps<typeof Field.Root>,
|
|
21
|
-
'children'
|
|
22
|
-
> & {
|
|
15
|
+
type FormFieldProps = Omit<React.ComponentProps<typeof Field.Root>, 'children'> & {
|
|
23
16
|
children: React.ReactNode;
|
|
24
17
|
controlId?: string;
|
|
25
18
|
description?: React.ReactNode;
|
|
@@ -104,9 +97,7 @@ function FormFieldRoot({
|
|
|
104
97
|
{label}
|
|
105
98
|
</FormFieldLabel>
|
|
106
99
|
) : null}
|
|
107
|
-
<FormFieldContext.Provider value={contextValue}>
|
|
108
|
-
{children}
|
|
109
|
-
</FormFieldContext.Provider>
|
|
100
|
+
<FormFieldContext.Provider value={contextValue}>{children}</FormFieldContext.Provider>
|
|
110
101
|
{errorMessage ? (
|
|
111
102
|
<FormError match>{errorMessage}</FormError>
|
|
112
103
|
) : description ? (
|
|
@@ -122,9 +113,7 @@ function isFormRadioGroupElement(
|
|
|
122
113
|
return React.isValidElement(child) && child.type === FormRadioGroupRoot;
|
|
123
114
|
}
|
|
124
115
|
|
|
125
|
-
function isFormSelectElement(
|
|
126
|
-
child: React.ReactNode,
|
|
127
|
-
): child is React.ReactElement<FormSelectProps> {
|
|
116
|
+
function isFormSelectElement(child: React.ReactNode): child is React.ReactElement<FormSelectProps> {
|
|
128
117
|
return React.isValidElement(child) && child.type === FormSelectRoot;
|
|
129
118
|
}
|
|
130
119
|
|
|
@@ -19,21 +19,11 @@ function FormInput({ id: idProp, name: nameProp, ...props }: FormInputProps) {
|
|
|
19
19
|
const name = useRequiredFieldName(nameProp, 'Form.Input');
|
|
20
20
|
const methods = useFormMethods();
|
|
21
21
|
const registeredProps = methods.register(name);
|
|
22
|
-
const controlProps = useFormControlProps(
|
|
23
|
-
{ id: idProp },
|
|
24
|
-
{ enabled: !isInsideInputGroup },
|
|
25
|
-
);
|
|
22
|
+
const controlProps = useFormControlProps({ id: idProp }, { enabled: !isInsideInputGroup });
|
|
26
23
|
|
|
27
24
|
const InputComponent = isInsideInputGroup ? InputGroupInput : Input;
|
|
28
25
|
|
|
29
|
-
return
|
|
30
|
-
<InputComponent
|
|
31
|
-
{...props}
|
|
32
|
-
{...registeredProps}
|
|
33
|
-
{...controlProps}
|
|
34
|
-
name={name}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
26
|
+
return <InputComponent {...props} {...registeredProps} {...controlProps} name={name} />;
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
export { FormInput };
|
|
@@ -11,15 +11,9 @@ type FormInputGroupProps = React.ComponentProps<typeof InputGroup>;
|
|
|
11
11
|
function FormInputGroup({ children, ...props }: FormInputGroupProps) {
|
|
12
12
|
const field = React.useContext(FormFieldContext);
|
|
13
13
|
const childArray = React.Children.toArray(children);
|
|
14
|
-
const controlIndex = field?.controlId
|
|
15
|
-
? childArray.findIndex(isFormInputElement)
|
|
16
|
-
: -1;
|
|
14
|
+
const controlIndex = field?.controlId ? childArray.findIndex(isFormInputElement) : -1;
|
|
17
15
|
const controlChildren = childArray.map((child, index) => {
|
|
18
|
-
if (
|
|
19
|
-
index === controlIndex &&
|
|
20
|
-
field?.controlId &&
|
|
21
|
-
isFormInputElement(child)
|
|
22
|
-
) {
|
|
16
|
+
if (index === controlIndex && field?.controlId && isFormInputElement(child)) {
|
|
23
17
|
// A group-level label should focus the first input in the group.
|
|
24
18
|
return React.cloneElement(child, {
|
|
25
19
|
id: field.controlId,
|
|
@@ -36,9 +30,7 @@ function FormInputGroup({ children, ...props }: FormInputGroupProps) {
|
|
|
36
30
|
);
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
function isFormInputElement(
|
|
40
|
-
child: React.ReactNode,
|
|
41
|
-
): child is React.ReactElement<FormInputProps> {
|
|
33
|
+
function isFormInputElement(child: React.ReactNode): child is React.ReactElement<FormInputProps> {
|
|
42
34
|
return React.isValidElement(child) && child.type === FormInput;
|
|
43
35
|
}
|
|
44
36
|
|
|
@@ -12,11 +12,7 @@ import { Switch, type SwitchProps } from './Switch';
|
|
|
12
12
|
|
|
13
13
|
type FormSwitchProps = WithoutAriaInvalid<SwitchProps>;
|
|
14
14
|
|
|
15
|
-
function FormSwitchRoot({
|
|
16
|
-
id: idProp,
|
|
17
|
-
name: nameProp,
|
|
18
|
-
...props
|
|
19
|
-
}: FormSwitchProps) {
|
|
15
|
+
function FormSwitchRoot({ id: idProp, name: nameProp, ...props }: FormSwitchProps) {
|
|
20
16
|
const { control } = useFormMethods();
|
|
21
17
|
const name = useRequiredFieldName(nameProp, 'Form.Switch');
|
|
22
18
|
const { field } = useController({
|