User Interaction
To specify when the Popover should be shown and hidden, set the showEvent and hideEvent properties. These properties can accept several events at once as well as an object.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popover } from 'devextreme-react/popover';
- const renderContent = () => {
- return (
- <p>Popover content</p>
- );
- };
- class App extends React.Component {
- render() {
- return (
- <div>
- <img id="image" src="https://url/to/an/image" />
- <Popover
- target="#image"
- showEvent="dxhoverstart"
- hideEvent="dxhoverend"
- contentRender={renderContent}
- />
- </div>
- );
- }
- }
- export default App;
The Popover can also be hidden when a user clicks outside it. To control this behavior of the Popover, use the hideOnOutsideClick property.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popover } from 'devextreme-react/popover';
- const renderContent = () => {
- return (
- <p>Popover content</p>
- );
- };
- class App extends React.Component {
- render() {
- return (
- <div>
- <img id="image" src="https://url/to/an/image" />
- <Popover
- target="#image"
- showEvent="dxhoverstart"
- hideEvent="dxhoverend"
- contentRender={renderContent}
- hideOnOutsideClick={false}
- />
- </div>
- );
- }
- }
- export default App;
API
To show or hide the Popover programmatically, bind the visible property of Popover to a state property. After that, change the latter property, and the Popover will appear or disappear.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Popover } from 'devextreme-react/popover';
- import { Button } from 'devextreme-react/button';
- const renderContent = () => {
- return (
- <p>Popover content</p>
- );
- }
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isPopoverVisible: false
- };
- this.showPopover = this.showPopover.bind(this);
- this.hidePopover = this.hidePopover.bind(this);
- }
- showPopover() {
- this.setState({
- isPopoverVisible: true
- });
- }
- hidePopover() {
- this.setState({
- isPopoverVisible: false
- });
- }
- render() {
- return (
- <div>
- <img id="image" src="https://url/to/an/image" />
- <Popover
- target="#image"
- visible={this.state.isPopoverVisible}
- contentRender={renderContent}
- onHiding={this.hidePopover}
- />
- <Button
- text="Show the Popover"
- onClick={this.showPopover}
- />
- <Button
- text="Hide the Popover"
- onClick={this.hidePopover}
- />
- </div>
- );
- }
- }
- export default App;
Events
To execute certain commands before or after the Popover 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 { Popover } from 'devextreme-react/popover';
- 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 (
- <Popover ...
- 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.