Popconfirm MDB Pro component

Popconfirm - Bootstrap 5 & Material Design 2.0 components

Popconfirm basically is a simple alert with confirmation buttons.

Note: Read the API tab to find all available options and advanced customization


Basic example

Basic example of popconfirm usage


          <button
            type="button"
            class="btn btn-primary popconfirm-toggle"
            data-message="This is example"
          >
            Default
          </button>
        

Display mode

You need to apply .popconfirm-toggle class to button.

You can choose between modal and inline to modify display mode.

Modal mode is rendered at the center of the screen and is static, you can't change its position but all other attributes can be applied


          <button
            type="button"
            data-popconfirm-mode="modal"
            class="btn btn-primary popconfirm-toggle"
          >
            Modal
          </button>
          <button
            type="button"
            data-popconfirm-mode="inline"
            class="btn btn-primary popconfirm-toggle"
          >
            Inline
          </button>
        

Icon example

To apply icon to message you need to give class in data-popconfirm-icon like on example data-popconfirm-icon="fa fa-comment"


          <button
            type="button"
            data-popconfirm-mode="inline"
            data-popconfirm-icon="fa fa-comment"
            data-message="Icon example"
            class="btn btn-primary popconfirm-toggle mr-1"
          >
            Icon
          </button>
        

Inline positions

You can choose between different positions

Available positions: top left; top; top right; right top; right; right bottom; bottom right; bottom; bottom left; left bottom; left; left top;


          <button
            type="button"
            data-popconfirm-mode="inline"
            data-position="top left"
            class="btn btn-primary popconfirm-toggle"
          >
            Top left
          </button>
          <button
            type="button"
            data-popconfirm-mode="inline"
            data-position="bottom"
            class="btn btn-primary popconfirm-toggle"
          >
            Bottom
          </button>
          <button
            type="button"
            data-popconfirm-mode="inline"
            data-position="right top"
            class="btn btn-primary popconfirm-toggle"
          >
            Right top
          </button>
        

Popconfirm - API


Usage

Via class

You need to apply .popconfirm-toggle class to button.


        <button type="button" class="btn btn-primary popconfirm-toggle">
          Default
        </button>
      

Via JavaScript

You need to apply .popconfirm-toggle class to button.


        const popconfirmElements = document.querySelectorAll('.popconfirm-toggle');
        popconfirmElements.forEach((currentElement) => { 
          new mdb.Popconfirm(currentElement)
        });
      

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-mode="", for two word options name use hyphen "-" as data-ok-text=""

Name Type Default Description
cancelLabel String 'Cancel' Text rendered under cancel button for screen readers
cancelText String 'Cancel' Text of cancel button, if empty string - button doesn't render
confirmLabel String 'Confirm' Text rendered under confirm button for screen readers
popconfirmIcon String '' Icon rendered at start of message
message String 'Are you sure?' Message rendered in popconfirm
popconfirmMode String 'inline' Mode of display -> 'inline' or 'modal'
okClass String 'btn-primary' Class of confirm button
okText String 'OK' Text of confirm button
position String '' Specify position to display popover

Methods

Method Description
getInstance Static method which allows you to get the popconfirm instance associated with a DOM element
dispose Destroys an element's popconfirm

          const popconfirmElements = document.querySelectorAll('.popconfirm-toggle');
          popconfirmElements.forEach((currentElement) => { 
            const button = new mdb.Popconfirm(currentElement);
            const buttonInstance = button.getInstance();
          })
        

Events

Name Description
cancel.mdb.popconfirm This event fires immediately when the popconfirm is closed without confirm button click.
confirm.mdb.popconfirm This event fires immediately when the popconfirm is closed using confirm button.

          document.addEventListener('cancel.mdb.popconfirm', () => { //Your code goes here });
        

Import

Popconfirm also works with module bundlers. Use the following code to import this component:


          import Popconfirm from './pro/popconfirm';