diff --git a/components/input/Input.tsx b/components/input/Input.tsx index 1a4d28ef5..3bb72580a 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -13,6 +13,7 @@ import VcInput from '../vc-input/Input'; import inputProps from './inputProps'; import omit from '../_util/omit'; import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled'; +import { NoCompactStyle, useCompactItemContext } from '../space/Compact'; // CSSINJS import useStyle from './style'; @@ -30,6 +31,11 @@ export default defineComponent({ const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status)); const { direction, prefixCls, size, autocomplete } = useConfigInject('input', props); + // ===================== Compact Item ===================== + const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction); + const mergedSize = computed(() => { + return compactSize.value || size.value; + }); // Style const [wrapSSR, hashId] = useStyle(prefixCls); @@ -140,12 +146,25 @@ export default defineComponent({ onFocus={handleFocus} suffix={suffixNode} allowClear={allowClear} - addonAfter={addonAfter && {addonAfter}} - addonBefore={addonBefore && {addonBefore}} + addonAfter={ + addonAfter && ( + + {addonAfter} + + ) + } + addonBefore={ + addonBefore && ( + + {addonBefore} + + ) + } + class={[attrs.class, compactItemClassnames.value]} inputClassName={classNames( { - [`${prefixClsValue}-sm`]: size.value === 'small', - [`${prefixClsValue}-lg`]: size.value === 'large', + [`${prefixClsValue}-sm`]: mergedSize.value === 'small', + [`${prefixClsValue}-lg`]: mergedSize.value === 'large', [`${prefixClsValue}-rtl`]: direction.value === 'rtl', [`${prefixClsValue}-borderless`]: !bordered, }, @@ -154,8 +173,8 @@ export default defineComponent({ )} affixWrapperClassName={classNames( { - [`${prefixClsValue}-affix-wrapper-sm`]: size.value === 'small', - [`${prefixClsValue}-affix-wrapper-lg`]: size.value === 'large', + [`${prefixClsValue}-affix-wrapper-sm`]: mergedSize.value === 'small', + [`${prefixClsValue}-affix-wrapper-lg`]: mergedSize.value === 'large', [`${prefixClsValue}-affix-wrapper-rtl`]: direction.value === 'rtl', [`${prefixClsValue}-affix-wrapper-borderless`]: !bordered, }, @@ -170,8 +189,8 @@ export default defineComponent({ )} groupClassName={classNames( { - [`${prefixClsValue}-group-wrapper-sm`]: size.value === 'small', - [`${prefixClsValue}-group-wrapper-lg`]: size.value === 'large', + [`${prefixClsValue}-group-wrapper-sm`]: mergedSize.value === 'small', + [`${prefixClsValue}-group-wrapper-lg`]: mergedSize.value === 'large', [`${prefixClsValue}-group-wrapper-rtl`]: direction.value === 'rtl', }, getStatusClassNames(`${prefixClsValue}-group-wrapper`, mergedStatus.value, hasFeedback), diff --git a/components/space/Compact.tsx b/components/space/Compact.tsx index 2b07a7c36..86c750cb2 100644 --- a/components/space/Compact.tsx +++ b/components/space/Compact.tsx @@ -9,6 +9,7 @@ import type { PropType, ExtractPropTypes, Ref } from 'vue'; import PropTypes from '../_util/vue-types'; import { booleanType, tuple } from '../_util/type'; import { isEmpty } from 'lodash-es'; +import { flattenChildren } from '../_util/props-util'; export const spaceCompactItemProps = () => ({ compactSize: String as PropType, @@ -60,7 +61,7 @@ export const NoCompactStyle = defineComponent({ export const spaceCompactProps = () => ({ prefixCls: String, size: { - type: [String, Number, Array] as PropType, + type: String as PropType, }, direction: PropTypes.oneOf(tuple('horizontal', 'vertical')).def('horizontal'), align: PropTypes.oneOf(tuple('start', 'end', 'center', 'baseline')), @@ -98,15 +99,14 @@ const Compact = defineComponent({ }); return () => { + const childNodes = flattenChildren(slots.default?.() || []); // =========================== Render =========================== - if (slots.default?.()?.length === 0) { + if (childNodes.length === 0) { return null; } - const childNodes = slots.default?.() || []; - return wrapSSR( -
+
{childNodes.map((child, i) => { const key = (child && child.key) || `${prefixCls.value}-item-${i}`; const noCompactItemContext = !compactItemContext || isEmpty(compactItemContext); @@ -114,7 +114,7 @@ const Compact = defineComponent({ return ( - - - - - - - - - - - - + :tree-data="treeData" + > Submit
@@ -217,11 +204,41 @@ Compact Mode for form component.