|
1 | 1 | import { zodResolver } from '@hookform/resolvers/zod'; |
| 2 | +import * as React from 'react'; |
2 | 3 | import { CanadaProvinceSelect, Select, USStateSelect } from '@lambdacurry/forms/remix-hook-form'; |
| 4 | +import { Select as UISelect } from '@lambdacurry/forms/ui/select'; |
3 | 5 | import { Button } from '@lambdacurry/forms/ui/button'; |
4 | 6 | import { CANADA_PROVINCES } from '@lambdacurry/forms/ui/data/canada-provinces'; |
5 | 7 | import { US_STATES } from '@lambdacurry/forms/ui/data/us-states'; |
@@ -630,3 +632,62 @@ export const CreatableOption: Story = { |
630 | 632 | }); |
631 | 633 | }, |
632 | 634 | }; |
| 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 | +}; |
0 commit comments