Browse Source

feat: DatePicker support kk:mm format (#42494)

Co-authored-by: fan.hu <fan.hu3@envision-digital.com>
pull/42518/head
cooljser 2 years ago
committed by GitHub
parent
commit
6195610a21
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      components/date-picker/__tests__/DatePicker.test.tsx
  2. 19
      components/date-picker/generatePicker/index.tsx

17
components/date-picker/__tests__/DatePicker.test.tsx

@ -295,4 +295,21 @@ describe('DatePicker', () => {
const { container } = render(<MyDatePicker />);
expect(container.firstChild).toMatchSnapshot();
});
it('kk:mm format', () => {
const { container } = render(
<DatePicker defaultValue={dayjs()} format="kk:mm" showTime open />,
);
expect(container.querySelectorAll('.ant-picker-time-panel-column').length).toBe(2);
expect(
container
.querySelectorAll('.ant-picker-time-panel-column')?.[0]
.querySelectorAll('.ant-picker-time-panel-cell').length,
).toBe(24);
expect(
container
.querySelectorAll('.ant-picker-time-panel-column')?.[1]
.querySelectorAll('.ant-picker-time-panel-cell').length,
).toBe(60);
});
});

19
components/date-picker/generatePicker/index.tsx

@ -1,6 +1,3 @@
import type { GenerateConfig } from 'rc-picker/lib/generate/index';
import type { Locale as RcPickerLocale, PickerMode } from 'rc-picker/lib/interface';
import type { SharedTimeProps } from 'rc-picker/lib/panels/TimePanel';
import type {
PickerBaseProps as RCPickerBaseProps,
PickerDateProps as RCPickerDateProps,
@ -11,9 +8,12 @@ import type {
RangePickerDateProps as RCRangePickerDateProps,
RangePickerTimeProps as RCRangePickerTimeProps,
} from 'rc-picker/lib/RangePicker';
import type { GenerateConfig } from 'rc-picker/lib/generate/index';
import type { PickerMode, Locale as RcPickerLocale } from 'rc-picker/lib/interface';
import type { SharedTimeProps } from 'rc-picker/lib/panels/TimePanel';
import type { InputStatus } from '../../_util/statusUtils';
import type { SizeType } from '../../config-provider/SizeContext';
import type { TimePickerLocale } from '../../time-picker';
import type { InputStatus } from '../../_util/statusUtils';
import PickerButton from '../PickerButton';
import generateRangePicker from './generateRangePicker';
import generateSinglePicker from './generateSinglePicker';
@ -47,10 +47,15 @@ export function getTimeProps<DateType, DisabledTime>(
if (!firstFormat.includes('m') && showMinute === undefined) {
showTimeObj.showMinute = false;
}
if (!firstFormat.includes('H') && !firstFormat.includes('h') && showHour === undefined) {
if (
!firstFormat.includes('H') &&
!firstFormat.includes('h') &&
!firstFormat.includes('K') &&
!firstFormat.includes('k') &&
showHour === undefined
) {
showTimeObj.showHour = false;
}
if ((firstFormat.includes('a') || firstFormat.includes('A')) && use12Hours === undefined) {
showTimeObj.use12Hours = true;
}
@ -70,7 +75,7 @@ export function getTimeProps<DateType, DisabledTime>(
};
}
const DataPickerPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
type DataPickerPlacement = typeof DataPickerPlacements[number];
type DataPickerPlacement = (typeof DataPickerPlacements)[number];
type InjectDefaultProps<Props> = Omit<
Props,

Loading…
Cancel
Save