mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
parent
ebc0c1fbc5
commit
1176454437
@ -1,5 +1,7 @@
|
||||
import * as React from 'react';
|
||||
import { Moment } from 'moment';
|
||||
import DatePicker from '..';
|
||||
import { DatePickRef, RangePickerRef } from '../generatePicker/interface';
|
||||
|
||||
describe('DatePicker.typescript', () => {
|
||||
it('DatePicker ref methods', () => {
|
||||
@ -13,6 +15,23 @@ describe('DatePicker.typescript', () => {
|
||||
);
|
||||
expect(datePicker).toBeTruthy();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/33417
|
||||
it('DatePicker ref methods with forwardRef', () => {
|
||||
const MyDatePicker = React.forwardRef((props, ref: DatePickRef<Moment>) => (
|
||||
<DatePicker {...props} ref={ref} />
|
||||
));
|
||||
const datePicker = (
|
||||
<MyDatePicker
|
||||
ref={picker => {
|
||||
picker?.focus();
|
||||
picker?.blur();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
expect(datePicker).toBeTruthy();
|
||||
});
|
||||
|
||||
it('RangePicker ref methods', () => {
|
||||
const rangePicker = (
|
||||
<DatePicker.RangePicker
|
||||
@ -24,4 +43,19 @@ describe('DatePicker.typescript', () => {
|
||||
);
|
||||
expect(rangePicker).toBeTruthy();
|
||||
});
|
||||
|
||||
it('RangePicker ref methods with forwardRef', () => {
|
||||
const MyRangePicker = React.forwardRef((props, ref: RangePickerRef<Moment>) => (
|
||||
<DatePicker.RangePicker {...props} ref={ref} />
|
||||
));
|
||||
const datePicker = (
|
||||
<MyRangePicker
|
||||
ref={picker => {
|
||||
picker?.focus();
|
||||
picker?.blur();
|
||||
}}
|
||||
/>
|
||||
);
|
||||
expect(datePicker).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
18
components/date-picker/generatePicker/interface.ts
Normal file
18
components/date-picker/generatePicker/interface.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type { ComponentClass, ForwardedRef, Component } from 'react';
|
||||
import { PickerProps, RangePickerProps } from '.';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export type PickerRef<P> = ForwardedRef<Component<P> & CommonPickerMethods>;
|
||||
|
||||
export type DatePickRef<DateType> = PickerRef<PickerProps<DateType>>;
|
||||
|
||||
export type RangePickerRef<DateType> = PickerRef<RangePickerProps<DateType>>;
|
Loading…
Reference in New Issue
Block a user