I am currently working on integrating an Antd Dropdown Menu with Search functionality. My goal is to have the dropdown close when clicking outside of it. However, in my code, the dropdown toggles between opening and closing even if I click on the Search box (which is not the desired behavior). I want the dropdown menu to only be open if there is text input in the search box, and to close if there is no text or if clicked outside. It should not continuously open and close when I click on the search box itself. Is there a specific property that I might be overlooking? Here is a snippet of the code:
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Menu, Dropdown, Input } from "antd";
class OverlayVisible extends React.Component {
state = {
visible: false
};
handleMenuClick = (e) => {
if (e.key === "3") {
this.setState({ visible: false });
}
};
handleVisibleChange = (flag) => {
this.setState({ visible: flag });
};
render() {
const menu = (
<Menu onClick={this.handleMenuClick}>
<Menu.Item key="1">Clicking me will not close the menu.</Menu.Item>
</Menu>
);
return (
<Dropdown
onClick={() => {
this.setState({ visible: true });
}}
overlay={menu}
onVisibleChange={this.handleVisibleChange}
visible={this.state.visible}
trigger={["click"]}
>
<Input.Search
onInput={() => {
this.setState({ visible: true });
}}
></Input.Search>
</Dropdown>
);
}
}
ReactDOM.render(<OverlayVisible />, document.getElementById("container"));
CodeSandbox Link: https://codesandbox.io/s/aman-521r2?file=/index.js:0-1236