File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
packages/radix-vue/src/Combobox Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,21 @@ describe('given default Combobox', () => {
5656 expect ( wrapper . html ( ) ) . toContain ( 'Apple' )
5757 } )
5858
59+ it ( 'should reset searchTerm when close' , async ( ) => {
60+ const input = wrapper . find ( 'input' )
61+ input . element . value = 'Testing'
62+ await input . trigger ( 'keydown' , { key : 'Escape' } )
63+ expect ( input . element . value ) . toBe ( '' )
64+ } )
65+
66+ it ( 'should not reset searchTerm when close' , async ( ) => {
67+ await wrapper . setProps ( { resetSearchTermOnBlur : false , key : 'key' } )
68+ const input = wrapper . find ( 'input' )
69+ input . element . value = 'Testing'
70+ await input . trigger ( 'keydown' , { key : 'Escape' } )
71+ expect ( input . element . value ) . toBe ( 'Testing' )
72+ } )
73+
5974 describe ( 'after selecting a value' , ( ) => {
6075 beforeEach ( async ( ) => {
6176 const selection = wrapper . findAll ( '[role=option]' ) [ 1 ]
Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ export interface ComboboxRootProps<T = AcceptableValue> extends PrimitiveProps {
6565 filterFunction? : (val : ArrayOrWrapped <T >, term : string ) => ArrayOrWrapped <T >
6666 /** The display value of input for selected item. Does not work with `multiple`. */
6767 displayValue? : (val : T ) => string
68+ /** Whether to reset the searchTerm when the Combobox input blurred
69+ * @defaultValue `true`
70+ */
71+ resetSearchTermOnBlur? : boolean
6872}
6973 </script >
7074
@@ -78,6 +82,7 @@ import isEqual from 'fast-deep-equal'
7882
7983const props = withDefaults (defineProps <ComboboxRootProps <T >>(), {
8084 open: undefined ,
85+ resetSearchTermOnBlur: true ,
8186})
8287const emit = defineEmits <ComboboxRootEmits <T >>()
8388
@@ -128,7 +133,8 @@ async function onOpenChange(val: boolean) {
128133 }
129134 else {
130135 isUserInputted .value = false
131- resetSearchTerm ()
136+ if (props .resetSearchTermOnBlur )
137+ resetSearchTerm ()
132138 }
133139}
134140
You can’t perform that action at this time.
0 commit comments