How can I help you?
Close popup in React Drop down list component
21 Feb 20263 minutes to read
Use the hidePopup method in DropDownList to close the popup when the window scroll event is triggered.
The following example demonstrates how to close the popup on scroll:
import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component {
dropDownListObject;
// define the data with category
sportsData = [
'Badminton', 'Cricket', 'Football', 'Golf', 'Tennis'
];
constructor(props) {
super(props);
window.addEventListener('scroll', this.handleScroll.bind(this));
}
// on scroll event
handleScroll() {
this.dropDownListObject.hidePopup();
}
render() {
return (
// specifies the tag for render the DropDownList component
<DropDownListComponent id="ddlelement" ref={(scope) => { this.dropDownListObject = scope; }} dataSource={this.sportsData} placeholder="Select a game"/>);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));import { DropDownListComponent } from '@syncfusion/ej2-react-dropdowns';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
export default class App extends React.Component<{}, {}> {
private dropDownListObject: any;
// define the data with category
private sportsData: { [key: string]: Object }[] = [
'Badminton', 'Cricket', 'Football', 'Golf', 'Tennis'];
constructor(props: any){
super(props);
window.addEventListener('scroll', this.handleScroll.bind(this));
}
// on scroll event
public handleScroll() {
this.dropDownListObject.hidePopup();
}
public render() {
return (
// specifies the tag for render the DropDownList component
<DropDownListComponent id="ddlelement" ref={(scope) => { this.dropDownListObject = scope; }} dataSource={this.sportsData} placeholder="Select a game" />
);
}
}
ReactDOM.render(<App />, document.getElementById('sample'));