fix: ok button of the DatePicker becomes compacted when used with Space.Compact (#46769)

* fix: ok button of the DatePicker becomes compacted when used with Space.Compact

* fix: break CSS selector

* fix: break the compact context on the panel

* chore: update test
This commit is contained in:
Fatpandac 2024-01-16 14:02:31 +08:00 committed by GitHub
parent 14af2a77ae
commit 77b351f68f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 112 deletions

View File

@ -1,6 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import type { ButtonProps } from '../button';
import Button from '../button'; import Button from '../button';
import type { ButtonProps } from '../button';
export default function PickerButton(props: ButtonProps) { export default function PickerButton(props: ButtonProps) {
return <Button size="small" type="primary" {...props} />; return <Button size="small" type="primary" {...props} />;

View File

@ -16,7 +16,7 @@ import DisabledContext from '../../config-provider/DisabledContext';
import useSize from '../../config-provider/hooks/useSize'; import useSize from '../../config-provider/hooks/useSize';
import { FormItemInputContext } from '../../form/context'; import { FormItemInputContext } from '../../form/context';
import { useLocale } from '../../locale'; import { useLocale } from '../../locale';
import { useCompactItemContext } from '../../space/Compact'; import { NoCompactStyle, useCompactItemContext } from '../../space/Compact';
import enUS from '../locale/en_US'; import enUS from '../locale/en_US';
import useStyle from '../style'; import useStyle from '../style';
import { import {
@ -124,6 +124,7 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
const [zIndex] = useZIndex('DatePicker', props.popupStyle?.zIndex as number); const [zIndex] = useZIndex('DatePicker', props.popupStyle?.zIndex as number);
return wrapCSSVar( return wrapCSSVar(
<NoCompactStyle>
<RCRangePicker<DateType> <RCRangePicker<DateType>
separator={ separator={
<span aria-label="to" className={`${prefixCls}-separator`}> <span aria-label="to" className={`${prefixCls}-separator`}>
@ -147,7 +148,11 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
[`${prefixCls}-${mergedSize}`]: mergedSize, [`${prefixCls}-${mergedSize}`]: mergedSize,
[`${prefixCls}-${variant}`]: enableVariantCls, [`${prefixCls}-${variant}`]: enableVariantCls,
}, },
getStatusClassNames(prefixCls, getMergedStatus(contextStatus, customStatus), hasFeedback), getStatusClassNames(
prefixCls,
getMergedStatus(contextStatus, customStatus),
hasFeedback,
),
hashId, hashId,
compactItemClassnames, compactItemClassnames,
className, className,
@ -175,7 +180,8 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
zIndex, zIndex,
}} }}
allowClear={mergeAllowClear(allowClear, clearIcon, <CloseCircleFilled />)} allowClear={mergeAllowClear(allowClear, clearIcon, <CloseCircleFilled />)}
/>, />
</NoCompactStyle>,
); );
}); });

View File

@ -17,7 +17,7 @@ import DisabledContext from '../../config-provider/DisabledContext';
import useSize from '../../config-provider/hooks/useSize'; import useSize from '../../config-provider/hooks/useSize';
import { FormItemInputContext } from '../../form/context'; import { FormItemInputContext } from '../../form/context';
import { useLocale } from '../../locale'; import { useLocale } from '../../locale';
import { useCompactItemContext } from '../../space/Compact'; import { NoCompactStyle, useCompactItemContext } from '../../space/Compact';
import enUS from '../locale/en_US'; import enUS from '../locale/en_US';
import useStyle from '../style'; import useStyle from '../style';
import { import {
@ -151,6 +151,7 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
const [zIndex] = useZIndex('DatePicker', props.popupStyle?.zIndex as number); const [zIndex] = useZIndex('DatePicker', props.popupStyle?.zIndex as number);
return wrapCSSVar( return wrapCSSVar(
<NoCompactStyle>
<RCPicker<DateType> <RCPicker<DateType>
ref={innerRef} ref={innerRef}
placeholder={getPlaceholder(locale, mergedPicker, placeholder)} placeholder={getPlaceholder(locale, mergedPicker, placeholder)}
@ -202,7 +203,8 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
zIndex, zIndex,
}} }}
allowClear={mergeAllowClear(allowClear, clearIcon, <CloseCircleFilled />)} allowClear={mergeAllowClear(allowClear, clearIcon, <CloseCircleFilled />)}
/>, />
</NoCompactStyle>,
); );
}, },
); );

View File

@ -6407,7 +6407,7 @@ exports[`renders components/space/demo/compact.tsx extend context correctly 1`]
class="ant-picker-ok" class="ant-picker-ok"
> >
<button <button
class="ant-btn ant-btn-primary ant-btn-sm ant-btn-compact-item ant-btn-compact-first-item" class="ant-btn ant-btn-primary ant-btn-sm"
disabled="" disabled=""
type="button" type="button"
> >
@ -8020,7 +8020,7 @@ exports[`renders components/space/demo/compact.tsx extend context correctly 1`]
class="ant-picker-ok" class="ant-picker-ok"
> >
<button <button
class="ant-btn ant-btn-primary ant-btn-sm ant-btn-compact-item ant-btn-compact-first-item" class="ant-btn ant-btn-primary ant-btn-sm"
disabled="" disabled=""
type="button" type="button"
> >
@ -15185,7 +15185,7 @@ Array [
class="ant-picker-ok" class="ant-picker-ok"
> >
<button <button
class="ant-btn ant-btn-primary ant-btn-sm ant-btn-compact-item ant-btn-compact-first-item" class="ant-btn ant-btn-primary ant-btn-sm"
disabled="" disabled=""
type="button" type="button"
> >

View File

@ -13,4 +13,4 @@ export type CompoundedStatistic = typeof Statistic & CompoundedComponent;
(Statistic as CompoundedStatistic).Countdown = Countdown; (Statistic as CompoundedStatistic).Countdown = Countdown;
export default (Statistic as CompoundedStatistic); export default Statistic as CompoundedStatistic;

View File

@ -627,4 +627,4 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
); );
}; };
export default (React.forwardRef(InternalTable) as RefInternalTable); export default React.forwardRef(InternalTable) as RefInternalTable;