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