Popup
A floating Popup widget, which can contain child widgets or plain html. Serves as the base class for Menu / Tooltip.
//<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
Configs
120Common
Float & align
Set to false to prevent dragging the popup element.
| Parameter | Type | Description |
|---|---|---|
handleSelector | String | CSS selector used to determine if a drag operation can be started from a mouse-downed element inside the popup |
Set to true to make this widget take all available space in the visible viewport.
Other
Auto show flag for Popup. If truthy then Popup is shown automatically upon hover.
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.
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.
Close popup when ESC key is pressed.
By default a Popup is focused when it is shown.
Configure this as false to prevent automatic focus on show.
DOM element to attach popup.
Show a tool in the header to maximize this popup
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
});
| Parameter | Type | Description |
|---|---|---|
closeOnMaskTap | Boolean | Specify as |
transparent | Boolean | Specify as |
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).
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.
Content
CSS
DOM
Layout
misc
Misc
Scrolling
Properties
97
Properties
97Class hierarchy
Float & align
Set to true to make this widget take all available space in the visible viewport.
CSS
DOM
Layout
Misc
Other
State
Widget hierarchy
Functions
75
Functions
75Other
Performs the configured closeAction upon this popup.
By default, the popup hides. The closeAction may be
configured as 'destroy'.
Configuration
Events
Misc
Widget hierarchy
Events
22
Events
22Fired 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Popup | This Popup |
Event handlers
22
Event handlers
22Called 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Popup | This Popup |
Typedefs
7
Typedefs
7CSS variables
60
CSS variables
60| Name | Description |
|---|---|
--b-popup-border-radius | Popup border-radius |
--b-popup-text-popup-width | Popup width for text popups |
--b-popup-close-icon-content | Content for the close icon pseudo element (font icon) |
--b-popup-maximize-icon-content | Content for the close icon pseudo element (font icon) |
--b-popup-padding | Popup padding |
--b-popup-background | Popup background-color |
--b-modal-mask-background | Popup mask background-color (for modal popups) |
--b-popup-border | Popup border |