Skip to content
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

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

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 },
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
],
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: '',
Comment on lines +113 to +114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 This is a breaking change

Suggested change
type: [String, Number],
default: '',
type: [Boolean, String, Number],
default: false,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can emphasise more on it in the Changelog, but I'd address this as bug:

According to docs, type checkbox can have Boolean or String[], but type radio does not support it, and it should be String:
https://vuejs.org/guide/essentials/forms#radio
https://vuejs.org/guide/essentials/forms#value-bindings

I also tried to revert changes and experiment, boolean v-model does not change its value in that case:
image

},

/**
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
Antreesy marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.model = this.value
}
Comment on lines +196 to +200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v-model="model" already handles change event and sets new this.model value which results in emitting the value.

It's handled twice now. Please, make sure it's correct, and no extra event is emitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Difference with old implementation (adding that to the bug description):

Event Before After
@update:* true prop value
@change Event Event


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