API
To show or hide the Popup programmatically, bind the visible property of Popup to a state property. After that, change the latter property, and the Popup will appear or disappear.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popup } from 'devextreme-react/popup';
- import { Button } from 'devextreme-react/button';
- const renderContent = () => {
- return (
- <p>Popup content</p>
- );
- };
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isPopupVisible: false
- };
- this.showPopup = this.showPopup.bind(this);
- this.hidePopup = this.hidePopup.bind(this);
- }
- showPopup() {
- this.setState({
- isPopupVisible: true
- });
- }
- hidePopup() {
- this.setState({
- isPopupVisible: false
- });
- }
- render() {
- return (
- <div>
- <Popup
- title="Popup Title"
- visible={this.state.isPopupVisible}
- contentRender={renderContent}
- onHiding={this.hidePopup}
- />
- <Button
- text="Show the Popup"
- onClick={this.showPopup}
- />
- <Button
- text="Hide the Popup"
- onClick={this.hidePopup}
- />
- </div>
- );
- }
- }
- export default App;
User Interaction
Enable the showCloseButton property to allow a user to hide the Popup component by clicking the Close button.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popup } from 'devextreme-react/popup';
- class App extends React.Component {
- return (
- <Popup
- showTitle={true}
- showCloseButton={true}
- />
- );
- }
- export default App;
The Popup can also be hidden when a user clicks outside of it. To control this Popup behavior, use the hideOnOutsideClick property.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popup } from 'devextreme-react/popup';
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isPopupVisible: true
- };
- this.onHiding = this.onHiding.bind(this);
- }
- onHiding() {
- this.setState({
- isPopupVisible: false
- });
- }
- render() {
- return (
- <Popup
- visible={this.state.isPopupVisible}
- hideOnOutsideClick={true}
- title="Popup Title"
- />
- );
- }
- }
- export default App;
You can also implement a custom Close button inside the Popup. Refer to the following demo for more information:
Events
To execute certain commands before or after the Popup was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popup } from 'devextreme-react/popup';
- class App extends React.Component {
- onShowing(e) {
- // Handler of the 'showing' event
- }
- onShown(e) {
- // Handler of the 'shown' event
- }
- onHiding(e) {
- // Handler of the 'hiding' event
- }
- onHidden(e) {
- // Handler of the 'hidden' event
- }
- render() {
- return (
- <Popup ...
- onShowing={this.onShowing}
- onShown={this.onShown}
- onHiding={this.onHiding}
- onHidden={this.onHidden}
- />
- );
- }
- }
- export default App;
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.