File tree Expand file tree Collapse file tree 2 files changed +59
-2
lines changed Expand file tree Collapse file tree 2 files changed +59
-2
lines changed Original file line number Diff line number Diff line change 8181<Base {id } {label } {helper } {state } {required } {leadingIcon }>
8282 <slot name =" info" slot =" info" />
8383 <input
84- type =" hidden"
84+ type =" text"
85+ class =" hidden"
86+ tabindex =" -1"
8587 {...$$restProps }
8688 {disabled }
8789 {readonly }
156158 @use ' ./input' ;
157159 @use ' ../../scss/mixins/transitions' ;
158160
161+ .hidden {
162+ position : absolute ;
163+ width : 1px ;
164+ height : 1px ;
165+ padding : 0 ;
166+ margin : -1px ;
167+ overflow : hidden ;
168+ clip : rect (0 , 0 , 0 , 0 );
169+ white-space : nowrap ;
170+ border : 0 ;
171+ pointer-events : none ;
172+ }
173+
159174 .selected {
160175 display : inline ;
161176 overflow : hidden ;
Original file line number Diff line number Diff line change 172172 } satisfies Meta ;
173173 </script >
174174
175- <script >
175+ <script lang = " ts " >
176176 import { Story , Template } from ' @storybook/addon-svelte-csf' ;
177177 import Select from ' $lib/input/Select.svelte' ;
178178 import { Button } from ' $lib/button/index.js' ;
181181 import Modal from ' $lib/Modal.svelte' ;
182182
183183 let open = false ;
184+
185+ let error: string | null = null ;
186+ let value: string | null = null ;
187+
188+ const handleInvalid = (event : Event ) => {
189+ event .preventDefault ();
190+ const element = event .target as HTMLInputElement ;
191+
192+ if (element .validity .valueMissing ) {
193+ error = ' This field is required' ;
194+ return ;
195+ }
196+
197+ error = element .validationMessage ;
198+ };
184199 </script >
185200
186201<Template let:args >
246261 </Modal >
247262 <Button on:click ={() => (open = ! open )}>Open Modal</Button >
248263</Story >
264+
265+ <Story name =" Form" >
266+ <form
267+ on:submit ={(e ) => {
268+ e .preventDefault ();
269+ console .log (' Form submitted successfully!' );
270+ }}
271+ >
272+ <Stack gap =" m" >
273+ <Select
274+ {value }
275+ required
276+ label =" Country"
277+ placeholder =" Select a country"
278+ state ={error ? ' error' : ' default' }
279+ helper ={error ?? ' Please select your country' }
280+ options ={[
281+ { label: ' Germany' , value: ' de' },
282+ { label: ' India' , value: ' in' },
283+ { label: ' United States' , value: ' us' }
284+ ]}
285+ on:invalid ={handleInvalid }
286+ />
287+ <Button type =" submit" >Submit</Button >
288+ </Stack >
289+ </form >
290+ </Story >
You can’t perform that action at this time.
0 commit comments