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`] = `
-
-
+
@@ -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`] = `
@@ -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`] = `
@@ -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`] = `
+
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 @@
-
+
@@ -40,7 +40,7 @@ import formContextVue from './form-context.vue';
import formInModalVue from './form-in-modal.vue';
import HorizontalLogin from './horizontal-login.vue';
import inlineLoginVue from './inline-login.vue';
-import LableWidth from './lable-width.vue';
+import LabelWidth from './label-width.vue';
import Layout from './layout.vue';
import NestedForm from './nest-messages.vue';
import normalLoginVue from './normal-login.vue';
@@ -74,7 +74,7 @@ export default defineComponent({
UseFormNested,
UseFormTrigger,
UseFormMerge,
- LableWidth,
+ LabelWidth,
CustomizedFormControls,
advancedSearchVue,
dynamicFormItemsComplexVue,
@@ -91,6 +91,7 @@ export default defineComponent({
.code-box-demo .ant-form:not(.ant-form-inline):not(.ant-form-vertical) {
max-width: 600px;
}
+
.markdown.api-container table td:nth-of-type(4) {
white-space: nowrap;
word-wrap: break-word;
diff --git a/components/form/demo/lable-width.vue b/components/form/demo/label-width.vue
similarity index 100%
rename from components/form/demo/lable-width.vue
rename to components/form/demo/label-width.vue
diff --git a/components/input-number/__tests__/__snapshots__/demo.test.js.snap b/components/input-number/__tests__/__snapshots__/demo.test.js.snap
index 111271bd0..b25b81fe7 100644
--- a/components/input-number/__tests__/__snapshots__/demo.test.js.snap
+++ b/components/input-number/__tests__/__snapshots__/demo.test.js.snap
@@ -20,11 +20,11 @@ exports[`renders ./components/input-number/demo/addon.vue correctly 1`] = `
@@ -71,11 +71,11 @@ exports[`renders ./components/input-number/demo/addon.vue correctly 1`] = `
diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx
index 05caeb101..3a3b0d15c 100644
--- a/components/input-number/index.tsx
+++ b/components/input-number/index.tsx
@@ -65,12 +65,13 @@ const InputNumber = defineComponent({
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
const { prefixCls, size, direction, disabled } = useConfigInject('input-number', props);
const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction);
+ const disabledContext = useInjectDisabled();
+ const mergedDisabled = computed(() => disabled.value ?? disabledContext.value);
// Style
const [wrapSSR, hashId] = useStyle(prefixCls);
const mergedSize = computed(() => compactSize.value || size.value);
- const disabledContext = useInjectDisabled();
- const mergedDisabled = computed(() => disabled.value ?? disabledContext.value);
+
const mergedValue = shallowRef(props.value === undefined ? props.defaultValue : props.value);
const focused = shallowRef(false);
watch(
@@ -120,7 +121,8 @@ const InputNumber = defineComponent({
prefix = slots.prefix?.(),
valueModifiers = {},
...others
- } = { ...attrs, ...props, id } as InputNumberProps & HTMLAttributes;
+ } = { ...attrs, ...props, id, disabled: mergedDisabled.value } as InputNumberProps &
+ HTMLAttributes;
const preCls = prefixCls.value;
diff --git a/components/input/ClearableLabeledInput.tsx b/components/input/ClearableLabeledInput.tsx
index 3728a249f..c2b6f973b 100644
--- a/components/input/ClearableLabeledInput.tsx
+++ b/components/input/ClearableLabeledInput.tsx
@@ -44,7 +44,6 @@ export default defineComponent({
},
setup(props, { slots, attrs }) {
const statusContext = FormItemInputContext.useInject();
-
const renderClearIcon = (prefixCls: string) => {
const { value, disabled, readonly, handleReset, suffix = slots.suffix } = props;
const needClear = !disabled && !readonly && value;
@@ -83,6 +82,7 @@ export default defineComponent({
if (!allowClear) {
return cloneElement(element, {
value,
+ disabled: props.disabled,
});
}
const affixWrapperCls = classNames(
@@ -106,6 +106,7 @@ export default defineComponent({
{cloneElement(element, {
style: null,
value,
+ disabled: props.disabled,
})}
{renderClearIcon(prefixCls)}
diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx
index c6dcaaea2..e7cb01313 100644
--- a/components/input/TextArea.tsx
+++ b/components/input/TextArea.tsx
@@ -66,6 +66,7 @@ export default defineComponent({
// Style
const [wrapSSR, hashId] = useStyle(prefixCls);
const disabled = useInjectDisabled();
+
const showCount = computed(() => {
return (props.showCount as any) === '' || props.showCount || false;
});
@@ -207,6 +208,7 @@ export default defineComponent({
getStatusClassNames(prefixCls.value, mergedStatus.value),
hashId.value,
],
+ disabled: disabled.value,
showCount: null,
prefixCls: prefixCls.value,
onInput: handleChange,
@@ -222,7 +224,7 @@ export default defineComponent({
return (
@@ -250,7 +252,6 @@ export default defineComponent({
return () => {
const { maxlength, bordered = true, hidden } = props;
const { style, class: customClass } = attrs;
-
const inputProps: any = {
...props,
...attrs,
diff --git a/components/input/__tests__/__snapshots__/demo.test.js.snap b/components/input/__tests__/__snapshots__/demo.test.js.snap
index a85eef9e7..ba0df7692 100644
--- a/components/input/__tests__/__snapshots__/demo.test.js.snap
+++ b/components/input/__tests__/__snapshots__/demo.test.js.snap
@@ -4,23 +4,26 @@ exports[`renders ./components/input/demo/addon.vue correctly 1`] = `
Http://.com
-
-
`;
exports[`renders ./components/input/demo/password-input.vue correctly 1`] = `
@@ -118,7 +129,8 @@ exports[`renders ./components/input/demo/password-input.vue correctly 1`] = `
`;
exports[`renders ./components/input/demo/presuffix.vue correctly 1`] = `
-