Skip to content

Commit 5488eb4

Browse files
authored
Merge pull request #6264 from nextcloud-libraries/fix/noid/action-radio-vmodel
2 parents 0d9efa6 + 938ef32 commit 5488eb4

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
- to `import NcButton from '@nextcloud/vue/components/NcButton'`
1717

1818
The old import paths are still valid, but deprecated and will be removed in version 9.
19+
* `NcActionRadio` is now expecting String|Number in `v-model` directive (to compare with passed `value`) instead of Boolean. Consider it for migration.
20+
1921

2022
## [v8.22.0](https://github.com/nextcloud-libraries/nextcloud-vue/tree/v8.22.0) (2024-12-20)
2123
[Full Changelog](https://github.com/nextcloud-libraries/nextcloud-vue/compare/v8.21.0...v8.22.0)

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)