From 203e42382f548347519d996a629fd9553642ad35 Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Tue, 6 Jul 2021 21:58:05 +0800
Subject: [PATCH 01/13] fix: timepicker error border not show #4331
---
.../__snapshots__/index.test.js.snap | 102 +++++++++---------
.../__snapshots__/index.test.js.snap | 2 +-
components/time-picker/index.tsx | 4 +
components/vc-time-picker/TimePicker.jsx | 4 +-
4 files changed, 59 insertions(+), 53 deletions(-)
diff --git a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap
index e7de8ecd5..c002bb226 100644
--- a/components/locale-provider/__tests__/__snapshots__/index.test.js.snap
+++ b/components/locale-provider/__tests__/__snapshots__/index.test.js.snap
@@ -609,7 +609,7 @@ exports[`Locale Provider should display the text as ar 1`] = `
-
+
~
@@ -1151,7 +1151,7 @@ exports[`Locale Provider should display the text as bg 1`] = `
-
+
~
@@ -1693,7 +1693,7 @@ exports[`Locale Provider should display the text as ca 1`] = `
-
+
~
@@ -2235,7 +2235,7 @@ exports[`Locale Provider should display the text as cs 1`] = `
-
+
~
@@ -2777,7 +2777,7 @@ exports[`Locale Provider should display the text as da 1`] = `
-
+
~
@@ -3319,7 +3319,7 @@ exports[`Locale Provider should display the text as de 1`] = `
-
+
~
@@ -3861,7 +3861,7 @@ exports[`Locale Provider should display the text as el 1`] = `
-
+
~
@@ -4403,7 +4403,7 @@ exports[`Locale Provider should display the text as en 1`] = `
-
+
~
@@ -4945,7 +4945,7 @@ exports[`Locale Provider should display the text as en-gb 1`] = `
-
+
~
@@ -5487,7 +5487,7 @@ exports[`Locale Provider should display the text as es 1`] = `
-
+
~
@@ -6029,7 +6029,7 @@ exports[`Locale Provider should display the text as et 1`] = `
-
+
~
@@ -6571,7 +6571,7 @@ exports[`Locale Provider should display the text as fa 1`] = `
-
+
~
@@ -7113,7 +7113,7 @@ exports[`Locale Provider should display the text as fi 1`] = `
-
+
~
@@ -7655,7 +7655,7 @@ exports[`Locale Provider should display the text as fr 1`] = `
-
+
~
@@ -8197,7 +8197,7 @@ exports[`Locale Provider should display the text as fr 2`] = `
-
+
~
@@ -8739,7 +8739,7 @@ exports[`Locale Provider should display the text as he 1`] = `
-
+
~
@@ -9281,7 +9281,7 @@ exports[`Locale Provider should display the text as hi 1`] = `
-
+
~
@@ -9823,7 +9823,7 @@ exports[`Locale Provider should display the text as hr 1`] = `
-
+
~
@@ -10365,7 +10365,7 @@ exports[`Locale Provider should display the text as hu 1`] = `
-
+
~
@@ -10907,7 +10907,7 @@ exports[`Locale Provider should display the text as hy 1`] = `
-
+
~
@@ -11449,7 +11449,7 @@ exports[`Locale Provider should display the text as id 1`] = `
-
+
~
@@ -11991,7 +11991,7 @@ exports[`Locale Provider should display the text as is 1`] = `
-
+
~
@@ -12533,7 +12533,7 @@ exports[`Locale Provider should display the text as it 1`] = `
-
+
~
@@ -13075,7 +13075,7 @@ exports[`Locale Provider should display the text as ja 1`] = `
-
+
~
@@ -13617,7 +13617,7 @@ exports[`Locale Provider should display the text as kn 1`] = `
-
+
~
@@ -14159,7 +14159,7 @@ exports[`Locale Provider should display the text as ko 1`] = `
-
+
~
@@ -14701,7 +14701,7 @@ exports[`Locale Provider should display the text as ku-iq 1`] = `
-
+
~
@@ -15243,7 +15243,7 @@ exports[`Locale Provider should display the text as lv 1`] = `
-
+
~
@@ -15785,7 +15785,7 @@ exports[`Locale Provider should display the text as mk 1`] = `
-
+
~
@@ -16327,7 +16327,7 @@ exports[`Locale Provider should display the text as mn-mn 1`] = `
-
+
~
@@ -16869,7 +16869,7 @@ exports[`Locale Provider should display the text as ms-my 1`] = `
-
+
~
@@ -17411,7 +17411,7 @@ exports[`Locale Provider should display the text as nb 1`] = `
-
+
~
@@ -17953,7 +17953,7 @@ exports[`Locale Provider should display the text as ne-np 1`] = `
-
+
~
@@ -18495,7 +18495,7 @@ exports[`Locale Provider should display the text as nl 1`] = `
-
+
~
@@ -19037,7 +19037,7 @@ exports[`Locale Provider should display the text as nl-be 1`] = `
-
+
~
@@ -19579,7 +19579,7 @@ exports[`Locale Provider should display the text as pl 1`] = `
-
+
~
@@ -20121,7 +20121,7 @@ exports[`Locale Provider should display the text as pt 1`] = `
-
+
~
@@ -20663,7 +20663,7 @@ exports[`Locale Provider should display the text as pt-br 1`] = `
-
+
~
@@ -21205,7 +21205,7 @@ exports[`Locale Provider should display the text as ro 1`] = `
-
+
~
@@ -21747,7 +21747,7 @@ exports[`Locale Provider should display the text as ru 1`] = `
-
+
~
@@ -22289,7 +22289,7 @@ exports[`Locale Provider should display the text as sk 1`] = `
-
+
~
@@ -22831,7 +22831,7 @@ exports[`Locale Provider should display the text as sl 1`] = `
-
+
~
@@ -23373,7 +23373,7 @@ exports[`Locale Provider should display the text as sr 1`] = `
-
+
~
@@ -23915,7 +23915,7 @@ exports[`Locale Provider should display the text as sv 1`] = `
-
+
~
@@ -24457,7 +24457,7 @@ exports[`Locale Provider should display the text as ta 1`] = `
-
+
~
@@ -24999,7 +24999,7 @@ exports[`Locale Provider should display the text as th 1`] = `
-
+
~
@@ -25541,7 +25541,7 @@ exports[`Locale Provider should display the text as tr 1`] = `
-
+
~
@@ -26083,7 +26083,7 @@ exports[`Locale Provider should display the text as uk 1`] = `
-
+
~
@@ -26625,7 +26625,7 @@ exports[`Locale Provider should display the text as vi 1`] = `
-
+
~
@@ -27167,7 +27167,7 @@ exports[`Locale Provider should display the text as zh-cn 1`] = `
-
+
~
@@ -27709,7 +27709,7 @@ exports[`Locale Provider should display the text as zh-tw 1`] = `
-
+
~
diff --git a/components/time-picker/__tests__/__snapshots__/index.test.js.snap b/components/time-picker/__tests__/__snapshots__/index.test.js.snap
index efdd99b93..20ee54124 100644
--- a/components/time-picker/__tests__/__snapshots__/index.test.js.snap
+++ b/components/time-picker/__tests__/__snapshots__/index.test.js.snap
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`TimePicker not render clean icon when allowClear is false 1`] = `
-
+
`;
diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx
index 479561920..8103baf17 100644
--- a/components/time-picker/index.tsx
+++ b/components/time-picker/index.tsx
@@ -20,6 +20,7 @@ import {
TimeOrTimesType,
} from '../_util/moment-util';
import { tuple, withInstall } from '../_util/type';
+import classNames from '../_util/classNames';
export function generateShowHourMinuteSecond(format: string) {
// Ref: http://momentjs.com/docs/#/parsing/string-format/
@@ -213,6 +214,8 @@ const TimePicker = defineComponent({
const { prefixCls: customizePrefixCls, getPopupContainer, placeholder, size } = props;
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('time-picker', customizePrefixCls);
+ const inputPrefixCls = getPrefixCls('input');
+ const pickerInputClass = classNames(`${prefixCls}-input`, inputPrefixCls);
const format = this.getDefaultFormat();
const pickerClassName = {
@@ -236,6 +239,7 @@ const TimePicker = defineComponent({
...this.$attrs,
allowEmpty: this.getAllowClear(),
prefixCls,
+ pickerInputClass,
getPopupContainer: getPopupContainer || getContextPopupContainer,
format,
value: this.sValue,
diff --git a/components/vc-time-picker/TimePicker.jsx b/components/vc-time-picker/TimePicker.jsx
index 8f16b52be..acf433302 100644
--- a/components/vc-time-picker/TimePicker.jsx
+++ b/components/vc-time-picker/TimePicker.jsx
@@ -35,6 +35,7 @@ export default defineComponent({
return moment();
},
},
+ pickerInputClass: String,
inputReadOnly: PropTypes.looseBool,
disabled: PropTypes.looseBool,
allowEmpty: PropTypes.looseBool,
@@ -346,6 +347,7 @@ export default defineComponent({
onFocus,
onBlur,
popupStyle,
+ pickerInputClass,
} = this;
const { class: className, style } = this.$attrs;
const popupClassName = this.getPopupClassName();
@@ -368,7 +370,7 @@ export default defineComponent({
>
Date: Wed, 7 Jul 2021 21:24:14 +0800
Subject: [PATCH 02/13] fix(UploadDragger): fix UploadDrager no export (#4334)
---
components/components.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/components.ts b/components/components.ts
index f02cb7ad8..e901d6a9a 100644
--- a/components/components.ts
+++ b/components/components.ts
@@ -192,6 +192,6 @@ export {
export type { UploadProps } from './upload';
-export { default as Upload } from './upload';
+export { default as Upload, UploadDragger } from './upload';
export { default as LocaleProvider } from './locale-provider';
From 427cf36eaa47f41e9f9e34231fb2d74db3a1abf8 Mon Sep 17 00:00:00 2001
From: John
Date: Wed, 7 Jul 2021 21:35:41 +0800
Subject: [PATCH 03/13] refactor(switch): support customize checked value #4329
(#4332)
* refactor(switch): support customize checked value #4329
* test: add test case
* refactor: update props name
* refactor: update ts
* refactor: optimize
---
components/switch/__tests__/index.test.js | 28 +++++++++
components/switch/index.tsx | 74 ++++++++++++++---------
2 files changed, 74 insertions(+), 28 deletions(-)
diff --git a/components/switch/__tests__/index.test.js b/components/switch/__tests__/index.test.js
index 73061036f..55980437b 100644
--- a/components/switch/__tests__/index.test.js
+++ b/components/switch/__tests__/index.test.js
@@ -4,6 +4,7 @@ import focusTest from '../../../tests/shared/focusTest';
import { resetWarned } from '../../_util/warning';
import mountTest from '../../../tests/shared/mountTest';
import { ref } from 'vue';
+import { asyncExpect } from '@/tests/utils';
describe('Switch', () => {
focusTest(Switch);
@@ -42,4 +43,31 @@ describe('Switch', () => {
);
errorSpy.mockRestore();
});
+
+ it('customize checked value should work', async () => {
+ resetWarned();
+ const checked = ref(1);
+ const onUpdate = val => (checked.value = val);
+ const wrapper = mount({
+ render() {
+ return (
+
+ );
+ },
+ });
+ await asyncExpect(() => {
+ wrapper.find('button').trigger('click');
+ });
+ expect(checked.value).toBe(2);
+
+ await asyncExpect(() => {
+ wrapper.find('button').trigger('click');
+ });
+ expect(checked.value).toBe(1);
+ });
});
diff --git a/components/switch/index.tsx b/components/switch/index.tsx
index 4febcce82..647b3961f 100644
--- a/components/switch/index.tsx
+++ b/components/switch/index.tsx
@@ -1,4 +1,4 @@
-import type { ExtractPropTypes } from 'vue';
+import type { ExtractPropTypes, PropType } from 'vue';
import {
defineComponent,
inject,
@@ -19,23 +19,35 @@ import { tuple, withInstall } from '../_util/type';
import { getPropsSlot } from '../_util/props-util';
import Omit from 'omit.js';
-export const SwitchSizes = tuple('small', 'default', 'large');
+export const SwitchSizes = tuple('small', 'default');
const switchProps = {
prefixCls: PropTypes.string,
size: PropTypes.oneOf(SwitchSizes),
disabled: PropTypes.looseBool,
- checkedChildren: PropTypes.any,
- unCheckedChildren: PropTypes.any,
+ checkedChildren: PropTypes.VNodeChild,
+ unCheckedChildren: PropTypes.VNodeChild,
tabindex: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
autofocus: PropTypes.looseBool,
loading: PropTypes.looseBool,
- checked: PropTypes.looseBool,
- onChange: PropTypes.func,
- onClick: PropTypes.func,
- onKeydown: PropTypes.func,
- onMouseup: PropTypes.func,
- 'onUpdate:checked': PropTypes.func,
+ checked: PropTypes.any,
+ checkedValue: PropTypes.any.def(true),
+ uncheckedValue: PropTypes.any.def(false),
+ onChange: {
+ type: Function as PropType<(checked: any, e: Event) => void>,
+ },
+ onClick: {
+ type: Function as PropType<(checked: any, e: Event) => void>,
+ },
+ onKeydown: {
+ type: Function as PropType<(e: Event) => void>,
+ },
+ onMouseup: {
+ type: Function as PropType<(e: Event) => void>,
+ },
+ 'onUpdate:checked': {
+ type: Function as PropType<(checked: any) => void>,
+ },
};
export type SwitchProps = Partial>;
@@ -46,7 +58,7 @@ const Switch = defineComponent({
inheritAttrs: false,
props: switchProps,
emits: ['update:checked', 'mouseup', 'change', 'click', 'keydown'],
- setup(props: SwitchProps, { attrs, slots, expose, emit }) {
+ setup(props, { attrs, slots, expose, emit }) {
onBeforeMount(() => {
warning(
!('defaultChecked' in attrs),
@@ -59,12 +71,13 @@ const Switch = defineComponent({
'`value` is not validate prop, do you mean `checked`?',
);
});
- const checked = ref(props.checked !== undefined ? !!props.checked : !!attrs.defaultChecked);
+ const checked = ref(props.checked !== undefined ? props.checked : attrs.defaultChecked);
+ const checkedStatus = computed(() => checked.value === props.checkedValue);
watch(
() => props.checked,
() => {
- checked.value = !!props.checked;
+ checked.value = props.checked;
},
);
@@ -92,29 +105,26 @@ const Switch = defineComponent({
});
});
- const setChecked = (check: boolean, e: MouseEvent | KeyboardEvent) => {
+ const setChecked = (check: any, e: MouseEvent | KeyboardEvent) => {
if (props.disabled) {
return;
}
- if (props.checked === undefined) {
- checked.value = check;
- }
emit('update:checked', check);
emit('change', check, e);
};
const handleClick = (e: MouseEvent) => {
focus();
- const newChecked = !checked.value;
+ const newChecked = checkedStatus.value ? props.uncheckedValue : props.checkedValue;
setChecked(newChecked, e);
emit('click', newChecked, e);
};
const handleKeyDown = (e: KeyboardEvent) => {
if (e.keyCode === KeyCode.LEFT) {
- setChecked(false, e);
+ setChecked(props.uncheckedValue, e);
} else if (e.keyCode === KeyCode.RIGHT) {
- setChecked(true, e);
+ setChecked(props.checkedValue, e);
}
emit('keydown', e);
};
@@ -123,6 +133,13 @@ const Switch = defineComponent({
refSwitchNode.value?.blur();
emit('mouseup', e);
};
+
+ const classNames = computed(() => ({
+ [`${prefixCls.value}-small`]: props.size === 'small',
+ [`${prefixCls.value}-loading`]: props.loading,
+ [`${prefixCls.value}-checked`]: checkedStatus.value,
+ [`${prefixCls.value}-disabled`]: props.disabled,
+ }));
return () => (