未验证 提交 cefb877a 编写于 作者: 偏右 提交者: GitHub

fix: AutoComplete warning when using placeholder and allowClear (#26765)

close #26760
上级 481fd209
......@@ -69,4 +69,13 @@ describe('AutoComplete', () => {
wrapper.find('input').simulate('change', { target: { value: '1' } });
expect(wrapper.find('.ant-select-item-option').length).toBe(2);
});
it('should not warning when getInputElement is null', () => {
jest.spyOn(console, 'warn').mockImplementation(() => undefined);
mount(<AutoComplete placeholder="input here" allowClear />);
// eslint-disable-next-line no-console
expect(console.warn).not.toBeCalled();
// eslint-disable-next-line no-console
console.warn.mockRestore();
});
});
......@@ -46,7 +46,7 @@ const AutoComplete: React.ForwardRefRenderFunction<Select, AutoCompleteProps> =
React.useImperativeHandle<Select, Select>(ref, () => selectRef.current!);
// ============================= Input =============================
let customizeInput: React.ReactElement;
let customizeInput: React.ReactElement | undefined;
if (
childNodes.length === 1 &&
......@@ -56,7 +56,7 @@ const AutoComplete: React.ForwardRefRenderFunction<Select, AutoCompleteProps> =
[customizeInput] = childNodes;
}
const getInputElement = (): React.ReactElement => customizeInput;
const getInputElement = customizeInput ? (): React.ReactElement => customizeInput! : undefined;
// ============================ Options ============================
let optionChildren: React.ReactNode;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册