Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace select dropdownClassName to popupClassName #140

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/demo/Select.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Select


<code src="../examples/Select.tsx" />
19 changes: 19 additions & 0 deletions docs/examples/Select.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Select defaultValue="lucy" style={{ width: 120 }} onChange={handleChange}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="disabled" disabled>
Disabled
</Option>
<Option value="Yiminghe">yiminghe</Option>
</Select>
);
};
38 changes: 38 additions & 0 deletions src/Select.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof Select>[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,
"[antd: Select] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);

return (
<Select {...restProps} popupClassName={popupClassName || dropdownClassName} ref={ref} />
);
},
) as unknown as ((
props: React.PropsWithChildren<SelectProps>,
) => React.ReactElement) & {
displayName: string;
Option: typeof Option;
};

if (process.env.NODE_ENV !== 'production') {
CompatibleSelect.displayName = 'CompatibleSelect';
}

export default CompatibleSelect;
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from 'antd';
export { default as AutoComplete } from './AutoComplete';
export { default as Cascader } from './Cascader';
export { default as Mentions } from './Mentions';
export { default as Select } from './Select';
29 changes: 29 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { Select } from '../src';
import { render } from '@testing-library/react';

describe('Select', () => {
it('dropdownClassName', async () => {
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

const { container } = render(
<Select
open
dropdownClassName="test"
value="1"
>
<Select.Option value="1">1</Select.Option>
<Select.Option value="2">2</Select.Option>
</Select>,
);

expect(errSpy).toHaveBeenCalledWith(
"Warning: [antd: Select] `dropdownClassName` is removed in v5, please use `popupClassName` instead.",
);

// TODO: Remove this when antd release version
// expect(container.querySelector('.test')).toBeTruthy();

errSpy.mockRestore();
});
});