@@ -349,110 +349,4 @@ export const FormSubmission: Story = {
349349 } ,
350350} ;
351351
352- // Component for testing fixed width
353- const FixedWidthSelectExample = ( ) => {
354- const fetcher = useFetcher < { message : string ; selectedState : string } > ( ) ;
355352
356- const methods = useRemixForm < { state : string } > ( {
357- resolver : zodResolver ( z . object ( { state : z . string ( ) . min ( 1 , 'Please select a state' ) } ) ) ,
358- defaultValues : { state : '' } ,
359- fetcher,
360- submitConfig : { action : '/' , method : 'post' } ,
361- } ) ;
362-
363- return (
364- < RemixFormProvider { ...methods } >
365- < fetcher . Form onSubmit = { methods . handleSubmit } className = "space-y-6" >
366- < div className = "w-[500px]" > { /* Fixed 500px width container */ }
367- < USStateSelect
368- name = "state"
369- label = "US State"
370- description = "Select a US state - container is 500px wide"
371- />
372- </ div >
373-
374- < Button type = "submit" > Submit</ Button >
375-
376- { fetcher . data ?. selectedState && (
377- < div className = "mt-4 p-4 bg-gray-100 rounded-md" >
378- < p className = "text-sm font-medium" > Selected state: { fetcher . data . selectedState } </ p >
379- </ div >
380- ) }
381- </ fetcher . Form >
382- </ RemixFormProvider >
383- ) ;
384- } ;
385-
386- const fixedWidthRouterDecorator = withReactRouterStubDecorator ( {
387- routes : [
388- {
389- path : '/' ,
390- Component : FixedWidthSelectExample ,
391- action : async ( { request } : ActionFunctionArgs ) => {
392- const { data, errors } = await getValidatedFormData < { state : string } > (
393- request ,
394- zodResolver ( z . object ( { state : z . string ( ) . min ( 1 , 'Please select a state' ) } ) )
395- ) ;
396-
397- if ( errors ) return { errors } ;
398- return { message : 'State selected successfully' , selectedState : data . state } ;
399- } ,
400- } ,
401- ] ,
402- } ) ;
403-
404- export const FixedWidth500px : Story = {
405- parameters : {
406- docs : {
407- description : {
408- story : 'Test select dropdown width matching with a fixed 500px container. The dropdown should match the full width of the trigger button.' ,
409- } ,
410- } ,
411- } ,
412- decorators : [ fixedWidthRouterDecorator ] ,
413- play : async ( { canvasElement, step } ) => {
414- const canvas = within ( canvasElement ) ;
415-
416- await step ( 'Verify container and trigger width' , ( ) => {
417- const stateSelect = canvas . getByLabelText ( 'US State' ) ;
418- expect ( stateSelect ) . toBeInTheDocument ( ) ;
419-
420- // The trigger should be 500px wide (minus padding/margins)
421- const triggerElement = stateSelect as HTMLElement ;
422- const computedStyle = window . getComputedStyle ( triggerElement ) ;
423-
424- // Log the actual width for debugging
425- console . log ( 'Trigger width:' , triggerElement . offsetWidth ) ;
426- console . log ( 'Computed width:' , computedStyle . width ) ;
427- } ) ;
428-
429- await step ( 'Open dropdown and verify width matching' , async ( ) => {
430- const stateSelect = canvas . getByLabelText ( 'US State' ) ;
431- await userEvent . click ( stateSelect ) ;
432-
433- // Wait for dropdown to appear
434- const listbox = await canvas . findByRole ( 'listbox' ) ;
435- expect ( listbox ) . toBeInTheDocument ( ) ;
436-
437- // Check if dropdown width matches trigger width
438- const triggerWidth = ( stateSelect as HTMLElement ) . offsetWidth ;
439- const dropdownWidth = ( listbox as HTMLElement ) . offsetWidth ;
440-
441- console . log ( 'Trigger width:' , triggerWidth ) ;
442- console . log ( 'Dropdown width:' , dropdownWidth ) ;
443-
444- // The dropdown should match the trigger width (allowing for small differences due to borders/padding)
445- expect ( Math . abs ( dropdownWidth - triggerWidth ) ) . toBeLessThan ( 5 ) ;
446- } ) ;
447-
448- await step ( 'Select an option and verify functionality' , async ( ) => {
449- const listbox = canvas . getByRole ( 'listbox' ) ;
450- const californiaOption = within ( listbox ) . getByTestId ( 'select-option-california' ) ;
451- await userEvent . click ( californiaOption ) ;
452-
453- // Verify the selection
454- const stateSelect = canvas . getByLabelText ( 'US State' ) ;
455- await expect ( stateSelect ) . toHaveTextContent ( 'California' ) ;
456- } ) ;
457- } ,
458- } ;
0 commit comments