Popup

A floating Popup widget, which can contain child widgets or plain html. Serves as the base class for Menu / Tooltip.

Popup
//<code-header>
fiddle.title = 'Popup';
//</code-header>
// button that display a popup containing html
new Button({
    appendTo : targetElement,
    text     : 'Html popup',
    onClick({ source }) {
        const popup = new Popup({
            owner       : source,
            header      : 'A simple text Popup',
            autoShow    : false,
            centered    : true,
            draggable   : true,
            closeAction : 'destroy',
            closable    : true,
            modal       : true,
            width       : '30em',
            rootElement : targetElement, // Only for docs, not needed in real code
            bbar        : {
                items : {
                    close : {
                        text     : 'Close',
                        minWidth : 100,
                        onAction : 'up.close'
                    }
                }
            },
            html : `<h3 style="margin-top:0.5em">Bacon ipsum dolor </h3>
                    <p style="line-height:1.5em">amet flank ribeye ham hock, 
                     rump alcatra pork belly pancetta leberkas bacon shoulder 
                    meatloaf ball tip pig. Tongue jerky meatloaf pancetta 
                    pork sirloin. Hamburger corned beef ball tip cupim 
                    sirloin frankfurter tri-tip. </p>`
        });
        popup.show();
    }
});

// button that display a modal popup
new Button({
    appendTo  : targetElement,
    rendition : 'filled',
    text      : 'Modal popup',
    style     : 'margin-right: .5em',
    onClick({ source }) {
        const popup = new Popup({
            owner       : source,
            header      : 'A simple modal Popup',
            autoShow    : false,
            closeAction : 'destroy',
            modal       : true,
            closable    : true,
            maximizable : true,
            width       : '30em',
            bbar        : {
                items : {
                    close : {
                        text     : 'Close',
                        onAction : 'up.close'
                    }
                }
            },
            html : `<h3 style="margin-top:0.5em">Bacon ipsum dolor </h3>
                    <p style="line-height:1.5em">amet flank ribeye ham hock, 
                     rump alcatra pork belly pancetta leberkas bacon shoulder 
                    meatloaf ball tip pig. Tongue jerky meatloaf pancetta 
                    pork sirloin. Hamburger corned beef ball tip cupim 
                    sirloin frankfurter tri-tip.</p>`
        });
        popup.show();
    }
});

// button that displays a popup containing widgets
new Button({
    appendTo : targetElement,
    text     : 'Widget popup',
    ripple   : false,
    onClick({ source }) {
        const popup = new Popup({
            owner         : source,
            header        : 'Anchored containing Widgets',
            autoShow      : false,
            closable      : true,
            closeAction   : 'destroy',
            width         : '27em',
            minHeight     : '18em',
            resizable     : true,
            rootElement   : targetElement, // Only for docs, not needed in real code
            labelPosition : 'align-before',
            align         : {
                align  : 't-b',
                anchor : true
            },
            bbar : {
                items : {
                    cancel : {
                        text     : 'Cancel',
                        minWidth : 100,
                        onAction : 'up.close'
                    },
                    close : {
                        text      : 'OK',
                        minWidth  : 100,
                        rendition : 'filled',
                        onAction  : () => {
                            Toast.show('Hello ' + popup.widgetMap.nameField.value);
                            popup.close();
                        }
                    }
                }
            },
            items : {
                // a text field
                nameField : {
                    type  : 'text',
                    label : 'Name',
                    value : 'John Doe'
                },
                numberField : {
                    type  : 'number',
                    label : 'Age',
                    value : 25
                }
            }
        });
        popup.showBy(source.element);
    }
});

When it contains focus, the Escape key closes the picker. When it hides, focus is reverted to the element from which it entered the Popup, or, if that is no longer focusable, a close relative of that element.

const popup = new Popup({
  forElement : document.querySelector('button'),
  items      : {
    text : { type : 'text', placeholder: 'Text' },
    button : { type: 'button', text: 'Okay', style: 'width: 100%', color: 'b-orange'}
  }
});

