@@ -2,7 +2,10 @@ import { computed, ref } from 'vue'
2
2
3
3
const formElements = [ 'input' , 'select' , 'textarea' , 'fieldset' , 'datalist' , 'option' , 'optgroup' ]
4
4
5
- const handleMultipleCheckbox = < TModelValue extends Array < any > > ( value : unknown , modelValue : TModelValue ) => {
5
+ function handleMultipleCheckbox < TModelValue extends Array < any > > (
6
+ value : unknown ,
7
+ modelValue : TModelValue ,
8
+ ) {
6
9
const currentModelValue = [ ...modelValue ]
7
10
// If the value is already checked, uncheck it
8
11
// else, add it to the checked array.
@@ -18,9 +21,9 @@ const handleMultipleCheckbox = <TModelValue extends Array<any>>(value: unknown,
18
21
* Function that emits the right events when using v-model.
19
22
*/
20
23
function handleInput <
21
- TEmit extends CallableFunction ,
24
+ TEmit extends CallableFunction ,
22
25
TModelValue extends Array < any > ,
23
- TAttrs extends Record < string , unknown >
26
+ TAttrs extends Record < string , unknown > ,
24
27
> ( e : Event , emit : TEmit , modelValue : TModelValue , attrs : TAttrs ) {
25
28
emit (
26
29
'update:modelValue' ,
@@ -41,22 +44,15 @@ function handleInput<
41
44
}
42
45
43
46
export function getAttributes <
44
- TModelValue extends Array < any > ,
45
- TEmit extends CallableFunction ,
46
- TAttrs extends Record < string , unknown > >
47
- (
48
- elementTag : string ,
49
- modelValue : TModelValue ,
50
- emit : TEmit ,
51
- attrs : TAttrs ,
52
- ) {
53
-
47
+ TModelValue extends Array < any > ,
48
+ TEmit extends CallableFunction ,
49
+ TAttrs extends Record < string , unknown > ,
50
+ > ( elementTag : string , modelValue : TModelValue , emit : TEmit , attrs : TAttrs ) {
54
51
const val = ref < Record < string , unknown > > ( { value : modelValue } )
55
52
const attributes = ref ( { ...attrs } )
56
53
57
54
// Only do this if v-model directive is provided, otherwise return user props
58
55
if ( formElements . includes ( elementTag ) && ( modelValue !== null || modelValue !== undefined ) ) {
59
-
60
56
if ( elementTag === 'input' && ( attrs . type === 'checkbox' || attrs . type === 'radio' ) ) {
61
57
const isChecked = computed ( ( ) =>
62
58
// If it's a boolean, it's probably a single checkbox or a radio button
@@ -72,9 +68,9 @@ export function getAttributes<
72
68
attributes . value = {
73
69
...val . value ,
74
70
onInput : ( e : Event ) => handleInput ( e , emit , modelValue , attrs ) ,
75
- ...attrs
71
+ ...attrs ,
76
72
}
77
73
}
78
-
74
+
79
75
return attributes . value
80
76
}
0 commit comments