Skip to content

Commit

Permalink
chore: auto merge branchs (ant-design#33945)
Browse files Browse the repository at this point in the history
chore: merge master into feature
  • Loading branch information
github-actions[bot] authored Feb 7, 2022
2 parents e81214a + 1176454 commit 281763f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
34 changes: 34 additions & 0 deletions components/date-picker/__tests__/type.test.tsx
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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
Expand All @@ -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 changes: 18 additions & 0 deletions components/date-picker/generatePicker/interface.ts
Original file line number Diff line number Diff line change
@@ -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>>;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"@types/gtag.js": "^0.0.8",
"@types/jest": "^27.0.0",
"@types/jest-axe": "^3.5.3",
"@types/jest-environment-puppeteer": "^4.4.1",
"@types/jest-environment-puppeteer": "^5.0.0",
"@types/jest-image-snapshot": "^4.1.0",
"@types/lodash": "^4.14.139",
"@types/puppeteer": "^5.4.0",
Expand Down Expand Up @@ -206,7 +206,7 @@
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-compat": "^4.0.0",
"eslint-plugin-import": "^2.21.1",
"eslint-plugin-jest": "^25.0.1",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-markdown": "^2.0.0",
"eslint-plugin-react": "^7.20.6",
Expand Down

0 comments on commit 281763f

Please sign in to comment.