Dragging & Resizing

Popups can be resized and dragged around the screen. To enable resizing, set the resizable config to true or an object with specific options. To enable dragging, set the draggable config to true.

For example:

const popup = new Popup({
   draggable : true,
   resizable : {
      handles : {
         top  : false,
         minWidth : 100
      }
   }
});

Configs

120

Common

listenersEvents

Float & align

draggable: Boolean | Object= true

Set to false to prevent dragging the popup element.

ParameterTypeDescription
handleSelectorString

CSS selector used to determine if a drag operation can be started from a mouse-downed element inside the popup

maximized: Boolean= falseAlso a property

Set to true to make this widget take all available space in the visible viewport.

alignWidget
anchorWidget
centeredWidget
floatingWidget
xWidget
yWidget

Other

autoClose: Boolean= true

By default, a Popup is transient, and will close when the user clicks or taps outside its owned widgets and when focus moves outside its owned widgets.

Note: Modal popups won't close when focus moves outside even if autoClose is true.

Configure as false to make a Popup non-transient.

autoShow: Boolean= true

Auto show flag for Popup. If truthy then Popup is shown automatically upon hover.

closable: Boolean= false

Show a tool in the header to close this Popup. The tool is available in the tools object under the name close. It uses the CSS class b-popup-close to apply a default close icon. This may be customized with your own CSS rules.

closeAction: hide | destroy= hide

The action to take when calling the close method. By default, the popup is hidden.

This may be set to 'destroy' to destroy the popup upon close.

closeOnEscape: Boolean= true

Close popup when ESC key is pressed.

focusOnToFront: Boolean= true

By default a Popup is focused when it is shown. Configure this as false to prevent automatic focus on show.

forElement: HTMLElement

DOM element to attach popup.

maximizable: Boolean= false

Show a tool in the header to maximize this popup

modal: Boolean | Object= false

Optionally show an opaque mask below this Popup when shown. Configure this as true to show the mask.

When a Popup is modal, it defaults to being centered. Also, it won't close when focus moves outside even if autoClose is true.

The default action is to focus the popup.

Usage:

new Popup({
    title  : 'I am modal',
    modal  : {
        closeOnMaskTap : true
    },
    height : 100,
    width  : 200
});
ParameterTypeDescription
closeOnMaskTapBoolean

Specify as true to close when mask is tapped.

transparentBoolean

Specify as true to use a transparent mask.

showOnClick: Boolean | Number= false

Show popup when user clicks the element that it is anchored to. Cannot be combined with showOnHover. Can also be provided as the button number (0: main button, 2: right button).

trapFocus: Boolean= true

By default, tabbing within a Popup is circular - that is it does not exit. Configure this as false to allow tabbing out of the Popup.

columnWidget
defaultFocusContainer
drawerPanel
labelPositionContainer
renditionContainer
resizableResizable
rtlRTL
spanWidget

Accessibility

ariaLabelWidget
keyMapKeyMap

Content

bbarPanel
defaultsContainer
footerPanel
headerPanel
itemsContainer
lazyItemsContainer
namedItemsContainer
stripsPanel
tbarPanel
textContentContainer
toolsPanel

CSS

bodyClsPanel
borderContainer
clsWidget
colorWidget
htmlClsWidget
itemClsContainer
styleWidget
uiPanel

DOM

adoptWidget
appendToWidget
contentWidget
datasetWidget
htmlWidget
idWidget
tagWidget

Layout

alignSelfWidget
dockWidget
flexWidget
heightWidget
hiddenWidget
hideWhenEmptyContainer
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
textAlignWidget
weightWidget
widthWidget

misc

tabBarItemsContainer

Misc

dataFieldWidget
disabledWidget
iconPanel
localeClassLocalizable
localizableLocalizable
maskedWidget
ownerWidget
readOnlyWidget
refWidget
rippleWidget
tabWidget
titlePanel
tooltipWidget

Record

