14
14
@blur =" hasFocus = false"
15
15
@keydown =" onKeydown"
16
16
/>
17
- <slot v-if =" shortcutIcon && !hasFocus && modelValue.length === 0 " name =" shortcut-icon" >
17
+ <slot v-if =" showShortcutIcon " name =" shortcut-icon" >
18
18
<i class =" search-icon shortcut" title =' Press "/" to search' ></i >
19
19
</slot >
20
- <slot v-if =" clearIcon && modelValue.length > 0 " name =" clear-icon" :clear =" clear" >
20
+ <slot v-if =" showClearIcon " name =" clear-icon" :clear =" clear" >
21
21
<i class =" search-icon clear" @mousedown =" clear" ></i >
22
22
</slot >
23
23
</div >
@@ -61,6 +61,7 @@ export default defineComponent({
61
61
searchIcon: defaultBoolean (),
62
62
shortcutIcon: defaultBoolean (),
63
63
clearIcon: defaultBoolean (),
64
+ hideShortcutIconOnBlur: defaultBoolean (),
64
65
clearOnEsc: defaultBoolean (),
65
66
blurOnEsc: defaultBoolean (),
66
67
selectOnFocus: defaultBoolean (),
@@ -82,6 +83,14 @@ export default defineComponent({
82
83
return res
83
84
})
84
85
86
+ const showClearIcon = computed (() => !! (props .clearIcon && props .modelValue .length > 0 ))
87
+
88
+ const showShortcutIcon = computed (() => {
89
+ if (props .shortcutIcon && ! hasFocus .value && ! props .hideShortcutIconOnBlur ) return true
90
+ if (props .shortcutIcon && ! hasFocus .value && props .modelValue .length === 0 ) return true
91
+ return false
92
+ })
93
+
85
94
const clear = () => {
86
95
emit (' update:modelValue' , ' ' )
87
96
}
@@ -117,7 +126,7 @@ export default defineComponent({
117
126
})
118
127
const elToFocus = allVisibleSearchInputs .length > 1 ? allVisibleSearchInputs [0 ] : inputRef .value
119
128
elToFocus ?.focus ()
120
- elToFocus ?.select ()
129
+ if ( props . selectOnFocus ) elToFocus ?.select ()
121
130
}
122
131
}
123
132
@@ -146,7 +155,9 @@ export default defineComponent({
146
155
onInput ,
147
156
onKeydown ,
148
157
attrsStyles ,
149
- attrsWithoutStyles
158
+ attrsWithoutStyles ,
159
+ showClearIcon ,
160
+ showShortcutIcon
150
161
}
151
162
}
152
163
})
0 commit comments