All Components

Popup Overview

The Kendo UI Popup is a React component that positions a piece of content next to a specific anchor component.

Basic Usage

The following example demonstrates the Popup in action.

<style>
  .popup-content {
    padding: 30px;
    color: #787878;
    background-color: #fcf7f8;
    border: 1px solid rgba(0,0,0,.05);
  }
</style>
class AppComponent extends React.Component {
       anchor = null;
       constructor(props) {
           super(props);
           this.state = { show: false };
       }

       componentDidMount() {
           this.setState({show: true});
       }

       render() {
           return (
               <div>
                   <button
                       className="k-button"
                       onClick={this.onClick}
                       ref={(button) => {
                           this.anchor = button;
                       }}
                   >
                       {this.state.show ? 'Hide' : 'Show'}
                   </button>
                   <Popup
                       anchor={this.anchor}
                       show={this.state.show}
                       popupClass={'popup-content'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }

       onClick = () => {
           this.setState({ show: !this.state.show });
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-popup
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { Popup } from '@progress/kendo-react-popup';
    // CommonJS format
    const { Popup } = require('@progress/kendo-react-popup');
  3. You are required to install one of the Kendo UI themes for React to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

The Popup package requires you to install the following peer dependencies in your application:

  • react
  • react-dom

Functionality and Features

Hidden State

To show or hide the Popup, use the show property.

<style>
  .popup-content {
    padding: 30px;
    color: #787878;
    background-color: #fcf7f8;
    border: 1px solid rgba(0,0,0,.05);
  }
</style>
class AppComponent extends React.Component {
       anchor = null;
       constructor(props) {
           super(props);
           this.state = { show: false };
       }

       render() {
           return (
               <div>
                   <button
                       className="k-button"
                       onClick={this.onClick}
                       ref={(button) => {
                           this.anchor = button;
                       }}
                   >
                       {this.state.show ? 'Hide' : 'Show'}
                   </button>
                   <Popup
                       anchor={this.anchor}
                       show={this.state.show}
                       popupClass={'popup-content'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }

       onClick = () => {
           this.setState({ show: !this.state.show });
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Animations

To disable the opening or closing Popup animation, use the animate property.

<style>
  .popup-content {
    padding: 30px;
    color: #787878;
    background-color: #fcf7f8;
    border: 1px solid rgba(0,0,0,.05);
  }
</style>
class AppComponent extends React.Component {
       anchor = null;
       constructor(props) {
           super(props);
           this.state = { show: false };
       }

       render() {
           return (
               <div>
                   <button
                       className="k-button"
                       onClick={this.onClick}
                       ref={(button) => {
                           this.anchor = button;
                       }}
                   >
                       {this.state.show ? 'Hide' : 'Show'}
                   </button>
                   <Popup
                       anchor={this.anchor}
                       show={this.state.show}
                       animate={false}
                       popupClass={'popup-content'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }

       onClick = () => {
           this.setState({ show: !this.state.show });
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Alignment

You can align the Popup to specific:

Aligning to Components

To align the Popup to a specific component, use the anchor property. The Popup opens next to the defined anchor component.

If an anchor is not provided, the Popup will use the offset property value.

<style>
  .popup-content {
    padding: 30px;
    color: #787878;
    background-color: #fcf7f8;
    border: 1px solid rgba(0,0,0,.05);
  }
</style>
class AppComponent extends React.Component {
       anchor = null;
       constructor(props) {
           super(props);
           this.state = { show: false };
       }

       componentDidMount() {
           this.setState({show: true});
       }

       render() {
           return (
               <div>
                   <button
                       className="k-button"
                       onClick={this.onClick}
                       ref={(button) => {
                           this.anchor = button;
                       }}
                   >
                       {this.state.show ? 'Hide' : 'Show'}
                   </button>
                   <Popup
                       anchor={this.anchor}
                       show={this.state.show}
                       popupClass={'popup-content'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }

       onClick = () => {
           this.setState({ show: !this.state.show });
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Aligning to Absolute Points

To align the Popup to a specific absolute point that is relative to the document, use the offset property. The Popup opens next to the point and uses the specified popupAlign configuration.

<style>
  .popup-content {
    padding: 30px;
    color: #787878;
    background-color: #fcf7f8;
    border: 1px solid rgba(0,0,0,.05);
  }
</style>
class AppComponent extends React.Component {
       /* Change left or top value to reposition the popup */
       offset = { left: 150, top: 50 };

       render() {
           return (
               <Popup
                   offset={this.offset}
                   show={true}
                   popupClass={'popup-content'}
               >
                   Popup content.
               </Popup>
           );
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Viewport Boundary Detection

To define the Popup boundary detection behavior, use the collision property. It specifies the behavior of the component when it does not fit in the view port.

By default, the Popup fits horizontally and flips vertically.

<style>
    .popup-content {
        color: #787878;
        background-color: #fcf7f8;
        border: 1px solid rgba(0,0,0,.05);
        padding: 30px;
    }

    .anchor {
        position: absolute;
        top: 150px;
        left: 50px;
    }
</style>
class AppComponent extends React.Component {
       anchor = null;

       constructor(props) {
           super(props);

           this.state = { show: false };
       }

       onClick = () => {
           this.setState({
               show: !this.state.show
           });
       }

       render() {
           return (
               <div>
                   <button
                       className="anchor k-button"
                       onClick={this.onClick}
                       ref={(button) => { this.anchor = button; }}
                   >
                       Toggle
                   </button>
                   <Popup
                       anchor={this.anchor}
                       collision={{
                           horizontal: "fit",
                           vertical: "flip"
                       }}
                       show={this.state.show}
                       popupClass={'popup-content'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }
   }

   ReactDOM.render(
     <AppComponent />,
     document.querySelector('my-app')
   );

Position

Both the anchor and the Popup are treated as rectangular elements and, as a result, each has nine pivot points. You can align every point of the Popup to an anchor point. The component will position itself by aligning its top-right point to the bottom-right point of the anchor.

<style>
     .content {
       padding: 30px;
       color: #ffffff;
       background-color: #999999;
       border: 1px solid rgba(0,0,0,.05);
     }

     .content p {
       margin: 0;
     }

     .anchor {
       display: block;
       width: 120px;
       margin: 100px auto;
     }
   </style>
class AppComponent extends React.Component {
       anchor = null;
       anchorHorizontal = null;
       anchorVertical = null;
       popupHorizontal = null;
       popupVertical = null;

       constructor(props) {
           super(props);

           this.state = {
               anchorAlign: {
                   horizontal: 'left',
                   vertical: 'bottom'
               },
               popupAlign: {
                   horizontal: 'right',
                   vertical: 'top'
               },
               show: false
           };
       }

       onClick = () => {
           this.setState({
               show: !this.state.show
           });
       }

       onConfigChange = () => {
           this.setState({
               anchorAlign: {
                   horizontal: this.anchorHorizontal.value,
                   vertical: this.anchorVertical.value
               },
               popupAlign: {
                   horizontal: this.popupHorizontal.value,
                   vertical: this.popupVertical.value
               }
           });
       }

       render() {
           const { anchorAlign, popupAlign, show } = this.state;

           return (
               <div>
                   <div className="example-config row">
                       <div className="col-sm-4 col-xs-12">
                           <h4>Anchor align point</h4>
                           <p>
                               Horizontal <br />
                               <select
                                   onChange={this.onConfigChange}
                                   ref={(anchorHorizontal) => {
                                       this.anchorHorizontal = anchorHorizontal;
                                   }}
                                   value={anchorAlign.horizontal}
                                   className="k-textbox"
                               >
                                   <option value="left">Left</option>
                                   <option value="center">Center</option>
                                   <option value="right">Right</option>
                               </select>
                           </p>
                           <p>
                               Vertical <br />
                               <select
                                   onChange={this.onConfigChange}
                                   ref={(anchorVertical) => {
                                       this.anchorVertical = anchorVertical;
                                   }}
                                   value={anchorAlign.vertical}
                                   className="k-textbox"
                               >
                                   <option value="top">Top</option>
                                   <option value="middle">Middle</option>
                                   <option value="bottom">Bottom</option>
                               </select>
                           </p>
                       </div>
                       <div className="col-sm-4 col-xs-12">
                           <h4>Popup align point</h4>
                           <p>
                               Horizontal <br />
                               <select
                                   onChange={this.onConfigChange}
                                   ref={(popupHorizontal) => {
                                       this.popupHorizontal = popupHorizontal;
                                   }}
                                   value={popupAlign.horizontal}
                                   className="k-textbox"
                               >
                                   <option value="left">Left</option>
                                   <option value="center">Center</option>
                                   <option value="right">Right</option>
                               </select>
                           </p>
                           <p>
                               Vertical <br />
                               <select
                                   onChange={this.onConfigChange}
                                   ref={(popupVertical) => {
                                       this.popupVertical = popupVertical;
                                   }}
                                   value={popupAlign.vertical}
                                   className="k-textbox"
                               >
                                   <option value="top">Top</option>
                                   <option value="middle">Middle</option>
                                   <option value="bottom">Bottom</option>
                               </select>
                           </p>
                       </div>
                       <div className="col-sm-4 col-xs-12">
                           <h4>Popup action</h4>
                           <br />
                           <button onClick={this.onClick} className="k-button k-primary">{show ? 'Close' : 'Open'}</button>
                       </div>
                   </div>
                   <span
                       ref={(anchor) => {this.anchor = anchor; }}
                       className="anchor content"
                   >
                       ANCHOR
                   </span>
                   <Popup
                       anchor={this.anchor}
                       anchorAlign={anchorAlign}
                       popupAlign={popupAlign}
                       show={show}
                   >
                       <div className="content">
                           <p>Popup content.</p>
                       </div>
                   </Popup>
               </div>
           );
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );

Styling

To style the host element of the Popup, decorate the component element. To style the element which holds the content, use the popupClass property.

<style>
     .wrapper {
         color: #ffffff;
         background-color: #eeeeee;
       }

       .inner-wrapper {
           padding: 20px;
           background-color: #fcfcfc;
       }
   </style>
class AppComponent extends React.Component {
       anchor = null;
       constructor(props) {
           super(props);
           this.state = { show: false };
       }

       render() {
           return (
               <div>
                   <button
                       onClick={this.onClick}
                       ref={(button) => {
                           this.anchor = button;
                       }}
                       className={'k-button'}
                   >
                       {this.state.show ? 'Hide' : 'Show'}
                   </button>
                   <Popup
                       anchor={this.anchor}
                       show={this.state.show}
                       className={'wrapper'}
                       popupClass={'inner-wrapper'}
                   >
                       Popup content.
                   </Popup>
               </div>
           );
       }

       onClick = () => {
           this.setState({ show: !this.state.show });
       }
   }

   ReactDOM.render(
       <AppComponent />,
       document.querySelector('my-app')
   );
In this article