@@ -10,27 +10,34 @@ So that only one of each name set can be selected at the same time.
10
10
11
11
```vue
12
12
<template>
13
- <NcActions>
14
- <NcActionRadio @change="alert('(un)checked !')" name="uniqueId">First choice</NcActionRadio>
15
- <NcActionRadio value="second" v-model="radioValue" name="uniqueId" @change="alert('(un)checked !')">Second choice (v-model)</NcActionRadio>
16
- <NcActionRadio :model-value="true" name="uniqueId" @change="alert('(un)checked !')">Third choice (checked)</NcActionRadio>
17
- <NcActionRadio :disabled="true" name="uniqueId" @change="alert('(un)checked !')">Fourth choice (disabled)</NcActionRadio>
18
- </NcActions>
13
+ <div>
14
+ <NcActions>
15
+ <NcActionRadio v-for="option in radioOptions"
16
+ :key="option.value"
17
+ :value="option.value"
18
+ :disabled="option.disabled"
19
+ name="uniqueId"
20
+ v-model="radioValue">
21
+ {{ option.label }}
22
+ </NcActionRadio>
23
+ </NcActions>
24
+ <span>Selected value: {{ radioValue }}</span>
25
+ </div>
19
26
</template>
20
27
21
28
<script>
22
29
export default {
23
30
data() {
24
31
return {
25
- radioValue: false,
32
+ radioOptions: [
33
+ { value: 'first', label: 'First choise', disabled: false },
34
+ { value: 'second', label: 'Second choise', disabled: false },
35
+ { value: 'third', label: 'Third choise', disabled: false },
36
+ { value: 'fourth', label: 'Fourth choise (disabled)', disabled: true },
37
+ ],
38
+ radioValue: 'first',
26
39
}
27
40
},
28
-
29
- methods: {
30
- alert(message) {
31
- alert(message)
32
- }
33
- }
34
41
}
35
42
</script>
36
43
```
@@ -41,8 +48,8 @@ So that only one of each name set can be selected at the same time.
41
48
<span class="action-radio" role="menuitemradio" :aria-checked="ariaChecked">
42
49
<input :id="id"
43
50
ref="radio"
51
+ v-model="model"
44
52
:disabled="disabled"
45
- :checked="checked"
46
53
:name="name"
47
54
:value="value"
48
55
:class="{ focusable: isFocusable }"
@@ -100,11 +107,11 @@ export default {
100
107
},
101
108
102
109
/**
103
- * checked state of the the radio element
110
+ * checked state of the radio element
104
111
*/
105
112
modelValue: {
106
- type: Boolean ,
107
- default: false ,
113
+ type: [String, Number] ,
114
+ default: '' ,
108
115
},
109
116
110
117
/**
@@ -186,7 +193,11 @@ export default {
186
193
this.$refs.label.click()
187
194
},
188
195
onChange(event) {
189
- this.model = this.$refs.radio.checked
196
+ if (this.checked !== undefined) {
197
+ this.model = this.$refs.radio.checked
198
+ } else {
199
+ this.model = this.value
200
+ }
190
201
191
202
/**
192
203
* Emitted when the radio state is changed
0 commit comments