Skip to content

Commit 7788aa7

Browse files
authored
Merge pull request #162 from lambda-curry/fix/add-type-prop-to-select
2 parents ad7fa7c + a913877 commit 7788aa7

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

apps/docs/src/remix-hook-form/select.stories.tsx

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { zodResolver } from '@hookform/resolvers/zod';
2+
import * as React from 'react';
23
import { CanadaProvinceSelect, Select, USStateSelect } from '@lambdacurry/forms/remix-hook-form';
4+
import { Select as UISelect } from '@lambdacurry/forms/ui/select';
35
import { Button } from '@lambdacurry/forms/ui/button';
46
import { CANADA_PROVINCES } from '@lambdacurry/forms/ui/data/canada-provinces';
57
import { US_STATES } from '@lambdacurry/forms/ui/data/us-states';
@@ -630,3 +632,62 @@ export const CreatableOption: Story = {
630632
});
631633
},
632634
};
635+
636+
// Story to verify custom input type for search input
637+
const NumberSearchTypeExample = () => {
638+
// Use UI Select directly with number-valued options
639+
const numberOptions = [
640+
{ label: '1', value: 1 },
641+
{ label: '2', value: 2 },
642+
{ label: '3', value: 3 },
643+
{ label: '4', value: 4 },
644+
{ label: '5', value: 5 },
645+
{ label: '6', value: 6 },
646+
{ label: '7', value: 7 },
647+
{ label: '8', value: 8 },
648+
{ label: '9', value: 9 },
649+
{ label: '10', value: 10 },
650+
{ label: '11', value: 11 },
651+
{ label: '12', value: 12 },
652+
{ label: '13', value: 13 },
653+
{ label: '14', value: 14 },
654+
{ label: '15', value: 15 },
655+
{ label: '16', value: 16 },
656+
{ label: '17', value: 17 },
657+
{ label: '18', value: 18 },
658+
{ label: '19', value: 19 },
659+
{ label: '20', value: 20 },
660+
];
661+
const [value, setValue] = React.useState<number | undefined>(10);
662+
return (
663+
<div style={{ width: 320 }}>
664+
<UISelect<number>
665+
options={numberOptions}
666+
placeholder="Pick a number"
667+
searchInputProps={{ type: 'number' }}
668+
value={value}
669+
onValueChange={setValue}
670+
/>
671+
</div>
672+
);
673+
};
674+
675+
export const NumberSearchInputType: Story = {
676+
decorators: [
677+
// No router needed for this simple UI-only story
678+
(StoryFn) => <StoryFn />,
679+
],
680+
render: () => <NumberSearchTypeExample />,
681+
play: async ({ canvasElement, step }) => {
682+
const canvas = within(canvasElement);
683+
await step('Open select and assert input type is number', async () => {
684+
// Open the UI select
685+
const trigger = await canvas.findByRole('combobox');
686+
await userEvent.click(trigger);
687+
688+
const input = await within(document.body).findByPlaceholderText('Search...');
689+
expect(input).toBeInTheDocument();
690+
expect(input).toHaveAttribute('type', 'number');
691+
});
692+
},
693+
};

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdacurry/forms",
3-
"version": "0.22.4",
3+
"version": "0.22.5",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/components/src/ui/command.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,25 @@ const CommandDialog = ({ children, ...props }: CommandDialogProps) => {
3030
);
3131
};
3232

33-
const CommandInput = ({ className, ...props }: React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>) => (
33+
type CommandInputProps = React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input> & {
34+
type?: React.InputHTMLAttributes<HTMLInputElement>['type'];
35+
};
36+
37+
const CommandInput = ({ className, type = 'text', ...props }: CommandInputProps) => (
3438
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
35-
<CommandPrimitive.Input
36-
className={cn(
37-
'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',
38-
className,
39-
)}
40-
{...props}
41-
/>
39+
{/*
40+
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
41+
Reference: https://github.com/pacocoursey/cmdk/blob/main/cmdk/src/index.tsx#L816
42+
*/}
43+
<CommandPrimitive.Input asChild {...props}>
44+
<input
45+
type={type}
46+
className={cn(
47+
'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',
48+
className,
49+
)}
50+
/>
51+
</CommandPrimitive.Input>
4252
</div>
4353
);
4454

0 commit comments

Comments
 (0)