From bca55227d31dc237aa6c1f995088cdec4bb35c1f Mon Sep 17 00:00:00 2001 From: wangning Date: Thu, 18 Aug 2022 22:59:28 +0800 Subject: [PATCH 1/2] feat: replace select dropdownClassName to popupClassName --- docs/demo/Select.md | 4 ++++ docs/examples/Select.tsx | 19 +++++++++++++++++++ src/Select.tsx | 38 ++++++++++++++++++++++++++++++++++++++ src/index.tsx | 1 + tests/Select.test.tsx | 29 +++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 docs/demo/Select.md create mode 100644 docs/examples/Select.tsx create mode 100644 src/Select.tsx create mode 100644 tests/Select.test.tsx diff --git a/docs/demo/Select.md b/docs/demo/Select.md new file mode 100644 index 0000000..15f9017 --- /dev/null +++ b/docs/demo/Select.md @@ -0,0 +1,4 @@ +## Select + + + diff --git a/docs/examples/Select.tsx b/docs/examples/Select.tsx new file mode 100644 index 0000000..ab65962 --- /dev/null +++ b/docs/examples/Select.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Select } from '../../src'; +const { Option } = Select; +console.log('Select',Select) +export default () => { + const handleChange = (value: string) => { + console.log(`selected ${value}`); + }; + return ( + + ); +}; diff --git a/src/Select.tsx b/src/Select.tsx new file mode 100644 index 0000000..0572980 --- /dev/null +++ b/src/Select.tsx @@ -0,0 +1,38 @@ +import * as React from 'react'; +import { Select } from 'antd'; +import warning from 'rc-util/lib/warning'; +import type { Option } from 'rc-select'; +type SelectProps = Parameters[0]; +type SelectRef = SelectProps['ref']; + +type CompatibleSelectProps = SelectProps& { + /** @deprecated Please use `popupClassName` instead. */ + dropdownClassName?: string; +}; + +const CompatibleSelect = React.forwardRef( + ( + { dropdownClassName, popupClassName, ...restProps }: CompatibleSelectProps, + ref: SelectRef, + ) => { + warning( + !dropdownClassName, + `[Compatible: Select] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.`, + ); + + return ( + + 1 + 2 + , + ); + + expect(errSpy).toHaveBeenCalledWith( + "Warning: [Compatible: Select] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.", + ); + + // TODO: Remove this when antd release version + // expect(container.querySelector('.test')).toBeTruthy(); + + errSpy.mockRestore(); + }); +}); From 9db19c31560496647f44d8510860fa05bd7bf4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91=E9=9B=A8?= Date: Fri, 19 Aug 2022 15:53:39 +0800 Subject: [PATCH 2/2] feat: edit warning info --- src/Select.tsx | 2 +- tests/Select.test.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Select.tsx b/src/Select.tsx index 0572980..2301840 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -17,7 +17,7 @@ const CompatibleSelect = React.forwardRef( ) => { warning( !dropdownClassName, - `[Compatible: Select] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.`, + "[antd: Select] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", ); return ( diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 1c9053c..8f24c12 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -18,7 +18,7 @@ describe('Select', () => { ); expect(errSpy).toHaveBeenCalledWith( - "Warning: [Compatible: Select] 'dropdownClassName' is deprecated. Please use 'popupClassName' instead.", + "Warning: [antd: Select] `dropdownClassName` is removed in v5, please use `popupClassName` instead.", ); // TODO: Remove this when antd release version