mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 04:37:47 +08:00
fix(components): [checkbox] fix true-value and false-value (#16051)
* fix(components): [checkbox] fix true-value and false-value closed #16049 * fix(components): update test
This commit is contained in:
parent
3ff8bbeaf8
commit
d2b8633f98
@ -247,14 +247,14 @@ describe('Checkbox', () => {
|
||||
<Checkbox
|
||||
label="Foobar"
|
||||
true-value="a"
|
||||
false-value={3}
|
||||
false-value={0}
|
||||
v-model={checked.value}
|
||||
/>
|
||||
))
|
||||
|
||||
await wrapper.trigger('click')
|
||||
await nextTick()
|
||||
expect(checked.value).toBe(3)
|
||||
expect(checked.value).toBe(0)
|
||||
await wrapper.trigger('click')
|
||||
await nextTick()
|
||||
expect(checked.value).toBe('a')
|
||||
@ -263,14 +263,14 @@ describe('Checkbox', () => {
|
||||
test('with label as slot content', async () => {
|
||||
const checked = ref('a')
|
||||
const wrapper = mount(() => (
|
||||
<Checkbox true-value="a" false-value={3} v-model={checked.value}>
|
||||
<Checkbox true-value="a" false-value={0} v-model={checked.value}>
|
||||
Foobar
|
||||
</Checkbox>
|
||||
))
|
||||
|
||||
await wrapper.trigger('click')
|
||||
await nextTick()
|
||||
expect(checked.value).toBe(3)
|
||||
expect(checked.value).toBe(0)
|
||||
await wrapper.trigger('click')
|
||||
await nextTick()
|
||||
expect(checked.value).toBe('a')
|
||||
|
@ -8,8 +8,8 @@
|
||||
:name="name"
|
||||
:tabindex="tabindex"
|
||||
:disabled="isDisabled"
|
||||
:true-value="trueValue || trueLabel"
|
||||
:false-value="falseValue || falseLabel"
|
||||
:true-value="trueValue ?? trueLabel"
|
||||
:false-value="falseValue ?? falseLabel"
|
||||
@change="handleChange"
|
||||
@focus="isFocused = true"
|
||||
@blur="isFocused = false"
|
||||
|
@ -16,8 +16,8 @@
|
||||
:name="name"
|
||||
:tabindex="tabindex"
|
||||
:disabled="isDisabled"
|
||||
:true-value="trueValue || trueLabel"
|
||||
:false-value="falseValue || falseLabel"
|
||||
:true-value="trueValue ?? trueLabel"
|
||||
:false-value="falseValue ?? falseLabel"
|
||||
@change="handleChange"
|
||||
@focus="isFocused = true"
|
||||
@blur="isFocused = false"
|
||||
|
@ -30,8 +30,8 @@ export const useCheckboxEvent = (
|
||||
|
||||
function getLabeledValue(value: string | number | boolean) {
|
||||
return [true, props.trueValue, props.trueLabel].includes(value)
|
||||
? (props.trueValue || props.trueLabel) ?? true
|
||||
: (props.falseValue || props.falseLabel) ?? false
|
||||
? props.trueValue ?? props.trueLabel ?? true
|
||||
: props.falseValue ?? props.falseLabel ?? false
|
||||
}
|
||||
|
||||
function emitChangeEvent(
|
||||
|
@ -43,7 +43,7 @@ export const useCheckbox = (
|
||||
if (isArray(model.value) && !model.value.includes(actualValue.value)) {
|
||||
model.value.push(actualValue.value)
|
||||
} else {
|
||||
model.value = props.trueValue || props.trueLabel || true
|
||||
model.value = props.trueValue ?? props.trueLabel ?? true
|
||||
}
|
||||
}
|
||||
props.checked && addToStore()
|
||||
|
Loading…
Reference in New Issue
Block a user