50
50
</template >
51
51
52
52
<script lang="ts">
53
- import { defineComponent , PropType , ref , computed , onBeforeUnmount , StyleValue } from ' vue'
53
+ import { defineComponent , PropType , ref , computed , onBeforeUnmount } from ' vue'
54
54
import { fieldType , FieldType } from ' ./SearchInput.types'
55
55
56
+ const filterObject = (obj : { [key : string ]: unknown }, properties : (string | number )[], remove = true ) => {
57
+ const res: { [key : string ]: unknown } = {}
58
+
59
+ Object .keys (obj ).forEach ((objAttr ) => {
60
+ const condition = remove ? properties .indexOf (objAttr ) === - 1 : properties .indexOf (objAttr ) >= 0
61
+ if (condition ) {
62
+ res [objAttr ] = obj [objAttr ]
63
+ }
64
+ })
65
+
66
+ return res
67
+ }
68
+
56
69
export default defineComponent ({
57
70
inheritAttrs: false ,
58
71
props: {
@@ -71,26 +84,9 @@ export default defineComponent({
71
84
const hasFocus = ref (false )
72
85
const inputRef = ref <null | HTMLInputElement >(null )
73
86
74
- const attrsWithoutStyles = computed (() => {
75
- const toOmit = [' class' , ' style' ]
76
- const res = {} as Record <string , unknown >
77
-
78
- Object .keys (attrs ).forEach ((attr ) => {
79
- if (toOmit .indexOf (attr ) === - 1 ) {
80
- res [attr ] = attrs [attr ]
81
- }
82
- })
87
+ const attrsWithoutStyles = computed (() => filterObject (attrs , [' class' , ' style' ]))
83
88
84
- return res
85
- })
86
-
87
- const attrsStyles = computed (() => {
88
- const style = attrs .style as StyleValue | undefined
89
- return {
90
- ... (attrs .class ? { class: attrs .class } : {}),
91
- ... (style ? { style } : {})
92
- }
93
- })
89
+ const attrsStyles = computed (() => filterObject (attrs , [' class' , ' style' ], false ))
94
90
95
91
const clear = () => {
96
92
emit (' update:modelValue' , ' ' )
0 commit comments