Skip to content

Commit

Permalink
chore(lib): update Checkbox
Browse files Browse the repository at this point in the history
- In `src/components/checkbox/Checkbox.vue`,
    - `disabled` attributes are bound to `disableOrUndefined` that
      is newly introduced to `CheckRadioMixin` (see below).
- In `src/utils/CheckRadioMixin.js`,
    - The default `v-model` binding is updated.
        - `value` --> `modelValue`
        - `input` --> `update:modelValue`
    - `disabledOrUndefined` that takes `true` or `undefined`. This is
      introduced to support new behavior of Vue 3. On Vue 3, setting
      a boolean attribute `false` does not remove it. To do so,
      `null` or `undefined` has to be given instead.
- Automatic ESLint fix is applied.
  • Loading branch information
kikuomax committed Jul 6, 2023
1 parent 1a878a9 commit c8aad46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/components/checkbox/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
class="b-checkbox checkbox"
:class="[size, { 'is-disabled': disabled }]"
ref="label"
:disabled="disabled"
:disabled="disabledOrUndefined"
@click="focus"
@keydown.prevent.enter="$refs.label.click()"
@keydown.prevent.space="$refs.label.click()">
@keydown.prevent.space="$refs.label.click()"
>
<!-- Checkbox needs to listen for a space event instead of a just a
click and enter event so that that using the keyboard spacebar will also
trigger the checkbox change in the b-table -->
Expand All @@ -18,15 +19,16 @@
ref="input"
@click.stop
:autocomplete="autocomplete"
:disabled="disabled"
:disabled="disabledOrUndefined"
:required="required"
:name="name"
:value="nativeValue"
:true-value="trueValue"
:false-value="falseValue"
:aria-labelledby="ariaLabelledby">
:aria-labelledby="ariaLabelledby"
>
<span class="check" :class="type" />
<span :id="ariaLabelledby" class="control-label"><slot/></span>
<span :id="ariaLabelledby" class="control-label"><slot /></span>
</label>
</template>

Expand Down
14 changes: 10 additions & 4 deletions src/utils/CheckRadioMixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
props: {
value: [String, Number, Boolean, Function, Object, Array],
modelValue: [String, Number, Boolean, Function, Object, Array],
nativeValue: [String, Number, Boolean, Function, Object, Array],
type: String,
disabled: Boolean,
Expand All @@ -10,7 +10,7 @@ export default {
},
data() {
return {
newValue: this.value
newValue: this.modelValue
}
},
computed: {
Expand All @@ -20,15 +20,21 @@ export default {
},
set(value) {
this.newValue = value
this.$emit('input', value)
this.$emit('update:modelValue', value)
}
},
disabledOrUndefined() {
// On Vue 3, setting a boolean attribute `false` does not remove it.
// To remove it, `null` or `undefined` has to be given.
// Setting `false` ends up with a grayed out component.
return this.disabled || undefined
}
},
watch: {
/**
* When v-model change, set internal value.
*/
value(value) {
modelValue(value) {
this.newValue = value
}
},
Expand Down

0 comments on commit c8aad46

Please sign in to comment.