mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 11:32:52 +08:00
fix: Input.Search enterButton don't trigger click event (#32999)
close #32993
This commit is contained in:
parent
3886ad6462
commit
34d23c8850
@ -68,10 +68,7 @@ const Search = React.forwardRef<Input, SearchProps>((props, ref) => {
|
|||||||
const prefixCls = getPrefixCls('input-search', customizePrefixCls);
|
const prefixCls = getPrefixCls('input-search', customizePrefixCls);
|
||||||
const inputPrefixCls = getPrefixCls('input', customizeInputPrefixCls);
|
const inputPrefixCls = getPrefixCls('input', customizeInputPrefixCls);
|
||||||
|
|
||||||
const searchIcon =
|
const searchIcon = typeof enterButton === 'boolean' ? <SearchOutlined /> : null;
|
||||||
typeof enterButton === 'boolean' ? (
|
|
||||||
<SearchOutlined />
|
|
||||||
) : null;
|
|
||||||
const btnClassName = `${prefixCls}-button`;
|
const btnClassName = `${prefixCls}-button`;
|
||||||
|
|
||||||
let button: React.ReactNode;
|
let button: React.ReactNode;
|
||||||
@ -81,7 +78,10 @@ const Search = React.forwardRef<Input, SearchProps>((props, ref) => {
|
|||||||
if (isAntdButton || enterButtonAsElement.type === 'button') {
|
if (isAntdButton || enterButtonAsElement.type === 'button') {
|
||||||
button = cloneElement(enterButtonAsElement, {
|
button = cloneElement(enterButtonAsElement, {
|
||||||
onMouseDown,
|
onMouseDown,
|
||||||
onClick: onSearch,
|
onClick: (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
enterButtonAsElement?.props?.onClick?.(e);
|
||||||
|
onSearch(e);
|
||||||
|
},
|
||||||
key: 'enterButton',
|
key: 'enterButton',
|
||||||
...(isAntdButton
|
...(isAntdButton
|
||||||
? {
|
? {
|
||||||
|
@ -110,10 +110,15 @@ describe('Input.Search', () => {
|
|||||||
|
|
||||||
it('should trigger onSearch when click search button of native', () => {
|
it('should trigger onSearch when click search button of native', () => {
|
||||||
const onSearch = jest.fn();
|
const onSearch = jest.fn();
|
||||||
|
const onButtonClick = jest.fn();
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<Search
|
<Search
|
||||||
defaultValue="search text"
|
defaultValue="search text"
|
||||||
enterButton={<button type="button">antd button</button>}
|
enterButton={
|
||||||
|
<button type="button" onClick={onButtonClick}>
|
||||||
|
antd button
|
||||||
|
</button>
|
||||||
|
}
|
||||||
onSearch={onSearch}
|
onSearch={onSearch}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
@ -126,6 +131,7 @@ describe('Input.Search', () => {
|
|||||||
preventDefault: expect.any(Function),
|
preventDefault: expect.any(Function),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
expect(onButtonClick).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should trigger onSearch when press enter', () => {
|
it('should trigger onSearch when press enter', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user