Skip to content

Commit 0385abf

Browse files
committed
fix(NcActionRadio): change modelValue to behave like NcCheckboxRadioSwitch
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 3c37a5a commit 0385abf

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/components/NcActionRadio/NcActionRadio.vue

+29-18
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,34 @@ So that only one of each name set can be selected at the same time.
1010

1111
```vue
1212
<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>
1926
</template>
2027

2128
<script>
2229
export default {
2330
data() {
2431
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',
2639
}
2740
},
28-
29-
methods: {
30-
alert(message) {
31-
alert(message)
32-
}
33-
}
3441
}
3542
</script>
3643
```
@@ -41,8 +48,8 @@ So that only one of each name set can be selected at the same time.
4148
<span class="action-radio" role="menuitemradio" :aria-checked="ariaChecked">
4249
<input :id="id"
4350
ref="radio"
51+
v-model="model"
4452
:disabled="disabled"
45-
:checked="checked"
4653
:name="name"
4754
:value="value"
4855
:class="{ focusable: isFocusable }"
@@ -100,11 +107,11 @@ export default {
100107
},
101108

102109
/**
103-
* checked state of the the radio element
110+
* checked state of the radio element
104111
*/
105112
modelValue: {
106-
type: Boolean,
107-
default: false,
113+
type: [String, Number],
114+
default: '',
108115
},
109116

110117
/**
@@ -186,7 +193,11 @@ export default {
186193
this.$refs.label.click()
187194
},
188195
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+
}
190201

191202
/**
192203
* Emitted when the radio state is changed

0 commit comments

Comments
 (0)