Skip to content

Commit

Permalink
feat: modelValue compatibility for NcActionCheckbox, NcActionRadio, N…
Browse files Browse the repository at this point in the history
…cCheckboxRadioSwitch

Signed-off-by: Grigorii K. Shartsev <[email protected]>
  • Loading branch information
ShGKme committed Oct 30, 2024
1 parent 1333165 commit 98e720c
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 59 deletions.
47 changes: 34 additions & 13 deletions src/components/NcActionCheckbox/NcActionCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This component is made to be used inside of the [NcActions](#NcActions) componen
<template>
<NcActions>
<NcActionCheckbox @change="alert('(un)checked !')">First choice</NcActionCheckbox>
<NcActionCheckbox value="second" v-model="checkboxValue" @change="alert('(un)checked !')">Second choice (v-model)</NcActionCheckbox>
<NcActionCheckbox :checked="true" @change="alert('(un)checked !')">Third choice (checked)</NcActionCheckbox>
<NcActionCheckbox v-model="checkboxValue" value="second" @change="alert('(un)checked !')">Second choice (v-model)</NcActionCheckbox>
<NcActionCheckbox :model-value="checkboxValue" @change="alert('(un)checked !')">Third choice (checked)</NcActionCheckbox>
<NcActionCheckbox :disabled="true" @change="alert('(un)checked !')">Fourth choice (disabled)</NcActionCheckbox>
</NcActions>
</template>
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
<input :id="id"
ref="checkbox"
:disabled="disabled"
:checked="checked"
:checked="model"
:value="value"
:class="{ focusable: isFocusable }"
type="checkbox"
Expand All @@ -56,6 +56,7 @@ export default {
</template>

<script>
import { useModelMigration } from '../../composables/useModelMigration.ts'
import ActionGlobalMixin from '../../mixins/actionGlobal.js'
import GenRandomId from '../../utils/GenRandomId.js'
Expand All @@ -72,8 +73,8 @@ export default {
},
model: {
prop: 'checked',
event: 'update:checked',
prop: 'modelValue',
event: 'update:modelValue',
},
props: {
Expand All @@ -87,9 +88,18 @@ export default {
},
/**
* checked state of the the checkbox element
* Removed in v9 - use `modelValue` (`v-model`) instead
* @deprecated
*/
checked: {
type: Boolean,
default: undefined,
},
/**
* checked state of the the checkbox element
*/
modelValue: {
type: Boolean,
default: false,
},
Expand All @@ -115,9 +125,25 @@ export default {
'change',
'check',
'uncheck',
/**
* Removed in v9 - use `update:modelValue` (`v-model`) instead
* @deprecated
*/
'update:checked',
/**
* Emitted when the checkbox state is changed
* @type {boolean}
*/
'update:modelValue',
],
setup() {
const model = useModelMigration('checked', 'update:checked')
return {
model,
}
},
computed: {
/**
* determines if the action is focusable
Expand All @@ -135,7 +161,7 @@ export default {
*/
ariaChecked() {
if (this.isInSemanticMenu) {
return this.checked ? 'true' : 'false'
return this.model ? 'true' : 'false'
}
return undefined
},
Expand All @@ -147,12 +173,7 @@ export default {
this.$refs.label.click()
},
onChange(event) {
/**
* Emitted when the checkbox state is changed
*
* @type {boolean}
*/
this.$emit('update:checked', this.$refs.checkbox.checked)
this.model = this.$refs.checkbox.checked
/**
* Emitted when the checkbox state is changed
Expand Down
43 changes: 32 additions & 11 deletions src/components/NcActionRadio/NcActionRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ So that only one of each name set can be selected at the same time.
<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 :checked="true" name="uniqueId" @change="alert('(un)checked !')">Third choice (checked)</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>
</template>
Expand Down Expand Up @@ -59,6 +59,7 @@ So that only one of each name set can be selected at the same time.
</template>

<script>
import { useModelMigration } from '../../composables/useModelMigration.ts'
import ActionGlobalMixin from '../../mixins/actionGlobal.js'
import GenRandomId from '../../utils/GenRandomId.js'
Expand All @@ -75,8 +76,8 @@ export default {
},
model: {
prop: 'checked',
event: 'update:checked',
prop: 'modelValue',
event: 'update:modelValue',
},
props: {
Expand All @@ -90,9 +91,18 @@ export default {
},
/**
* checked state of the the radio element
* Removed in v9 - use `modelValue` (`v-model`) instead
* @deprecated
*/
checked: {
type: Boolean,
default: undefined,
},
/**
* checked state of the the radio element
*/
modelValue: {
type: Boolean,
default: false,
},
Expand Down Expand Up @@ -125,10 +135,26 @@ export default {
},
emits: [
/**
* Removed in v9 - use `update:modelValue` (`v-model`) instead
* @deprecated
*/
'update:checked',
/**
* The radio state is changed
* @type {boolean}
*/
'update:modelValue',
'change',
],
setup() {
const model = useModelMigration('checked', 'update:checked')
return {
model,
}
},
computed: {
/**
* determines if the action is focusable
Expand All @@ -146,7 +172,7 @@ export default {
*/
ariaChecked() {
if (this.isInSemanticMenu) {
return this.checked ? 'true' : 'false'
return this.model ? 'true' : 'false'
}
return undefined
},
Expand All @@ -158,12 +184,7 @@ export default {
this.$refs.label.click()
},
onChange(event) {
/**
* Emitted when the radio state is changed
*
* @type {boolean}
*/
this.$emit('update:checked', this.$refs.radio.checked)
this.model = this.$refs.radio.checked
/**
* Emitted when the radio state is changed
Expand Down
Loading

0 comments on commit 98e720c

Please sign in to comment.