Skip to content

fix(NcActionRadio): change modelValue to behave like NcCheckboxRadioSwitch #6264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- to `import NcButton from '@nextcloud/vue/components/NcButton'`

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


## [v8.22.0](https://github.com/nextcloud-libraries/nextcloud-vue/tree/v8.22.0) (2024-12-20)
[Full Changelog](https://github.com/nextcloud-libraries/nextcloud-vue/compare/v8.21.0...v8.22.0)
Expand Down
47 changes: 29 additions & 18 deletions src/components/NcActionRadio/NcActionRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@ So that only one of each name set can be selected at the same time.

```vue
<template>
<NcActions>
<NcActionRadio @change="alert('(un)checked !')" name="uniqueId">First choice</NcActionRadio>
<NcActionRadio value="second" v-model="radioValue" name="uniqueId" @change="alert('(un)checked !')">Second choice (v-model)</NcActionRadio>
<NcActionRadio :model-value="true" name="uniqueId" @change="alert('(un)checked !')">Third choice (checked)</NcActionRadio>
<NcActionRadio :disabled="true" name="uniqueId" @change="alert('(un)checked !')">Fourth choice (disabled)</NcActionRadio>
</NcActions>
<div>
<NcActions>
<NcActionRadio v-for="option in radioOptions"
:key="option.value"
:value="option.value"
:disabled="option.disabled"
name="uniqueId"
v-model="radioValue">
{{ option.label }}
</NcActionRadio>
</NcActions>
<span>Selected value: {{ radioValue }}</span>
</div>
</template>

<script>
export default {
data() {
return {
radioValue: false,
radioOptions: [
{ value: 'first', label: 'First choise', disabled: false },
{ value: 'second', label: 'Second choise', disabled: false },
{ value: 'third', label: 'Third choise', disabled: false },
{ value: 'fourth', label: 'Fourth choise (disabled)', disabled: true },
],
radioValue: 'first',
}
},

methods: {
alert(message) {
alert(message)
}
}
}
</script>
```
Expand All @@ -41,8 +48,8 @@ So that only one of each name set can be selected at the same time.
<span class="action-radio" role="menuitemradio" :aria-checked="ariaChecked">
<input :id="id"
ref="radio"
v-model="model"
:disabled="disabled"
:checked="checked"
:name="name"
:value="value"
:class="{ focusable: isFocusable }"
Expand Down Expand Up @@ -100,11 +107,11 @@ export default {
},

/**
* checked state of the the radio element
* checked state of the radio element
*/
modelValue: {
type: Boolean,
default: false,
type: [String, Number],
default: '',
},

/**
Expand Down Expand Up @@ -186,7 +193,11 @@ export default {
this.$refs.label.click()
},
onChange(event) {
this.model = this.$refs.radio.checked
if (this.checked !== undefined) {
this.model = this.$refs.radio.checked
} else {
this.model = this.value
}

/**
* Emitted when the radio state is changed
Expand Down
Loading