From 94c404b12a7ead55d8c85b974faa5355e73d8710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=E3=81=BF=E3=81=9A=E3=81=8D?= <45122329+cokemine@users.noreply.github.com> Date: Sat, 30 Oct 2021 21:30:52 +0800 Subject: [PATCH] fix(checkbox): fix checkbox when modelvalue length less than min limit (#1745) * fix(checkbox): fix checkbox when modelvalue length less than min limit * fix * fix something wrong while handling conflict --- .../checkbox/__tests__/checkbox.spec.ts | 29 ++++++++++++------- .../components/checkbox/src/useCheckbox.ts | 14 +-------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/packages/components/checkbox/__tests__/checkbox.spec.ts b/packages/components/checkbox/__tests__/checkbox.spec.ts index 41a7a7ac30..f30d5393cd 100644 --- a/packages/components/checkbox/__tests__/checkbox.spec.ts +++ b/packages/components/checkbox/__tests__/checkbox.spec.ts @@ -294,34 +294,43 @@ describe('check-button', () => { ` + `, () => ({ - checkList: ['a'], + checkList: ['a', 'b'], lastEvent: null, }) ) const vm = wrapper.vm - expect(vm.checkList.length).toBe(1) + expect(vm.checkList.length).toBe(2) await wrapper.findComponent({ ref: 'a' }).trigger('click') vm.$nextTick(async () => { - expect(vm.checkList.length).toBe(1) - await wrapper.findComponent({ ref: 'b' }).trigger('click') expect(vm.checkList.length).toBe(2) await wrapper.findComponent({ ref: 'c' }).trigger('click') - expect(vm.checkList.length).toBe(2) - expect(vm.checkList).toEqual(['a', 'b']) - expect((wrapper.findComponent({ ref: 'c' }).vm as any).isDisabled).toBe( + expect(vm.checkList.length).toBe(3) + expect(vm.checkList).toEqual(['a', 'b', 'c']) + expect((wrapper.findComponent({ ref: 'd' }).vm as any).isDisabled).toBe( true ) - expect((wrapper.findComponent({ ref: 'd' }).vm as any).isDisabled).toBe( + expect((wrapper.findComponent({ ref: 'e' }).vm as any).isDisabled).toBe( + true + ) + vm.checkList = [] + await vm.$nextTick() + await wrapper.findComponent({ ref: 'a' }).trigger('click') + await wrapper.findComponent({ ref: 'd' }).trigger('click') + expect(vm.checkList).toEqual(['a', 'd']) + await wrapper.findComponent({ ref: 'a' }).trigger('click') + expect(vm.checkList).toEqual(['a', 'd']) + expect((wrapper.findComponent({ ref: 'a' }).vm as any).isDisabled).toBe( true ) }) diff --git a/packages/components/checkbox/src/useCheckbox.ts b/packages/components/checkbox/src/useCheckbox.ts index 690b36a3ec..cd3873fd3f 100644 --- a/packages/components/checkbox/src/useCheckbox.ts +++ b/packages/components/checkbox/src/useCheckbox.ts @@ -73,21 +73,9 @@ const useModel = (props: IUseCheckboxProps) => { set(val: unknown) { if (isGroup.value && Array.isArray(val)) { - isLimitExceeded.value = false - - if ( - checkboxGroup.min !== undefined && - val.length < checkboxGroup.min.value - ) { - isLimitExceeded.value = true - } - if ( + isLimitExceeded.value = checkboxGroup.max !== undefined && val.length > checkboxGroup.max.value - ) { - isLimitExceeded.value = true - } - isLimitExceeded.value === false && checkboxGroup?.changeEvent?.(val) } else { emit(UPDATE_MODEL_EVENT, val)