Skip to content

Commit 3ab0534

Browse files
authored
Merge pull request #138 from lambda-curry/codegen-bot/keyboard-navigation-select-1758083721
2 parents 6962b05 + 97b5f7e commit 3ab0534

File tree

15 files changed

+81
-95
lines changed

15 files changed

+81
-95
lines changed

apps/docs/src/remix-hook-form/phone-input.stories.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ const ControlledPhoneInputExample = () => {
3737
<RemixFormProvider {...methods}>
3838
<fetcher.Form onSubmit={methods.handleSubmit}>
3939
<div className="grid gap-8">
40-
<PhoneInput
41-
name="usaPhone"
42-
label="Phone Number"
43-
description="Enter a US phone number"
44-
/>
40+
<PhoneInput name="usaPhone" label="Phone Number" description="Enter a US phone number" />
4541
<PhoneInput
4642
name="internationalPhone"
4743
label="International Phone Number"
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,79 @@
1+
import type { StoryContext } from '@storybook/react';
12
import { expect } from '@storybook/test';
23
import { userEvent, within } from '@storybook/testing-library';
3-
import { StoryContext } from '@storybook/react';
44

55
// Test selecting a US state
66
export const testUSStateSelection = async ({ canvasElement }: StoryContext) => {
77
const canvas = within(canvasElement);
8-
8+
99
// Find and click the US state dropdown
1010
const stateDropdown = canvas.getByLabelText('US State');
1111
await userEvent.click(stateDropdown);
12-
12+
1313
// Select a state (e.g., California)
1414
const californiaOption = await canvas.findByText('California');
1515
await userEvent.click(californiaOption);
16-
16+
1717
// Verify the selection
1818
expect(stateDropdown).toHaveTextContent('California');
1919
};
2020

2121
// Test selecting a Canadian province
2222
export const testCanadaProvinceSelection = async ({ canvasElement }: StoryContext) => {
2323
const canvas = within(canvasElement);
24-
24+
2525
// Find and click the Canada province dropdown
2626
const provinceDropdown = canvas.getByLabelText('Canadian Province');
2727
await userEvent.click(provinceDropdown);
28-
28+
2929
// Select a province (e.g., Ontario)
3030
const ontarioOption = await canvas.findByText('Ontario');
3131
await userEvent.click(ontarioOption);
32-
32+
3333
// Verify the selection
3434
expect(provinceDropdown).toHaveTextContent('Ontario');
3535
};
3636

3737
// Test form submission
3838
export const testFormSubmission = async ({ canvasElement }: StoryContext) => {
3939
const canvas = within(canvasElement);
40-
40+
4141
// Select a state
4242
const stateDropdown = canvas.getByLabelText('US State');
4343
await userEvent.click(stateDropdown);
4444
const californiaOption = await canvas.findByText('California');
4545
await userEvent.click(californiaOption);
46-
46+
4747
// Select a province
4848
const provinceDropdown = canvas.getByLabelText('Canadian Province');
4949
await userEvent.click(provinceDropdown);
5050
const ontarioOption = await canvas.findByText('Ontario');
5151
await userEvent.click(ontarioOption);
52-
52+
5353
// Select a custom region
5454
const regionDropdown = canvas.getByLabelText('Custom Region');
5555
await userEvent.click(regionDropdown);
5656
const customOption = await canvas.findByText('New York');
5757
await userEvent.click(customOption);
58-
58+
5959
// Submit the form
6060
const submitButton = canvas.getByRole('button', { name: 'Submit' });
6161
await userEvent.click(submitButton);
62-
62+
6363
// Verify the submission (mock response would be shown)
6464
await expect(canvas.findByText('Selected regions:')).resolves.toBeInTheDocument();
6565
};
6666

6767
// Test validation errors
6868
export const testValidationErrors = async ({ canvasElement }: StoryContext) => {
6969
const canvas = within(canvasElement);
70-
70+
7171
// Submit the form without selecting anything
7272
const submitButton = canvas.getByRole('button', { name: 'Submit' });
7373
await userEvent.click(submitButton);
74-
74+
7575
// Verify error messages
7676
await expect(canvas.findByText('Please select a state')).resolves.toBeInTheDocument();
7777
await expect(canvas.findByText('Please select a province')).resolves.toBeInTheDocument();
7878
await expect(canvas.findByText('Please select a region')).resolves.toBeInTheDocument();
7979
};
80-

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.19.6",
3+
"version": "0.19.7",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import * as React from 'react';
2-
import { Select, type SelectProps } from './select';
31
import { CANADA_PROVINCES } from '../ui/data/canada-provinces';
2+
import { Select, type SelectProps } from './select';
43

54
export type CanadaProvinceSelectProps = Omit<SelectProps, 'options'>;
65

76
export function CanadaProvinceSelect(props: CanadaProvinceSelectProps) {
8-
return (
9-
<Select
10-
{...props}
11-
options={CANADA_PROVINCES}
12-
placeholder="Select a province"
13-
/>
14-
);
7+
return <Select {...props} options={CANADA_PROVINCES} placeholder="Select a province" />;
158
}
16-

packages/components/src/remix-hook-form/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ export * from './use-data-table-url-state';
1717
export * from './select';
1818
export * from './us-state-select';
1919
export * from './canada-province-select';
20-

packages/components/src/remix-hook-form/phone-input.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import * as React from 'react';
2-
import { PhoneInputField as BasePhoneInputField, type PhoneInputFieldProps as BasePhoneInputFieldProps } from '../ui/phone-input-field';
1+
import type * as React from 'react';
2+
import {
3+
PhoneInputField as BasePhoneInputField,
4+
type PhoneInputFieldProps as BasePhoneInputFieldProps,
5+
} from '../ui/phone-input-field';
36
import { FormControl, FormDescription, FormLabel, FormMessage } from './form';
47

58
import { useRemixFormContext } from 'remix-hook-form';

packages/components/src/remix-hook-form/select.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as React from 'react';
1+
import type * as React from 'react';
22
import { useRemixFormContext } from 'remix-hook-form';
3-
import { FormControl, FormDescription, FormLabel, FormMessage } from './form';
43
import { FormField, FormItem } from '../ui/form';
5-
import { Select as UISelect, type SelectProps as UISelectProps, type SelectUIComponents } from '../ui/select';
4+
import { type SelectUIComponents, Select as UISelect, type SelectProps as UISelectProps } from '../ui/select';
5+
import { FormControl, FormDescription, FormLabel, FormMessage } from './form';
66

77
export interface SelectProps extends Omit<UISelectProps, 'value' | 'onValueChange'> {
88
name: string;
@@ -19,14 +19,7 @@ export interface SelectProps extends Omit<UISelectProps, 'value' | 'onValueChang
1919
>;
2020
}
2121

22-
export function Select({
23-
name,
24-
label,
25-
description,
26-
className,
27-
components,
28-
...props
29-
}: SelectProps) {
22+
export function Select({ name, label, description, className, components, ...props }: SelectProps) {
3023
const { control } = useRemixFormContext();
3124

3225
return (
@@ -50,9 +43,7 @@ export function Select({
5043
}}
5144
/>
5245
</FormControl>
53-
{description && (
54-
<FormDescription Component={components?.FormDescription}>{description}</FormDescription>
55-
)}
46+
{description && <FormDescription Component={components?.FormDescription}>{description}</FormDescription>}
5647
<FormMessage Component={components?.FormMessage} />
5748
</FormItem>
5849
)}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import * as React from 'react';
2-
import { Select, type SelectProps } from './select';
31
import { US_STATES } from '../ui/data/us-states';
2+
import { Select, type SelectProps } from './select';
43

54
export type USStateSelectProps = Omit<SelectProps, 'options'>;
65

76
export function USStateSelect(props: USStateSelectProps) {
8-
return (
9-
<Select
10-
{...props}
11-
options={US_STATES}
12-
placeholder="Select a state"
13-
/>
14-
);
7+
return <Select {...props} options={US_STATES} placeholder="Select a state" />;
158
}
16-
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import * as React from 'react';
2-
import { Select, type SelectProps } from './select';
31
import { CANADA_PROVINCES } from './data/canada-provinces';
2+
import { Select, type SelectProps } from './select';
43

54
export type CanadaProvinceSelectProps = Omit<SelectProps, 'options'>;
65

76
export function CanadaProvinceSelect(props: CanadaProvinceSelectProps) {
8-
return (
9-
<Select
10-
options={CANADA_PROVINCES}
11-
placeholder="Select a province"
12-
{...props}
13-
/>
14-
);
7+
return <Select options={CANADA_PROVINCES} placeholder="Select a province" {...props} />;
158
}
16-

packages/components/src/ui/data/canada-provinces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SelectOption } from '../select';
1+
import type { SelectOption } from '../select';
22

33
export const CANADA_PROVINCES: SelectOption[] = [
44
{ value: 'AB', label: 'Alberta' },

0 commit comments

Comments
 (0)