From 9878b06bf374268cd890b41645dc9b91dde09222 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Sun, 30 Oct 2022 01:23:56 +0800 Subject: [PATCH] fix(form-item): label text is in wrong position when `label-align="left"` and `require-mark-placement="left"` and `label-placement="left"`, closes #3871 --- CHANGELOG.en-US.md | 1 + CHANGELOG.zh-CN.md | 1 + src/form/src/FormItem.tsx | 45 ++++++++++++++++++++------- src/form/src/styles/form-item.cssr.ts | 3 ++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 5269e06c7bf..a8e1b2f106b 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -20,6 +20,7 @@ ### Fixes - Fix `n-image` to preview the image, press and drag the left mouse click,closes [#3950](https://github.com/tusen-ai/naive-ui/issues/3950). +- Fix `n-form-item`'s label text is in wrong position when `label-align="left"` and `require-mark-placement="left"` and `label-placement="left"`, closes [#3871](https://github.com/tusen-ai/naive-ui/issues/3871). ### i18n diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index fa78f1c0b4b..87285108433 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -20,6 +20,7 @@ ### Fixes - 修复 `n-image` 进行图片预览只可以按住鼠标左键拖拽,关闭 [#3950](https://github.com/tusen-ai/naive-ui/issues/3950) +- 修复 `n-form-item` 在 `label-align="left"` 并且 `require-mark-placement="left"` 并且 `label-placement="left"` 时标签文本显示位置有问题,关闭 [#3871](https://github.com/tusen-ai/naive-ui/issues/3871) ### i18n diff --git a/src/form/src/FormItem.tsx b/src/form/src/FormItem.tsx index c72e40e375f..5bf668b4f93 100644 --- a/src/form/src/FormItem.tsx +++ b/src/form/src/FormItem.tsx @@ -156,7 +156,8 @@ export default defineComponent({ const { mergedSize: mergedSizeRef } = formItemSizeRefs const { mergedLabelPlacement: labelPlacementRef, - mergedLabelAlign: labelTextAlignRef + mergedLabelAlign: labelTextAlignRef, + mergedRequireMarkPlacement: mergedRequireMarkPlacementRef } = formItemMiscRefs const renderExplainsRef = ref< Array<{ @@ -425,22 +426,40 @@ export default defineComponent({ } return cssVars }) - const themeClassHandle = useThemeClass( - 'form-item', - computed(() => { - return `${mergedSizeRef.value[0]}${labelPlacementRef.value[0]}${ - labelTextAlignRef.value?.[0] || '' - }` - }), - cssVarsRef, - props - ) + const themeClassHandle = inlineThemeDisabled + ? useThemeClass( + 'form-item', + computed(() => { + return `${mergedSizeRef.value[0]}${labelPlacementRef.value[0]}${ + labelTextAlignRef.value?.[0] || '' + }` + }), + cssVarsRef, + props + ) + : undefined + const reverseColSpaceRef = computed(() => { + // label placement left + // require-mark-placement | label align | areas (1fr auto) + // left | left | mark text (need reverse) + // left | right | mark text (okay) + // right | left | mark text (okay) + // right | right | mark text (okay) + // right-hanging | left | text mark (okay) + // right-hanging | right | text mark (okay) + return ( + labelPlacementRef.value === 'left' && + mergedRequireMarkPlacementRef.value === 'left' && + labelTextAlignRef.value === 'left' + ) + }) return { labelElementRef, mergedClsPrefix: mergedClsPrefixRef, mergedRequired: mergedRequiredRef, feedbackId: feedbackIdRef, renderExplains: renderExplainsRef, + reverseColSpace: reverseColSpaceRef, ...formItemMiscRefs, ...formItemSizeRefs, ...exposedRef, @@ -492,7 +511,9 @@ export default defineComponent({ class={[ labelProps?.class, `${mergedClsPrefix}-form-item-label`, - `${mergedClsPrefix}-form-item-label--${mergedRequireMarkPlacement}-mark` + `${mergedClsPrefix}-form-item-label--${mergedRequireMarkPlacement}-mark`, + this.reverseColSpace && + `${mergedClsPrefix}-form-item-label--reverse-columns-space` ]} style={this.mergedLabelStyle as any} ref="labelElementRef" diff --git a/src/form/src/styles/form-item.cssr.ts b/src/form/src/styles/form-item.cssr.ts index befba62a9cf..7bdfc8a4e72 100644 --- a/src/form/src/styles/form-item.cssr.ts +++ b/src/form/src/styles/form-item.cssr.ts @@ -72,6 +72,9 @@ export default cB('form-item', ` flex-shrink: 0; flex-grow: 0; `, [ + cM('reverse-columns-space', ` + grid-template-columns: auto 1fr; + `), cM('left-mark', ` grid-template-areas: "mark text"