Browse Source

fix: prevent Search component to throw passing null as enterButton (#27591)

pull/27600/head
Davide Bianchi 4 years ago
committed by GitHub
parent
commit
72dbcfcfde
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/input/Search.tsx
  2. 6
      components/input/__tests__/Search.test.js

2
components/input/Search.tsx

@ -56,7 +56,7 @@ const Search = React.forwardRef<Input, SearchProps>((props, ref) => {
const btnClassName = `${prefixCls}-button`;
let button: React.ReactNode;
const enterButtonAsElement = enterButton as React.ReactElement;
const enterButtonAsElement = (enterButton || {}) as React.ReactElement;
const isAntdButton =
enterButtonAsElement.type &&
(enterButtonAsElement.type as typeof Button).__ANT_BUTTON === true;

6
components/input/__tests__/Search.test.js

@ -21,6 +21,12 @@ describe('Input.Search', () => {
expect(wrapper.render()).toMatchSnapshot();
});
it('should support enterButton null', () => {
expect(() => {
mount(<Search enterButton={null} />);
}).not.toThrow();
});
it('should support ReactNode suffix without error', () => {
const wrapper = mount(<Search suffix={<div>ok</div>} />);
expect(wrapper.render()).toMatchSnapshot();

Loading…
Cancel
Save