recordContainer

Scrolling

State

stateIdState

Properties

97

Class hierarchy

isPopup: Boolean= truereadonly
Identifies an object as an instance of Popup class, or subclass thereof.
isPopup: Boolean= truereadonlystatic
Identifies an object as an instance of Popup class, or subclass thereof.
isContainerContainer
isDelayableDelayable
isEventsEvents
isKeyMapKeyMap
isLocalizableLocalizable
isPanelPanel
isResizableResizable
isStateState
isToolableToolable
isWidgetWidget

Float & align

Set to true to make this widget take all available space in the visible viewport.

xWidget
yWidget

Accessibility

keyMapKeyMap

Content

bbarPanel
tbarPanel

CSS

clsWidget

DOM

appendToWidget
contentWidget
datasetWidget
elementWidget
htmlWidget
idWidget
styleWidget

Layout

alignSelfWidget
flexWidget
heightWidget
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
widthWidget

Lifecycle

configBase

Misc

cellInfoWidget
disabledWidget
localeHelperLocalizable
localeManagerLocalizable
readOnlyWidget
refWidget
tabWidget
titlePanel
tooltipWidget

Other

$namestaticWidget
columnWidget
firstItemContainer
hasChangesContainer
isValidContainer
itemsContainer
labelPositionContainer
lastItemContainer
renditionContainer
resizableResizable
rtlRTL
spanWidget
toolsPanel
typestaticWidget
valuesContainer

Record

recordContainer

State

stateState

Visibility

hiddenWidget
isVisibleWidget

Widget hierarchy

ownerWidget
parentWidget
widgetMapContainer

Functions

75

Other

Performs the configured closeAction upon this popup. By default, the popup hides. The closeAction may be configured as 'destroy'.

addContainer
composeWidget
createOnFrameDelayable
disableWidget
enableWidget
focusWidget
getAtContainer
getWidgetByIdContainer
insertContainer
LstaticLocalizable
maskWidget
onEvents
recomposeWidget
relayAllEvents
removeContainer
removeAllContainer
resetValuesContainer
setValuesContainer
triggerEvents
unEvents
unmaskWidget

Configuration

applyDefaultsstaticBase

Events

Float & align

alignToWidget
setXYWidget
showByWidget
toFrontWidget

Lifecycle

createstaticWidget
destroystaticBase
initClassstaticWidget

Misc

attachTooltipstaticWidget
fromElementstaticWidget
fromSelectorstaticWidget
getByIdstaticWidget
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

State

Visibility

hideWidget
showWidget

Widget hierarchy

closestWidget
containsWidget
ownsWidget
queryWidget
queryAllWidget
upWidget

Events

22

Fired when the close method is called and the popup is not hidden. May be vetoed by returning false from a handler.

// Adding a listener using the "on" method
popup.on('beforeClose', ({ source }) => {

});
ParameterTypeDescription
sourcePopup

This Popup

catchAllEvents
destroyEvents
expandPanel
focusInWidget
focusOutWidget
hideWidget
paintWidget
readOnlyWidget
recomposeWidget
resizeWidget
showWidget

Event handlers

22

Called when the close method is called and the popup is not hidden. May be vetoed by returning false from a handler.

new Popup({
    onBeforeClose({ source }) {

    }
});
ParameterTypeDescription
sourcePopup

This Popup

onDestroyEvents
onFocusInWidget
onHideWidget
onPaintWidget
onResizeWidget
onShowWidget

Typedefs

7

CSS variables

60
NameDescription
--b-popup-border-radiusPopup border-radius
--b-popup-text-popup-widthPopup width for text popups
--b-popup-close-icon-contentContent for the close icon pseudo element (font icon)
--b-popup-maximize-icon-contentContent for the close icon pseudo element (font icon)
--b-popup-paddingPopup padding
--b-popup-backgroundPopup background-color
--b-modal-mask-backgroundPopup mask background-color (for modal popups)
--b-popup-borderPopup border

Inherited