Browse Source

chore: auto merge branchs (#33945)

chore: merge master into feature
pull/33954/head
github-actions[bot] 3 years ago
committed by GitHub
parent
commit
281763f345
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      components/date-picker/__tests__/type.test.tsx
  2. 18
      components/date-picker/generatePicker/interface.ts
  3. 4
      package.json

34
components/date-picker/__tests__/type.test.tsx

@ -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

@ -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
package.json

@ -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",
@ -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",

Loading…
Cancel
Save