File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
routes/docs/components/TextField Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 6161 ? (node ) => [autoFocus (node , typeof autofocus === ' object' ? autofocus : undefined )]
6262 : undefined ;
6363 export let operators: { label: string ; value: string }[] | undefined = undefined ;
64- export let inputEl: HTMLInputElement | null = null ;
64+ export let inputEl: HTMLInputElement | HTMLTextAreaElement | null = null ;
65+ // this is a workaround because Input only accepts an HTMLInputElement, not a TextAreaElement
66+ const inputHolder = {
67+ set input(value : HTMLInputElement | null ) {
68+ inputEl = value ;
69+ },
70+ };
6571 export let debounceChange: boolean | number = false ;
6672 export let classes: {
6773 root? : string ;
327333 {disabled }
328334 value ={inputValue }
329335 {autocapitalize }
336+ bind:this ={inputEl }
330337 on:input ={handleInput }
331338 on:focus
332339 on:blur
366373 {max }
367374 {step }
368375 {actions }
369- bind:inputEl
376+ bind:inputEl ={ inputHolder . input }
370377 on:input ={handleInput }
371378 on:focus
372379 on:blur
Original file line number Diff line number Diff line change 2020
2121 import Preview from ' $lib/components/Preview.svelte' ;
2222 import Blockquote from ' $docs/Blockquote.svelte' ;
23+ import Toggle from ' $lib/components/Toggle.svelte' ;
2324
2425 const numberOperators = [
2526 { label: ' =' , value: ' equal' },
4041 let value = ' ' ;
4142 let numberValue = 1 ;
4243 let multilineValue = ' one\n two\n three' ;
44+
45+ let inputEl: HTMLInputElement | HTMLTextAreaElement | null = null ;
4346 </script >
4447
4548<h1 >Examples</h1 >
225228 />
226229</Preview >
227230
231+ <h2 >bind:inputEl</h2 >
232+
233+ <Preview >
234+ <div class =" grid gap-2 justify-start" >
235+ <Button on:click ={() => inputEl ?.focus ()}>Manually Focus</Button >
236+ <Toggle let:on ={multiline } let:toggle >
237+ <Button on:click ={toggle }>{multiline ? ' To single line' : ' To multiline' }</Button >
238+ <TextField label ="Name" {multiline } bind:inputEl />
239+ </Toggle >
240+ </div >
241+ </Preview >
242+
228243<SectionDivider >Type</SectionDivider >
229244
230245<h2 >Input types</h2 >
You can’t perform that action at this time.
0 commit comments