Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/docs/src/remix-hook-form/select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,10 @@ const CreatableSelectExample = () => {
<Select
name="region"
label="Custom Region"
description="Creatable option enabled"
description="Creatable option enabled (defaults to trimming the input and using it as label/value)"
options={[...US_STATES.slice(0, 5), ...CANADA_PROVINCES.slice(0, 5)]}
placeholder="Select a custom region"
creatable
onCreateOption={async (input) => ({ label: input, value: input })}
/>
<Button type="submit">Submit</Button>
{fetcher.data?.selectedRegion && (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdacurry/forms",
"version": "0.22.3",
"version": "0.22.4",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 6 additions & 2 deletions packages/components/src/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,12 @@ export function Select<T extends React.Key = string>({
value={q}
role="option"
onSelect={async () => {
if (!onCreateOption) return;
const created = await onCreateOption(q);
const defaultCreate = (input: string): SelectOption<T> => {
const normalized = input.trim();
// Keep value as a string; schema can coerce on submit if needed
return { label: normalized, value: normalized as unknown as T };
};
const created = await Promise.resolve((onCreateOption ?? defaultCreate)(q));
onValueChange?.(created.value);
popoverState.close();
}}
Expand Down