File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
src/components/fields/ComboBox Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ const TemplateForm: StoryFn<CubeComboBoxProps<any>> = (
4444 < Flow gap = "2x" >
4545 < Form
4646 form = { form }
47- defaultValues = { { combobox : 'red' } }
47+ defaultValues = { { combobox : args . allowsCustomValue ? 'Unknown' : 'red' } }
4848 onSubmit = { ( data ) => console . log ( '! submit' , data ) }
4949 >
5050 < ComboBox name = "combobox" { ...args } >
@@ -137,8 +137,15 @@ WithinForm.play = async ({ canvasElement }) => {
137137 const { getByRole } = within ( canvasElement ) ;
138138
139139 const combobox = getByRole ( 'combobox' ) ;
140- const button = getByRole ( 'button' , { name : 'Focus' } ) ;
140+ // const button = getByRole('button', { name: 'Focus' });
141141
142142 await userEvent . click ( combobox ) ;
143- await userEvent . click ( button ) ;
143+ // await userEvent.click(button);
144+ } ;
145+
146+ export const WithinFormAllosCustomValue = TemplateForm . bind ( { } ) ;
147+ WithinFormAllosCustomValue . play = WithinForm . play ;
148+ WithinFormAllosCustomValue . args = {
149+ ...TemplateForm . args ,
150+ allowsCustomValue : true ,
144151} ;
Original file line number Diff line number Diff line change @@ -150,11 +150,10 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
150150 onSelectionChange ( val : string ) {
151151 if ( val != null ) {
152152 onChange ( val ) ;
153+ } else {
154+ onChange ( inputRef ?. current ?. value ) ;
153155 }
154156 } ,
155- onBlur ( evt ) {
156- evt ?. stopPropagation ( ) ;
157- } ,
158157 } ;
159158 } ,
160159 } ) ;
@@ -335,10 +334,10 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
335334 } ) ;
336335
337336 useEffect ( ( ) => {
338- ref . current ?. addEventListener ( 'keydown' , onKeyPress , true ) ;
337+ inputRef . current ?. addEventListener ( 'keydown' , onKeyPress , true ) ;
339338
340339 return ( ) => {
341- ref . current ?. removeEventListener ( 'keydown' , onKeyPress , true ) ;
340+ inputRef . current ?. removeEventListener ( 'keydown' , onKeyPress , true ) ;
342341 } ;
343342 } , [ ] ) ;
344343
@@ -359,11 +358,12 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
359358 data-size = { size }
360359 >
361360 < InputElement
361+ ref = { inputRef }
362362 qa = "Input"
363363 autoFocus = { autoFocus }
364364 data-autofocus = { autoFocus ? '' : undefined }
365365 { ...allInputProps }
366- ref = { inputRef }
366+ value = { allInputProps . value || props . selectedKey }
367367 autoComplete = { autoComplete }
368368 styles = { inputStyles }
369369 { ...modAttrs ( mods ) }
You can’t perform that action at this time.
0 commit comments