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
61 changes: 61 additions & 0 deletions apps/docs/src/remix-hook-form/select.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { zodResolver } from '@hookform/resolvers/zod';
import * as React from 'react';
import { CanadaProvinceSelect, Select, USStateSelect } from '@lambdacurry/forms/remix-hook-form';
import { Select as UISelect } from '@lambdacurry/forms/ui/select';
import { Button } from '@lambdacurry/forms/ui/button';
import { CANADA_PROVINCES } from '@lambdacurry/forms/ui/data/canada-provinces';
import { US_STATES } from '@lambdacurry/forms/ui/data/us-states';
Expand Down Expand Up @@ -630,3 +632,62 @@ export const CreatableOption: Story = {
});
},
};

// Story to verify custom input type for search input
const NumberSearchTypeExample = () => {
// Use UI Select directly with number-valued options
const numberOptions = [
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 },
{ label: '4', value: 4 },
{ label: '5', value: 5 },
{ label: '6', value: 6 },
{ label: '7', value: 7 },
{ label: '8', value: 8 },
{ label: '9', value: 9 },
{ label: '10', value: 10 },
{ label: '11', value: 11 },
{ label: '12', value: 12 },
{ label: '13', value: 13 },
{ label: '14', value: 14 },
{ label: '15', value: 15 },
{ label: '16', value: 16 },
{ label: '17', value: 17 },
{ label: '18', value: 18 },
{ label: '19', value: 19 },
{ label: '20', value: 20 },
];
const [value, setValue] = React.useState<number | undefined>(10);
return (
<div style={{ width: 320 }}>
<UISelect<number>
options={numberOptions}
placeholder="Pick a number"
searchInputProps={{ type: 'number' }}
value={value}
onValueChange={setValue}
/>
</div>
);
};

export const NumberSearchInputType: Story = {
decorators: [
// No router needed for this simple UI-only story
(StoryFn) => <StoryFn />,
],
render: () => <NumberSearchTypeExample />,
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);
await step('Open select and assert input type is number', async () => {
// Open the UI select
const trigger = await canvas.findByRole('combobox');
await userEvent.click(trigger);

const input = await within(document.body).findByPlaceholderText('Search...');
expect(input).toBeInTheDocument();
expect(input).toHaveAttribute('type', 'number');
});
},
};
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.4",
"version": "0.22.5",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
26 changes: 18 additions & 8 deletions packages/components/src/ui/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
);
};

const CommandInput = ({ className, ...props }: React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>) => (
type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
type?: React.InputHTMLAttributes<HTMLInputElement>['type'];
};
Comment on lines +33 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Export the CommandInputProps type.

The type definition follows the correct naming convention, but it should be exported for external use and better type safety when composing components.

As per coding guidelines: "Always export both the component and its props type"

Apply this diff to export the type:

-type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
+export type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
  type?: React.InputHTMLAttributes<HTMLInputElement>['type'];
};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
type?: React.InputHTMLAttributes<HTMLInputElement>['type'];
};
export type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
type?: React.InputHTMLAttributes<HTMLInputElement>['type'];
};
🤖 Prompt for AI Agents
In packages/components/src/ui/command.tsx around lines 33 to 35, the
CommandInputProps type is currently declared but not exported; update the
declaration to export the type so consumers can import it (e.g., change the
declaration to export type CommandInputProps = ...), and ensure any existing
imports/exports in the file remain consistent with the new exported type.


const CommandInput = ({ className, type = 'text', ...props }: CommandInputProps) => (
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
<CommandPrimitive.Input
className={cn(
'flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50',
className,
)}
{...props}
/>
{/*
To override the type of the input, we couldn't apply the type attribute to the CommandPrimitive.Input component b/c it's hardcoded as 'text' in the cmdk library
Reference: https://github.com/pacocoursey/cmdk/blob/main/cmdk/src/index.tsx#L816
*/}
<CommandPrimitive.Input asChild {...props}>
<input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcmohsen why do we need asChild and input here? Is CommandPrimitive.Input not already an input?

Copy link
Contributor Author

@lcmohsen lcmohsen Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type={type}
className={cn(
'flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50',
className,
)}
/>
</CommandPrimitive.Input>
</div>
);

Expand Down