From 598448bcf1045d68d3d53562eacc784ac900044f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=B3=BD=E5=9D=A4?= <984757534@qq.com> Date: Fri, 1 Nov 2024 11:09:26 +0800 Subject: [PATCH 1/2] fix: `n-input-group-label` component is not affected by the `size` attribute of the `n-form` component --- CHANGELOG.en-US.md | 1 + CHANGELOG.zh-CN.md | 1 + src/input/src/InputGroupLabel.tsx | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 7c694ac867b..e7dff1105ef 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -7,6 +7,7 @@ ### Fixes - Fix `n-time-picker`'s `use-12-hours` type error warning, closes [#4308](https://github.com/tusen-ai/naive-ui/issues/4308) +- Fix `n-input-group-label` component is not affected by the `size` attribute of the `n-form` component, closes [#6504](https://github.com/tusen-ai/naive-ui/issues/6504) ### Features diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 06e42e84b73..303f21036cd 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -7,6 +7,7 @@ ### Fixes - `n-time-picker` 的 `use-12-hours` 类型错误警告,关闭 [#4308](https://github.com/tusen-ai/naive-ui/issues/4308) +- 修复 `n-input-group-label` 不受表单组件 `n-form` 的 `size` 属性影响,关闭 [#6504](https://github.com/tusen-ai/naive-ui/issues/6504) ### Features diff --git a/src/input/src/InputGroupLabel.tsx b/src/input/src/InputGroupLabel.tsx index 6cd1f3e573d..9b9de764946 100644 --- a/src/input/src/InputGroupLabel.tsx +++ b/src/input/src/InputGroupLabel.tsx @@ -1,5 +1,5 @@ import { type PropType, computed, defineComponent, h } from 'vue' -import { useConfig, useTheme, useThemeClass } from '../../_mixins' +import { useConfig, useFormItem, useTheme, useThemeClass } from '../../_mixins' import type { ThemeProps } from '../../_mixins' import { createKey } from '../../_utils' import type { ExtractPublicPropTypes } from '../../_utils' @@ -30,6 +30,20 @@ export default defineComponent({ setup(props) { const { mergedBorderedRef, mergedClsPrefixRef, inlineThemeDisabled } = useConfig(props) + + const formItem = useFormItem(props, { + mergedSize(NFormItem) { + if (NFormItem) { + const { mergedSize } = NFormItem + if (mergedSize.value !== undefined) { + return mergedSize.value + } + } + return props.size + } + }) + const { mergedSizeRef } = formItem + const themeRef = useTheme( 'Input', '-input-group-label', @@ -39,7 +53,7 @@ export default defineComponent({ mergedClsPrefixRef ) const cssVarsRef = computed(() => { - const { size } = props + const { value: size } = mergedSizeRef const { common: { cubicBezierEaseInOut }, self: { @@ -66,7 +80,10 @@ export default defineComponent({ const themeClassHandle = inlineThemeDisabled ? useThemeClass( 'input-group-label', - computed(() => props.size[0]), + computed(() => { + const { value: size } = mergedSizeRef + return size[0] + }), cssVarsRef, props ) @@ -74,6 +91,7 @@ export default defineComponent({ return { mergedClsPrefix: mergedClsPrefixRef, mergedBordered: mergedBorderedRef, + mergedSize: mergedSizeRef, cssVars: inlineThemeDisabled ? undefined : cssVarsRef, themeClass: themeClassHandle?.themeClass, onRender: themeClassHandle?.onRender From 48f31de66117a9d03500b1b6ca1b904fd830de6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=B3=BD=E5=9D=A4?= <984757534@qq.com> Date: Fri, 1 Nov 2024 16:49:36 +0800 Subject: [PATCH 2/2] feat: ++ --- src/input/src/InputGroupLabel.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/input/src/InputGroupLabel.tsx b/src/input/src/InputGroupLabel.tsx index 9b9de764946..ebd4e4e6201 100644 --- a/src/input/src/InputGroupLabel.tsx +++ b/src/input/src/InputGroupLabel.tsx @@ -10,10 +10,7 @@ import type { Size } from './interface' export const inputGroupLabelProps = { ...(useTheme.props as ThemeProps), - size: { - type: String as PropType, - default: 'medium' - }, + size: String as PropType, bordered: { type: Boolean as PropType, default: undefined @@ -33,13 +30,16 @@ export default defineComponent({ const formItem = useFormItem(props, { mergedSize(NFormItem) { + const { size } = props + if (size !== undefined) + return size if (NFormItem) { const { mergedSize } = NFormItem if (mergedSize.value !== undefined) { return mergedSize.value } } - return props.size + return 'medium' } }) const { mergedSizeRef } = formItem