Skip to content

Commit

Permalink
Merge pull request #6470 from nextcloud-libraries/fix/6264/action-rad…
Browse files Browse the repository at this point in the history
…io-vmodel

fix(NcActionRadio): follow-up fixes, promote migration to v-model
  • Loading branch information
Antreesy authored Feb 13, 2025
2 parents 6c15905 + bc9e52b commit 0696745
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
```

The old import paths are still valid, but deprecated and will be removed in version 9.

### 📝 Notes
* `NcActionRadio` is now expecting String|Number in `v-model` directive (to compare with passed `value`) instead of Boolean. Consider it for migration.


Expand Down
29 changes: 14 additions & 15 deletions src/components/NcActionRadio/NcActionRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ So that only one of each name set can be selected at the same time.
data() {
return {
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 },
{ value: 'first', label: 'First choice', disabled: false },
{ value: 'second', label: 'Second choice', disabled: false },
{ value: 'third', label: 'Third choice', disabled: false },
{ value: 'fourth', label: 'Fourth choice (disabled)', disabled: true },
],
radioValue: 'first',
}
Expand All @@ -47,7 +47,6 @@ So that only one of each name set can be selected at the same time.
<li class="action" :class="{ 'action--disabled': disabled }" :role="isInSemanticMenu && 'presentation'">
<span class="action-radio" role="menuitemradio" :aria-checked="ariaChecked">
<input :id="id"
ref="radio"
v-model="model"
:disabled="disabled"
:name="name"
Expand All @@ -66,6 +65,7 @@ So that only one of each name set can be selected at the same time.
</template>

<script>
import Vue from 'vue'
import { useModelMigration } from '../../composables/useModelMigration.ts'
import ActionGlobalMixin from '../../mixins/actionGlobal.js'
import GenRandomId from '../../utils/GenRandomId.js'
Expand Down Expand Up @@ -107,11 +107,12 @@ export default {
},

/**
* checked state of the radio element
* Checked state of the radio element
* Boolean type removed in v9 - use String | Number instead
*/
modelValue: {
type: [String, Number],
default: '',
type: [Boolean, String, Number],
default: false,
},

/**
Expand Down Expand Up @@ -157,7 +158,11 @@ export default {
'change',
],

setup() {
setup(props) {
if (typeof props.modelValue === 'boolean') {
Vue.util.warn('[NcActionRadio] Boolean type of `modelValue` is deprecated and will be removed in next versions')
}

const model = useModelMigration('checked', 'update:checked')
return {
model,
Expand Down Expand Up @@ -193,12 +198,6 @@ export default {
this.$refs.label.click()
},
onChange(event) {
if (this.checked !== undefined) {
this.model = this.$refs.radio.checked
} else {
this.model = this.value
}

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

0 comments on commit 0696745

Please sign in to comment.