mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix(date-picker): DatePicker ref typing (#31993)
This commit is contained in:
parent
a7a1a806b8
commit
999660c574
27
components/date-picker/__tests__/type.test.tsx
Normal file
27
components/date-picker/__tests__/type.test.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
import * as React from 'react';
|
||||
import DatePicker from '..';
|
||||
|
||||
describe('DatePicker.typescript', () => {
|
||||
it('DatePicker ref methods', () => {
|
||||
const datePicker = (
|
||||
<DatePicker
|
||||
ref={picker => {
|
||||
picker?.focus();
|
||||
picker?.blur();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
expect(datePicker).toBeTruthy();
|
||||
});
|
||||
it('RangePicker ref methods', () => {
|
||||
const rangePicker = (
|
||||
<DatePicker.RangePicker
|
||||
ref={picker => {
|
||||
picker?.focus();
|
||||
picker?.blur();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
expect(rangePicker).toBeTruthy();
|
||||
});
|
||||
});
|
@ -12,10 +12,11 @@ import SizeContext from '../../config-provider/SizeContext';
|
||||
import LocaleReceiver from '../../locale-provider/LocaleReceiver';
|
||||
import { getRangePlaceholder } from '../util';
|
||||
import { RangePickerProps, PickerLocale, getTimeProps, Components } from '.';
|
||||
import { PickerComponentClass } from './interface';
|
||||
|
||||
export default function generateRangePicker<DateType>(
|
||||
generateConfig: GenerateConfig<DateType>,
|
||||
): React.ComponentClass<RangePickerProps<DateType>> {
|
||||
): PickerComponentClass<RangePickerProps<DateType>> {
|
||||
class RangePicker extends React.Component<RangePickerProps<DateType>> {
|
||||
static contextType = ConfigContext;
|
||||
|
||||
|
@ -20,6 +20,7 @@ import {
|
||||
getTimeProps,
|
||||
Components,
|
||||
} from '.';
|
||||
import { PickerComponentClass } from './interface';
|
||||
|
||||
export default function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
|
||||
type DatePickerProps = PickerProps<DateType>;
|
||||
@ -147,7 +148,7 @@ export default function generatePicker<DateType>(generateConfig: GenerateConfig<
|
||||
Picker.displayName = displayName;
|
||||
}
|
||||
|
||||
return Picker as React.ComponentClass<InnerPickerProps>;
|
||||
return Picker as PickerComponentClass<InnerPickerProps>;
|
||||
}
|
||||
|
||||
const DatePicker = getPicker<DatePickerProps>();
|
||||
|
@ -1,4 +1,3 @@
|
||||
import * as React from 'react';
|
||||
import { GenerateConfig } from 'rc-picker/lib/generate/index';
|
||||
import {
|
||||
PickerBaseProps as RCPickerBaseProps,
|
||||
@ -128,14 +127,8 @@ export type RangePickerProps<DateType> =
|
||||
|
||||
function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
|
||||
// =========================== Picker ===========================
|
||||
const {
|
||||
DatePicker,
|
||||
WeekPicker,
|
||||
MonthPicker,
|
||||
YearPicker,
|
||||
TimePicker,
|
||||
QuarterPicker,
|
||||
} = generateSinglePicker(generateConfig);
|
||||
const { DatePicker, WeekPicker, MonthPicker, YearPicker, TimePicker, QuarterPicker } =
|
||||
generateSinglePicker(generateConfig);
|
||||
|
||||
// ======================== Range Picker ========================
|
||||
const RangePicker = generateRangePicker(generateConfig);
|
||||
@ -145,7 +138,7 @@ function generatePicker<DateType>(generateConfig: GenerateConfig<DateType>) {
|
||||
WeekPicker: typeof WeekPicker;
|
||||
MonthPicker: typeof MonthPicker;
|
||||
YearPicker: typeof YearPicker;
|
||||
RangePicker: React.ComponentClass<RangePickerProps<DateType>>;
|
||||
RangePicker: typeof RangePicker;
|
||||
TimePicker: typeof TimePicker;
|
||||
QuarterPicker: typeof QuarterPicker;
|
||||
};
|
||||
|
11
components/date-picker/generatePicker/interface.tsx
Normal file
11
components/date-picker/generatePicker/interface.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import { ComponentClass } from 'react';
|
||||
|
||||
export interface CommonPickerMethods {
|
||||
focus: () => void;
|
||||
blur: () => void;
|
||||
}
|
||||
|
||||
export interface PickerComponentClass<P = {}, S = unknown> extends ComponentClass<P, S> {
|
||||
new (...args: ConstructorParameters<ComponentClass<P, S>>): InstanceType<ComponentClass<P, S>> &
|
||||
CommonPickerMethods;
|
||||
}
|
Loading…
Reference in New Issue
Block a user