From 308c30c738823ba4cd4d8f5ecb5339958b8c344c Mon Sep 17 00:00:00 2001 From: Cherry7 <79909910+CCherry07@users.noreply.github.com> Date: Thu, 15 Jun 2023 11:17:58 +0800 Subject: [PATCH] fix: add disabledContext override with form components (#6618) * fix: add disabledContext override with form components * test: update snap * fix: LabelWidth demo filename * fix: fontsize spelling mistake --- .../__tests__/__snapshots__/demo.test.js.snap | 20 +++--- components/button/button.tsx | 11 ++-- components/checkbox/Checkbox.tsx | 4 +- .../__tests__/__snapshots__/demo.test.js.snap | 65 +++++++++++-------- components/form/demo/index.vue | 7 +- .../demo/{lable-width.vue => label-width.vue} | 0 .../__tests__/__snapshots__/demo.test.js.snap | 12 ++-- components/input-number/index.tsx | 8 ++- components/input/ClearableLabeledInput.tsx | 3 +- components/input/TextArea.tsx | 5 +- .../__tests__/__snapshots__/demo.test.js.snap | 62 +++++++++++------- components/page-header/style/index.ts | 2 +- components/radio/Radio.tsx | 5 +- components/switch/index.tsx | 12 ++-- 14 files changed, 128 insertions(+), 88 deletions(-) rename components/form/demo/{lable-width.vue => label-width.vue} (100%) diff --git a/components/button/__tests__/__snapshots__/demo.test.js.snap b/components/button/__tests__/__snapshots__/demo.test.js.snap index a706d9d1d..cd54d6e05 100644 --- a/components/button/__tests__/__snapshots__/demo.test.js.snap +++ b/components/button/__tests__/__snapshots__/demo.test.js.snap @@ -260,8 +260,8 @@ exports[`renders ./components/button/demo/icon.vue correctly 1`] = `
-
- +
+
-
- +
+
@@ -281,14 +281,14 @@ exports[`renders ./components/button/demo/icon.vue correctly 1`] = `
-
- +
+
-
- +
+
@@ -347,10 +347,10 @@ exports[`renders ./components/button/demo/multiple.vue correctly 1`] = ` secondary
-
- +
diff --git a/components/button/button.tsx b/components/button/button.tsx index 06a30f118..32fdf9e21 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -13,6 +13,7 @@ import Wave from '../_util/wave'; import buttonProps from './buttonTypes'; import { flattenChildren, initDefaultProps } from '../_util/props-util'; import useConfigInject from '../config-provider/hooks/useConfigInject'; +import { useInjectDisabled } from '../config-provider/DisabledContext'; import devWarning from '../vc-util/devWarning'; import LoadingIcon from './LoadingIcon'; import useStyle from './style'; @@ -46,6 +47,8 @@ export default defineComponent({ const { prefixCls, autoInsertSpaceInButton, direction, size } = useConfigInject('btn', props); const [wrapSSR, hashId] = useStyle(prefixCls); const groupSizeContext = GroupSizeContext.useInject(); + const disabledContext = useInjectDisabled(); + const mergedDisabled = computed(() => props.disabled ?? disabledContext.value); const buttonNodeRef = shallowRef(null); const delayTimeoutRef = shallowRef(undefined); let isNeedInserted = false; @@ -124,7 +127,7 @@ export default defineComponent({ }; const handleClick = (event: Event) => { // https://github.com/ant-design/ant-design/issues/30207 - if (innerLoading.value || props.disabled) { + if (innerLoading.value || mergedDisabled.value) { event.preventDefault(); return; } @@ -178,13 +181,13 @@ export default defineComponent({ isNeedInserted = children.length === 1 && !icon && !isUnBorderedButtonType(props.type); - const { type, htmlType, disabled, href, title, target } = props; + const { type, htmlType, href, title, target } = props; const iconType = innerLoading.value ? 'loading' : icon; const buttonProps = { ...attrs, title, - disabled, + disabled: mergedDisabled.value, class: [ classes.value, attrs.class, @@ -194,7 +197,7 @@ export default defineComponent({ onMousedown: handleMousedown, }; // https://github.com/vueComponent/ant-design-vue/issues/4930 - if (!disabled) { + if (!mergedDisabled.value) { delete buttonProps.disabled; } const iconNode = diff --git a/components/checkbox/Checkbox.tsx b/components/checkbox/Checkbox.tsx index 145d9f273..a52109a5c 100644 --- a/components/checkbox/Checkbox.tsx +++ b/components/checkbox/Checkbox.tsx @@ -33,7 +33,6 @@ export default defineComponent({ const formItemContext = useInjectFormItemContext(); const formItemInputContext = FormItemInputContext.useInject(); const { prefixCls, direction, disabled } = useConfigInject('checkbox', props); - // style const [wrapSSR, hashId] = useStyle(prefixCls); @@ -85,6 +84,7 @@ export default defineComponent({ id, prefixCls: prefixCls.value, ...restAttrs, + disabled: mergedDisabled.value, }; if (checkboxGroup && !skipGroup) { checkboxProps.onChange = (...args) => { @@ -93,7 +93,7 @@ export default defineComponent({ }; checkboxProps.name = checkboxGroup.name.value; checkboxProps.checked = checkboxGroup.mergedValue.value.includes(props.value); - checkboxProps.disabled = props.disabled || checkboxGroup.disabled.value; + checkboxProps.disabled = mergedDisabled.value || checkboxGroup.disabled.value; checkboxProps.indeterminate = indeterminate; } else { checkboxProps.onChange = handleChange; diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index 7972ca268..3a4f51c88 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -294,7 +294,7 @@ exports[`renders ./components/form/demo/custom-validation.vue correctly 1`] = `
-
+
@@ -333,9 +333,10 @@ exports[`renders ./components/form/demo/customized-form-controls.vue correctly 1
-
RMB +
RMB -
+
@@ -448,11 +449,11 @@ exports[`renders ./components/form/demo/dynamic-form-items-complex.vue correctly
-
-
+
@@ -726,7 +727,7 @@ exports[`renders ./components/form/demo/inline-login.vue correctly 1`] = ` `; -exports[`renders ./components/form/demo/lable-width.vue correctly 1`] = ` +exports[`renders ./components/form/demo/label-width.vue correctly 1`] = `
@@ -940,7 +941,7 @@ exports[`renders ./components/form/demo/nest-messages.vue correctly 1`] = `
-
+
@@ -1080,6 +1081,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`]
+
@@ -1103,6 +1105,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`]
+
@@ -1126,6 +1129,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`]
+
@@ -1151,6 +1155,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`]
+
@@ -1176,6 +1181,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`]
+
@@ -1199,6 +1205,7 @@ exports[`renders ./components/form/demo/time-related-controls.vue correctly 1`] +
@@ -1253,11 +1260,11 @@ exports[`renders ./components/form/demo/useForm-basic.vue correctly 1`] = `
-
please select your zone -
+
@@ -1332,11 +1339,11 @@ exports[`renders ./components/form/demo/useForm-merge.vue correctly 1`] = `
-
please select your zone -
+
@@ -1463,11 +1470,11 @@ exports[`renders ./components/form/demo/useForm-trigger.vue correctly 1`] = `
-
please select your zone -
+
@@ -1525,11 +1532,11 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
Please select a country -
+
@@ -1550,7 +1557,6 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
@@ -1582,7 +1589,7 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
+
machines
@@ -1623,8 +1630,8 @@ exports[`renders ./components/form/demo/validate-other.vue correctly 1`] = `
-
+
ABCDEF
@@ -1920,6 +1927,7 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
+
@@ -1943,6 +1951,7 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = ` +
@@ -1968,6 +1977,7 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
+
@@ -1987,11 +1997,11 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
-
I'm Select -
+
@@ -2012,11 +2022,11 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
-
I'm Cascader -
+
@@ -2042,11 +2052,11 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
-
I'm TreeSelect -
+
@@ -2082,6 +2092,7 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = `
+
@@ -2108,6 +2119,7 @@ exports[`renders ./components/form/demo/validate-static.vue correctly 1`] = ` +
@@ -2270,11 +2282,11 @@ exports[`renders ./components/form/demo/validation.vue correctly 1`] = `
-
please select your zone -
+
@@ -2299,6 +2311,7 @@ exports[`renders ./components/form/demo/validation.vue correctly 1`] = `
+
diff --git a/components/form/demo/index.vue b/components/form/demo/index.vue index 6e624792a..83c29a8a9 100644 --- a/components/form/demo/index.vue +++ b/components/form/demo/index.vue @@ -1,7 +1,7 @@