Widget
The base class for all other widgets in the Bryntum libraries. The Widget base class encapsulates a native DOM element, and can optionally contain html. See also Container which lets you build a component tree where widgets can contain other widgets. Simple widget example (inspect with the DOM inspector to see it's really just a simple DIV):
//<code-header>
fiddle.title = 'Widget';
//</code-header>
new Widget({
appendTo : targetElement,
style : 'padding:1em; border:1px solid #aaa',
html : 'A simple Widget with static HTML'
});Rendering
Subclasses should override the compose method to return their encapsulating element and internal
DOM structure. The compose() method returns a createElement config
object that is* used to create the DOM structure, based on its configurable
properties:
class Button extends Widget {
static configurable = {
cls : null,
text : null
};
compose() {
const { cls, text } = this; // collect all relevant configs properties (for auto-detection)
return {
tag : 'button',
class : cls,
text
};
}
}
The config properties used by the compose() method are auto-detected when the method is first called for a class.
All relevant properties must be read, even if they end up not being used so that future changes to these properties
will mark the rendering as dirty.
When a config property used by compose() is modified, the recompose method is called. Since
recompose() is a delayable method, calling it schedules a
delayed call to compose() and a DOM update. Accessing the Widget's primary element or any reference element
property will force the DOM update to occur immediately.
Lifecycle events
The lifecycle events provide hooks into the various stages of a widget's existence, allowing for custom behavior at key points.
These events include
-
elementCreated - Fired once, after the widget's main element has been created but before it is added to the DOM. At this stage it will have its style and cls applied. But since the element is not yet in the DOM, it will not be visible, nor will styles from CSS be applied.
If you need to measure the element (for example to set its size based on its content), you should add a listener for the paint event and perform your measurements there.
-
paint - Fired whenever the widget becomes visible and eligible for layout. This event may be fired multiple times during the lifetime of a widget, whenever it becomes visible after being hidden, or when an ancestor widget is shown after being hidden.
Note that to only react the first time a widget is painted, you can use the
onceoption when adding a listener early in the widget's lifecycle or check thefirstPaintproperty of the event object. -
beforeDestroy - Fired when the widget is being destroyed. At this stage the widget is still fully functional and can be interacted with if certain actions need to be called.
-
destroy - Fired after the widget has been destroyed. At this stage the widget's DOM elements have been removed from the DOM and all event listeners have been detached. The widget is completely inert and has no properties or methods.
Child Elements
Unlike typical DOM config objects, the object returned
by compose() can use an object to simplify naming:
class Button extends Widget {
...
compose() {
const { cls, iconCls, text } = this; // collect all relevant configs properties (for auto-detection)
return {
tag : 'button',
class : cls,
children : {
iconElement : iconCls && {
class : {
'button-icon' : 1,
[iconCls] : 1
}
},
textElement : {
text
}
}
};
}
}
The keys of the children are iterated to convert
the values into the array required by createElement. The names of the
properties becomes the reference of the element.
For example, the above is equivalent to the following:
class Button extends Widget {
...
compose() {
const { cls, iconCls, text } = this; // collect all relevant configs properties (for auto-detection)
return {
tag : 'button',
class : cls,
children : [iconCls && {
reference : 'iconElement',
class : {
'button-icon' : 1,
[iconCls] : 1
}
}, {
reference : 'textElement',
text
}]
};
}
}
In other places inside your class, you can then access those elements as this.iconElement and this.textElement,
no need to use querySelector etc.
The object form of children is preferred for clarity but also because it facilitates inheritance.
Inheritance
When a derived class implements compose(), the object it returns is automatically merged with the object returned
by the base class.
For example, the following class adds a new child element:
class MenuButton extends Button {
...
compose() {
const { menuCls } = this; // collect all relevant configs properties (for auto-detection)
return {
children : {
menuElement : {
class : {
'button-menu' : 1,
[menuCls] : 1
}
}
}
};
}
}
Listeners
Reference elements may also define event listeners in the compose() method:
class Button extends Widget {
compose() {
const { cls, text } = this;
return {
tag : 'button',
class : cls,
text,
listeners : {
click : 'onClick'
}
};
}
onClick(event) {
// handle click event
}
}
Resolving properties
Values for a Widgets properties can be resolved from the ownership hierarchy. For example a text field in a toolbar can get its initial value from a property on the container owning the toolbar. This is achieved by prefixing the desired property name with 'up.':
const grid = new Grid((
tbar : [{
type : 'numberfield',
// Fields value will be retrieved from the grids rowHeight property
value : 'up.rowHeight'
}]
});
NOTE: this is for now a one way one time binding, the value will only be read initially and not kept up to date on later changes.
Configs
74
Configs
74Common
Accessibility
A localizable string (May contain 'L{}' tokens which resolve in the locale file) to inject
into an element which will be linked using the aria-describedby attribute.
This widget is passed as the templateData so that functions in the locale file can
interrogate the widget's state.
A localizable string (May contain 'L{}' tokens which resolve in the locale file) to inject as
the aria-label attribute.
This widget is passed as the templateData so that functions in the locale file can
interrogate the widget's state.
CSS
Custom CSS classes to add to element. May be specified as a space separated string, or as an object in which property names with truthy values are used as the class names:
cls : {
'b-my-class' : 1,
[this.extraCls] : 1,
[this.activeCls] : this.isActive
}
Applies the specified color to the widget, by setting the --b-primary CSS variable in the widgets
style block.
If the supplied color starts with b-, a named color from the current theme will be used (red ->
b-color-red etc.). Applied as <tag style="--b-primary: var(--b-color-<color>)">, for example:
<tag style="--b-primary: var(--b-color-red)">
When the supplied color does not start with b-, it is assumed to be a valid CSS color specification and
is used as is. Applied as <tag style="--b-primary: <color>">, for example:
<tag style="--b-primary: red">
Custom CSS classes to add to the contentElement. May be specified as a space separated string, or as an object in which property names with truthy values are used as the class names:
cls : {
'b-my-class' : 1,
[this.extraCls] : 1,
[this.activeCls] : this.isActive
}
The CSS class(es) to add when HTML content is being applied to this widget.
Custom style spec to add to element
Custom CSS class name suffixes to apply to the elements rendered by this widget. This may be specified as a space separated string, an array of strings, or as an object in which property names with truthy values are used as the class names.
For example, consider a Panel with a ui config like so:
new Panel({
text : 'OK',
ui : 'light'
});
This will apply the CSS class 'b-panel-ui-light' to the main element of the panel as well as its many
child elements. This allows simpler CSS selectors to match the child elements of this particular panel
UI:
.b-panel-content.b-panel-ui-light {
background-color : #eee;
}
Using the cls config would make matching the content element more complex, and in the presence of docked items and nested panels, impossible to target accurately.
DOM
Element (or element id) to adopt as this Widget's encapsulating element. The widget's content will be placed inside this element.
If this widget has not been configured with an id, it will adopt the id of the element in order to preserve CSS rules which may apply to the id.
Element (or the id of an element) to append this widget's element to. Can be configured, or set once at runtime. To access the element of a rendered widget, see element.
The HTML content that coexists with sibling elements which may have been added to the contentElement by plugins and features. When specifying html, this widget's element will also have the htmlCls class added to its classList, to allow targeted styling.
Object to apply to elements dataset (each key will be used as a data-attribute on the element)
The HTML to display initially or a function returning the markup (called at widget construction time).
This may be specified as the name of a function which can be resolved in the component ownership hierarchy, such as 'up.getHTML' which will be found on an ancestor Widget.
| Parameter | Type | Description |
|---|---|---|
widget | Widget | The calling Widget |
Widget id, if not specified one will be generated. Also used for lookups through Widget.getById
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
The tag name of this Widget's root element
A title to display for the widget. Only in effect when inside a container that uses it (such as TabPanel)
Float & align
Only valid if this Widget is floating.
How to align this element with its target when showBy is called passing a simple element as an align target.
Either a full alignment config object, or for simple cases, the edge alignment string to use.
When using a simple string, the format is '[trblc]n-[trblc]n' and it specifies our edge and
the target edge plus optional offsets from 0 to 100 along the edges to align to. Also supports direction
independent edges horizontally, s for start and e for end (maps to l and r for LTR, r and l
for RTL).
See the showBy function for more details about using the object form.
Once set, this is stored internally in object form.
Only valid if this Widget is floating.
Set to true to centre the Widget in browser viewport space.
Only valid if this Widget is floating or positioned. Element, Widget or Rectangle to which this Widget is constrained.
Only valid if this Widget is floating.
Set to true to be able to drag a widget freely on the page. Or set to an object with a ´handleSelector´
property which controls when a drag should start.
draggable : {
handleSelector : ':not(button)'
}
| Parameter | Type | Description |
|---|---|---|
handleSelector | String | CSS selector used to determine if drag can be started from a mouse-downed element inside the widget |
Set to true to move the widget out of the document flow and position it
absolutely in browser viewport space.
Only valid if this Widget is floating.
An object which defined which CSS style property should be animated upon hide, and how it should be animated eg:
{
opacity: {
to : 0,
duration: '10s',
delay: '0s'
}
}
Set to 'false' to disable animation.
Set to true when a widget is rendered into another widget's contentElement, but must
not participate in the standard layout of that widget, and must be positioned relatively to that
widget's contentElement.
Editors are positioned widgets.
Defines what to do if document is scrolled while Widget is visible (only relevant when floating is set to true).
Valid values: ´null´: do nothing, ´hide´: hide the widget or ´realign´: realign to the target if possible.
Only valid if this Widget is floating.
An object which defined which CSS style property should be animated upon show, and how it should be animated eg:
{
opacity: {
to : 1,
duration: '10s',
delay: '0s'
}
}
Set to 'false' to disable animation.
The x position for the widget.
Only valid if this Widget is floating and not aligned or anchored to an element.
The y position for the widget.
Only valid if this Widget is floating and not aligned or anchored to an element.
Layout
When this widget is a child of a Container, it will by default be participating in a flexbox layout. This config allows you to set this widget's align-self style.
Controls the placement of this widget when it is added to a panel's
strips collection. Typical values for this config are 'top',
'bottom', 'left', or 'right', which cause the widget to be placed on that side of the panel's
body. Such widgets are called "edge strips".
Also accepts direction neutral horizontal values 'start' and 'end'.
If this config is set to 'header', the widget is placed in the panel's header, following the title. If
this config is set to 'pre-header', the widget is placed before the title. Such widgets are called
"header strips".
When this widget is a child of a Container, it will by default be participating in a
flexbox layout. This config allows you to set this widget's
flex style.
This may be configured as a single number or a <flex-grow> <flex-shrink> <flex-basis> format string.
numeric-only values are interpreted as the flex-grow value.
Widget's height, used to set element style.height. Either specify a valid height string or a number,
which will get 'px' appended. We recommend using CSS as the primary way to control height, but in some
cases this config is convenient.
Widget's margin. This may be configured as a single number or a TRBL format string.
numeric-only values are interpreted as pixels.
The element's maxHeight. Can be either a String or a Number (which will have 'px' appended). Note that like height, reading the value will return the numeric value in pixels.
The elements maxWidth. Can be either a String or a Number (which will have 'px' appended). Note that like width, reading the value will return the numeric value in pixels.
The element's minHeight. Can be either a String or a Number (which will have 'px' appended). Note that like height, reading the value will return the numeric value in pixels.
The elements minWidth. Can be either a String or a Number (which will have 'px' appended). Note that like width, reading the value will return the numeric value in pixels.
Text alignment: 'left', 'center' or 'right'. Also accepts direction neutral 'start' and 'end'.
Applied by adding a b-text-align-xx class to the widgets element. Blank by default, which does not add
any alignment class.
To be compliant with RTL, 'left' yields same result as 'start' and 'right' as 'end'.
A widgets weight determines its position among siblings when added to a Container. Higher weights go further down.
Widget's width, used to set element style.width. Either specify a valid width string or a number, which
will get 'px' appended. We recommend using CSS as the primary way to control width, but in some cases
this config is convenient.
Misc
When this Widget configuration is used in the Grid's RowExpander feature's widget config, provide the
field on the expanded record to use for populating this widget's store (if applicable)
The name of the property to set when a single value is to be applied to this Widget. Such as when used
in a grid WidgetColumn, this is the property to which the column's field is applied.
Disable or enable the widget. It is similar to readOnly except a disabled widget cannot be focused, uses a different rendition (usually greyish) and does not allow selecting its value.
Set to 'inert' to also set the inert DOM attribute.
An object specifying attributes to assign to the root element of this widget.
Set null value to attribute to remove it.
new Label({
elementAttributes : {
'data-role': 'primary', // Add data-role attribute with `"primary"` value
inert : '', // Add inert with no value
title : null // This will remove the title attribute from the element
}
});
Determines if the widgets read-only state should be controlled by its parent.
When set to true, setting a parent container to read-only will not affect the widget. When set to
false, it will affect the widget.
Set to true to apply the default mask to the widget. Alternatively, this can be the mask message or a
Mask config object.
When this is configured as true a ResizeObserver
is used to monitor this element for size changes caused by either style manipulation, or by CSS
layout.
By default, notifications are queued up for delivery in the next microtask.
To receive notifications immediately, set the immediate option to true.
Size changes are announced using the resize event.
| Parameter | Type | Description |
|---|---|---|
immediate | Boolean | Set to |
The owning Widget of this Widget. If this Widget is directly contained (that is, it is one of the items of a Container), this config will be ignored. In this case the owner is always the encapsulating Container.
If this Widget is floating, this config should be specified by the developer.
Registering with an owner creates a lifecycle relationship with that owning Widget. When the owner is
destroyed this widget will also be destroyed.
This also allows focus to be tracked in the ownership tree. If a widget owns another widget, then even
if that other widget is in a different element, focusing that owned widget will not cause a
focusOut event, and the containsFocus property remains set.
A widget can unregister from its owner and break this relationship at any time by setting the property
to null. It is then the developer's responsibility to ensure that this Widget is destroyed.
Prevent tooltip from being displayed on touch devices. Useful for example for buttons that display a menu on click etc, since the tooltip would be displayed at the same time.
Whether this widget is read-only. This is only valid if the widget is an input field, or contains input fields at any depth.
All descendant input fields follow the widget's setting. If a descendant widget has a readOnly config, that is set.
An identifier by which this widget will be registered in the widgetMap of all ancestor containers.
If omitted, this widget will be registered using its id. In most cases ref is
preferable over id since id is required to be globally unique while ref is not.
The ref value is also added to the elements dataset, to allow targeting it using CSS etc.
Configure as true to have the component display a translucent ripple when its
focusElement, or element is tapped if the
current theme supports ripples. Out of the box, only the Material theme supports ripples.
This may also be a config object containing the properties listed below.
E.g.
columns : [{}...],
ripple : {
color : 'red',
clip : '.b-grid-row'
},
...
| Parameter | Type | Description |
|---|---|---|
delegate | String | A CSS selector to filter which child elements trigger ripples. By default, the ripple is clipped to the triggering element. |
color | String | A CSS color name or specification. |
radius | Number | The ending radius of the ripple. Note that it will be clipped by the target element by default. |
clip | String | A string which describes how to clip the ripple if it is not to be clipped to the default element. Either the property of the widget to use as the clipping element, or a selector to allow clipping to the closest matching ancestor to the target element. |
If you are rendering this widget to a shadow root inside a web component, set this config to the shadowRoot. If not inside a web component, set it to document.body
Set to false to not show the tooltip when this widget is disabled
A configuration for the tab created for this widget when it is placed in a
TabPanel. For example, this config can be used to control the icon of the tab for
this widget:
items : {
panel : {
type : 'panel',
// other configs...
tab : {
icon : 'fa-wrench'
}
},
...
}
Another use for this config is to set the tab's rotate value
differently than the default managed by the TabPanel:
items : {
panel : {
type : 'panel',
// other configs...
tab : {
rotate : false // don't rotate even if tabBar is docked left or right
}
},
...
}
Set this to false to prevent the creation of a tab for this widget. In this case, this widget must
be shown explicitly. The activeTab for the
tab panel will be -1 in this situation.
items : {
panel : {
type : 'panel',
tab : false, // no tab for this item
// other configs...
},
...
]
Tooltip for the widget, either as a string or as a Tooltip config object.
By default, the Widget will use a single, shared instance to display its tooltip as configured, reconfiguring it to the specification before showing it. Therefore, it may not be permanently mutated by doing things such as adding fixed event listeners.
To have this Widget own its own Tooltip instance, add the property newInstance : true
to the configuration. In this case, the tooltip's owner will be this Widget.
Note that in the absence of a configured ariaDescription, the tooltip's value
will be used to populate an aria-describedBy element within this Widget.
Other
Set to false to not call onXXX method names (e.g. onShow, onClick), as an easy way to listen for events.
const container = new Container({
callOnFunctions : true
onHide() {
// Do something when the 'hide' event is fired
}
});
Programmatic control over which column to start in when used in a grid layout.
Check for CSS compatibility issues when upgrading to v7. Performs the following checks:
- Detects usage of
.b-faclass for icons. FontAwesome is no longer built-in, the standard.faclass should be used instead. - Detects missing FontAwesome font. With FontAwesome no longer built-in, this must be included separately by the app.
- Checks for presence of a Bryntum theme. Theme and structural CSS has been separated, both structural CSS and a theme must be included.
Defaults to true in Grid, Scheduler, Scheduler Pro, Gantt, Calendar and TaskBoard.
Programmatic control over how many columns to span when used in a grid layout.
Scrolling
Specifies whether (and optionally in which axes) a Widget may scroll. true means this widget may scroll
in both axes. May be an object containing boolean overflowX and overflowY properties which are
applied to CSS style properties overflowX and overflowY. If they are boolean, they are translated to
CSS overflow properties thus:
true->'auto'false->'hidden'
After initialization, this property yields a Scroller which may be used to both set and read scroll information.
A Widget uses its overflowElement property to select which element is to be scrollable. By default,
in the base Widget class, this is the Widget's encapsulating element. Subclasses may implement get overflowElement to scroll inner elements.
Properties
65
Properties
65Accessibility
This property yields true if the currently focused element has been reached through other means
than mouse click. If the activeElement matches :focus-visible.
Class hierarchy
CSS
Custom CSS classes to add to element. May be specified as a space separated string, or as an object in which property names with truthy values are used as the class names:
cls : {
'b-my-class' : 1,
[this.extraCls] : 1,
[this.activeCls] : this.isActive
}
DOM
Element (or the id of an element) to append this widget's element to. Can be configured, or set once at runtime. To access the element of a rendered widget, see element.
Set HTML content safely, without disturbing sibling elements which may have been added to the contentElement by plugins and features. When specifying html, this widget's element will also have the htmlCls added to its classList, to allow targeted styling.
Get widgets elements dataset or assign to it
Get this widget's encapsulating HTMLElement, which is created along with the widget but added to DOM at render time.
Returns this widget's focusElement if that element can currently be given focus (e.g., this widget is not disabled, or hidden).
Get this widget's primary focus holding element if this widget is itself focusable, or contains focusable widgets.
The HTML to display initially or a function returning the markup (called at widget construction time).
This may be specified as the name of a function which can be resolved in the component ownership hierarchy, such as 'up.getHTML' which will be found on an ancestor Widget.
| Parameter | Type | Description |
|---|---|---|
widget | Widget | The calling Widget |
Get/set widgets id
Element (or element id) to insert this widget before. If provided, appendTo config is ignored.
Element (or element id) to append this widget element to, as a first child. If provided, appendTo config is ignored.
The child element which scrolls if any. This means the element used by the scrollable.
Get/set widgets elements style. The setter accepts a cssText string or a style config object, the getter always returns a CSSStyleDeclaration
Float & align
Returns an [x, y] array containing the width and height of the anchor arrow used when
aligning this Widget to another Widget or element.
The height is the height of the arrow when pointing upwards, the width is the width of the baseline.
Moves this Widget to the desired x position.
Only valid if this Widget is floating and not aligned or anchored to an element.
Moves this Widget to the desired y position.
Only valid if this Widget is floating and not aligned or anchored to an element.
Layout
Get/set this widget's align-self flexbox setting. This may be set to modify how this widget is aligned
within the cross axis of a flexbox layout container.
Get element's flex property. This may be configured as a single number or a format string:
<flex-grow> <flex-shrink> <flex-basis>
Numeric-only values are interpreted as the flex-grow value.
Get element's offsetHeight or sets its style.height, or specified height if element no created yet.
Get element's margin property. This may be configured as a single number or a TRBL format string.
numeric-only values are interpreted as pixels.
Get/set element's maxHeight. Getter returns max-height from elements style, which is always a string. Setter accepts either a String or a Number (which will have 'px' appended). Note that like height, reading the value will return the numeric value in pixels.
Get/set elements maxWidth. Getter returns max-width from elements style, which is always a string. Setter accepts either a String or a Number (which will have 'px' appended). Note that like width, reading the value will return the numeric value in pixels.
Get/set element's minHeight. Getter returns min-height from elements style, which is always a string. Setter accepts either a String or a Number (which will have 'px' appended). Note that like height, reading the value will return the numeric value in pixels.
Get/set elements minWidth. Getter returns min-width from elements style, which is always a string. Setter accepts either a String or a Number (which will have 'px' appended). Note that like width, reading the value will return the numeric value in pixels.
Accessor to the Scroller which can be used to both set and read scroll information.
Get elements offsetWidth or sets its style.width, or specified width if element not created yet.
Misc
An object providing the record and column for a widget embedded inside a WidgetColumn
columns : [
{
type : 'widget',
widgets: [{
type : 'button',
icon : 'fa fa-trash',
onAction : ({ source : btn }) => btn.cellInfo.record.remove()
}]
}
]
Get/set element's disabled state. Set to 'inert' to also set the inert DOM attribute.
Get/set element's readOnly state. This is only valid if the widget is an input field, or contains input fields at any depth. Updating this property will trigger a readOnly event.
All descendant input fields follow the widget's setting. If a descendant widget has a readOnly config, that is set.
An identifier by which this widget will be registered in the widgetMap of all ancestor containers.
If omitted, this widget will be registered using its id. In most cases ref is
preferable over id since id is required to be globally unique while ref is not.
The ref value is also added to the elements dataset, to allow targeting it using CSS etc.
Get/set a tooltip on the widget. Accepts a string or tooltip config (specify true (or 'true') to use placeholder
as tooltip). When using a string it will configure the tooltip with textContent: true which enforces a default
max width.
By default, this uses a singleton Tooltip instance which may be accessed from the Widget
class under the name Widget.tooltip. This is configured according to the config object on pointer over.
To request a separate instance be created just for this widget, add newInstance : true to the configuration.
Other
Class name getter. Used when original ES6 class name is minified or mangled during production build. Should be overridden in each class which extends Widget or it descendants.
class MyNewClass extends Widget {
static $name = 'MyNewClass';
}
Programmatic control over which column to start in when used in a grid layout.
By default, on touch devices, a two finger pinch gesture where both touch points are
within a Bryntum widget is converted to a CTRL/wheel event injected at the mid-point between
the two initial touches.
This is so that Scheduler and Calendar views which are configured to zoomOnMouseWheel will
zoom on pinch on touch devices.
That disables the platform's native pinch-zooming. Set this static flag to false to disable
the conversion:
Widget.convertPinchToMousewheel = false;
Programmatic control over how many columns to span when used in a grid layout.
Widget name alias which you can use in the items of a Container widget.
class MyWidget extends Widget {
static get type() {
return 'mywidget';
}
}
const panel = new Panel({
title : 'Cool widgets',
items : {
customWidget : { type : 'mywidget', html : 'Lorem ipsum dolor sit amet...' }
}
});
Visibility
Determines visibility by checking if the Widget is hidden, or any ancestor is hidden and that it has an element which is visible in the DOM
Widget hierarchy
This property is set to true when focus is within the ownership tree of this Widget.
This means that either the DOM of this widget contains focus, or, any widget DOM who's owner axis leads to this widget contains focus.
For example a DateField with its DatePicker open and
being interacted with will still have containsFocus set.
Get this Widget's next sibling in the parent Container, or, if not in a Container, the next sibling widget in the same parentElement.
The owning Widget of this Widget. If this Widget is directly contained (i.e. it is one of the items of a Container), this property will be read-only, and will refer to the containing Widget.
If this property has not been set and this is a Popup with a forElement,
this config will refer to that element's encapsulating Widget.
If this Widget is floating, this property should be set by the developer.
Registering with an owner creates a lifecycle relationship with that owning Widget. When
the owner is destroyed this widget will also be destroyed.
A widget can unregister from its owner and break this relationship at any time by setting
the property to null. It is then the developer's responsibility to ensure that this Widget
is destroyed.
Get this Widget's previous sibling in the parent Container, or, if not in a Container, the previous sibling widget in the same parentElement.
Functions
60
Functions
60Float & align
If this Widget is floating or positioned, and visible, aligns the widget according to the passed specification. To stop aligning, call this method without arguments.
| Parameter | Type | Description |
|---|---|---|
spec | AlignSpec | HTMLElement | Alignment options. May be an alignment specification object, or an
|
Moves this Widget to the x,y position. Both arguments can be omitted to just set one value.
For floating Widgets, this is a position in the browser viewport. For positioned Widgets, this is a position in the element it was rendered into.
| Parameter | Type | Description |
|---|---|---|
x | Number | |
y | Number |
Lifecycle
Creates a new widget instance based on the passed config object. The config object is require to have a type property which determines what kind of widget to create.
| Parameter | Type | Description |
|---|---|---|
config | ContainerItemConfig | Config object with |
The instance of the created Widget
Call once per class for custom widgets to have them register with the Widget class, allowing them to be created
by type.
For example:
class MyWidget extends Widget {
static get type() {
return 'mywidget';
}
}
MyWidget.initClass();
Misc
Attached a tooltip to the specified element.
Widget.attachTooltip(element, {
text: 'Useful information goes here'
});
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | Element to attach tooltip for |
configOrText | TooltipConfig | String | Tooltip config or tooltip string, see example and source |
The passed element
Returns the Widget which owns the passed element (or event).
bryntum object as bryntum.fromElement.| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | Event | String | The element, CSS selector for an element or event to start from |
type | String | function | The type of Widget to scan upwards for. The lowercase
class name. Or a filter function which returns |
limit | HTMLElement | Number | The number of components to traverse upwards to find a match of the type parameter, or the element to stop at |
The found Widget or null
Returns the Widget which owns the passed CSS selector.
const button = Widget.fromSelector('#my-button');
| Parameter | Type | Description |
|---|---|---|
selector | String | CSS selector |
The found Widget or null
Returns the widget with the specified id.
| Parameter | Type | Description |
|---|---|---|
id | String | Id of widget to find |
The widget
Other
Announces a text message that can be parsed by assistive technologies using an aria-live element.
| Parameter | Type | Description |
|---|---|---|
message | String | The message to announce |
Returns a createElement config object that defines this widget's DOM structure. This object should be determined using configurable properties to ensure this method is called again if these properties are modified.
For more information see class documentation.
Disable the widget
Enable the widget
Exits fullscreen mode
A Promise which is resolved once the user agent has finished exiting full-screen mode
Focuses this widget if it has a focusable element.
Mask the widget, showing the specified message
| Parameter | Type | Description |
|---|---|---|
msg | String | MaskConfig | Mask message (or a Mask config object |
Calling this delayable method marks this widget as dirty. The DOM will be updated on the next animation frame:
widget.recompose();
console.log(widget.recompose.isPending);
> true
A pending update can be flushed by calling flush() (this does nothing if no update is pending):
widget.recompose.flush();
This can be combined in one call to force a DOM update without first scheduling one:
widget.recompose.now();
Requests fullscreen display for this widget
A Promise which is resolved with a value of undefined when the transition to full screen is complete.
If this Widget contains focus, focus is reverted to the source from which it entered if possible, or to a close relative if not.
| Parameter | Type | Description |
|---|---|---|
force | Boolean | Pass as |
Unmask the widget
Visibility
Hide widget
| Parameter | Type | Description |
|---|---|---|
animate | Boolean | Pass |
A promise which is resolved when the widget has been hidden
Shows this widget
| Parameter | Type | Description |
|---|---|---|
options | Object | modifications to the show operation |
options.align | AlignSpec | An alignment specification as passed to alignTo |
options.animate | Boolean | Specify as |
A promise which is resolved when the widget is shown
Widget hierarchy
Starts with this Widget, then Looks up the owner axis to find an ancestor which matches the
passed selector. The selector may be a widget type identifier, such as 'grid', or a function which will return
true when passed the desired ancestor.
| Parameter | Type | Description |
|---|---|---|
selector | String | function | A Type identifier or selection function. |
deep | Boolean | When using a string identifier, pass |
limit | Number | String | Widget | how many steps to step up before aborting the search, or a selector to stop at or the topmost ancestor to consider. |
Returns true if this widget is or contains the specified element or widget.
| Parameter | Type | Description |
|---|---|---|
elementOrWidget | HTMLElement | Widget | The element or widget |
strict | Boolean | Pass |
Iterate over all ancestors of this widget.
Note: Due to this method aborting when the function returns false, beware of using short form arrow
functions. If the expression executed evaluates to false, iteration will terminate.
| Parameter | Type | Description |
|---|---|---|
fn | function | Function to execute for all ancestors. Terminate iteration by returning |
Returns true if iteration was not aborted by a step returning false
Iterate over all widgets owned by this widget and any descendants.
Note: Due to this method aborting when the function returns false, beware of using short form arrow
functions. If the expression executed evaluates to false, iteration will terminate.
| Parameter | Type | Description |
|---|---|---|
fn | function | A function to execute upon each descendant widget.
Iteration terminates if this function returns |
fn.widget | Widget | The current descendant widget. |
fn.control | Object | An object containing recursion control options. |
fn.control.down | Boolean | A copy of the |
deep | Boolean | Pass as |
Returns true if iteration was not aborted by a step returning false
Returns true if this Widget owns the passed Element, Event or Widget. This is based on the widget hierarchy,
not DOM containment. So an element in a Combo's dropdown list will be owned by the Combo.
| Parameter | Type | Description |
|---|---|---|
target | HTMLElement | Event | Widget | The element event or Widget to test for being within the ownership tree of this Widget. |
Returns the first descendant widgets which the passed
filter function returns true for.
| Parameter | Type | Description |
|---|---|---|
filter | function | A function which, when passed a widget,
returns |
The first matching descendant widget.
Analogous to document.querySelector, finds the first Bryntum widget matching the passed
selector. Supported selector formats:
- Widget type (lowercased class name):
'grid','scheduler','gantt' - ID selector:
'#myWidgetId' - Attribute selector:
'[ref=myRef]','[customProp=value]' - Filter function returning
truefor matching widgets
Widget.query('grid').destroy();
Widget.query('#myScheduler');
Widget.query('[ref=timeline]');
Widget.query(widget => widget.isCool);
bryntum object as bryntum.query.| Parameter | Type | Description |
|---|---|---|
selector | Widget | String | function | A widget instance, widget type, id selector (#id), attribute selector ([attr=value]), or filter function. |
deep | Boolean | Specify |
The first matched widget if any.
Returns an array of all descendant widgets which the passed
filter function returns true for.
| Parameter | Type | Description |
|---|---|---|
filter | function | A function which, when passed a widget,
returns |
All matching descendant widgets.
Analogous to document.querySelectorAll, finds all Bryntum widgets matching the passed
selector. Supported selector formats:
- Widget type (lowercased class name):
'grid','scheduler','gantt' - ID selector:
'#myWidgetId' - Attribute selector:
'[ref=myRef]','[customProp=value]' - Filter function returning
truefor matching widgets
Widget.queryAll('field', true);
Widget.queryAll('[customProp=someValue]');
bryntum object as bryntum.queryAll.| Parameter | Type | Description |
|---|---|---|
selector | String | function | A widget type, id selector (#id), attribute selector ([attr=value]), or filter function. |
deep | Boolean | Specify |
The first matched widgets if any - an empty array will be returned if no matches are found.
Looks up the owner axis to find an ancestor which matches the passed selector.
The selector may be a widget type identifier, such as 'grid', or a function which will return
true when passed the desired ancestor.
| Parameter | Type | Description |
|---|---|---|
selector | String | function | A Type identifier or selection function. If not provided, this method returns the owner of this widget |
deep | Boolean | When using a string identifier, pass |
limit | Number | String | Widget | how many steps to step up before aborting the search, or a selector to stop at or the topmost ancestor to consider. |
Configuration
Events
Events
14
Events
14Triggered before a widget is hidden. Return false to prevent the action.
// Adding a listener using the "on" method
widget.on('beforeHide', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being hidden. |
Triggered before a widget is shown. Return false to prevent the action.
// Adding a listener using the "on" method
widget.on('beforeShow', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being shown |
Triggered when a widget's element is available.
// Adding a listener using the "on" method
widget.on('elementCreated', ({ element }) => {
});| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The Widget's element. |
Fired when focus enters this Widget.
// Adding a listener using the "on" method
widget.on('focusIn', ({ source, fromElement, toElement, fromWidget, toWidget, backwards }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
fromElement | HTMLElement | The element which lost focus. |
toElement | HTMLElement | The element which gained focus. |
fromWidget | Widget | The widget which lost focus. |
toWidget | Widget | The widget which gained focus. |
backwards | Boolean |
|
Fired when focus exits this Widget's ownership tree. This is different from a blur event.
focus moving from within this Widget's ownership tree, even if there are floating widgets
will not trigger this event. This is when focus exits this widget completely.
// Adding a listener using the "on" method
widget.on('focusOut', ({ source, fromElement, toElement, fromWidget, toWidget, backwards }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
fromElement | HTMLElement | The element which lost focus. |
toElement | HTMLElement | The element which gained focus. |
fromWidget | Widget | The widget which lost focus. |
toWidget | Widget | The widget which gained focus. |
backwards | Boolean |
|
Triggered after a widget was hidden
// Adding a listener using the "on" method
widget.on('hide', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget |
Triggered when a widget which had been in a non-visible state for any reason achieves visibility.
A non-visible state might mean the widget is hidden and has just been shown.
But this event will also fire on widgets when a non-visible (unrendered, or hidden) ancestor achieves visibility, for example a Popup being shown.
TLDR: This event can fire multiple times
// Adding a listener using the "on" method
widget.on('paint', ({ source, firstPaint }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being painted. |
firstPaint | Boolean |
|
Fired when a Widget's read only state is toggled
// Adding a listener using the "on" method
widget.on('readOnly', ({ readOnly }) => {
});| Parameter | Type | Description |
|---|---|---|
readOnly | Boolean | Read only or not |
This event is fired after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.
// Adding a listener using the "on" method
widget.on('recompose', ({ }) => {
});Fired when the encapsulating element of a Widget resizes only when monitorResize is true.
// Adding a listener using the "on" method
widget.on('resize', ({ source, width, height, oldWidth, oldHeight }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
width | Number | The new width |
height | Number | The new height |
oldWidth | Number | The old width |
oldHeight | Number | The old height |
Triggered after a widget is shown.
// Adding a listener using the "on" method
widget.on('show', ({ source }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget |
Event handlers
14
Event handlers
14Called before a widget is hidden. Return false to prevent the action.
new Widget({
onBeforeHide({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being hidden. |
Called before a widget is shown. Return false to prevent the action.
new Widget({
onBeforeShow({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being shown |
Called when a widget's element is available.
new Widget({
onElementCreated({ element }) {
}
});| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The Widget's element. |
Called when focus enters this Widget.
new Widget({
onFocusIn({ source, fromElement, toElement, fromWidget, toWidget, backwards }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
fromElement | HTMLElement | The element which lost focus. |
toElement | HTMLElement | The element which gained focus. |
fromWidget | Widget | The widget which lost focus. |
toWidget | Widget | The widget which gained focus. |
backwards | Boolean |
|
Called when focus exits this Widget's ownership tree. This is different from a blur event.
focus moving from within this Widget's ownership tree, even if there are floating widgets
will not trigger this event. This is when focus exits this widget completely.
new Widget({
onFocusOut({ source, fromElement, toElement, fromWidget, toWidget, backwards }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
fromElement | HTMLElement | The element which lost focus. |
toElement | HTMLElement | The element which gained focus. |
fromWidget | Widget | The widget which lost focus. |
toWidget | Widget | The widget which gained focus. |
backwards | Boolean |
|
Called after a widget was hidden
new Widget({
onHide({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget |
Called when a widget which had been in a non-visible state for any reason achieves visibility.
A non-visible state might mean the widget is hidden and has just been shown.
But this event will also fire on widgets when a non-visible (unrendered, or hidden) ancestor achieves visibility, for example a Popup being shown.
TLDR: This event can fire multiple times
new Widget({
onPaint({ source, firstPaint }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget being painted. |
firstPaint | Boolean |
|
Called when a Widget's read only state is toggled
new Widget({
onReadOnly({ readOnly }) {
}
});| Parameter | Type | Description |
|---|---|---|
readOnly | Boolean | Read only or not |
This event is called after a widget's elements have been synchronized due to a direct or indirect call to recompose, if this results in some change to the widget's rendered DOM elements.
new Widget({
onRecompose({ }) {
}
});Called when the encapsulating element of a Widget resizes only when monitorResize is true.
new Widget({
onResize({ source, width, height, oldWidth, oldHeight }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | This Widget |
width | Number | The new width |
height | Number | The new height |
oldWidth | Number | The old width |
oldHeight | Number | The old height |
Called after a widget is shown.
new Widget({
onShow({ source }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Widget | The widget |
Typedefs
6
Typedefs
6Specification for how to align a Widget to another Widget, Element or Rectangle.
| Parameter | Type | Description |
|---|---|---|
target | HTMLElement | Widget | Rectangle | Event | The Widget or Element or Rectangle or event to align to. |
inflate | Number | Number[] | Arguments to inflate. Specify as a number to inflate the target rectangle by that many pixels, or as an array of inflate values for each edge. |
domEvent | Event | A pointer event to position this Widget by. |
anchor | Boolean | True to show a pointer arrow connecting to the target. Defaults to false. |
overlap | Boolean | True to allow this to overlap the target. |
align | String | The edge alignment specification string, Defaults to this instance's The edge alignment specification string describes two points to bring together. Each point is described by an edge
initial ( So the form would be For example Also supports direction independent edges horizontally, |
constrainTo | HTMLElement | Widget | Rectangle | The Widget or Element or
Rectangle to constrain to. If the requested alignment cannot be constrained (it will first shrink the resulting
Rectangle according to the |
constrainPadding | Number | Number[] | The amount of pixels to pad from the |
minHeight | Number | The minimum height this widget may be compressed to when constraining within the
|
minWidth | Number | The minimum width this widget may be compressed to when constraining within the
|
axisLock | Boolean | flexible | Specify as |
matchSize | Boolean | min | When aligning edge-to-edge, match the length of the aligned-to edge of the target.
This is only honored when Setting this value to If not aligning edge-to-edge, |
offset | Number | Number[] | The
|
monitorResize | Boolean | Configure as |
A context object injected into all cell widgets owned by grid widget columns. It allows event handlers for the widget to ascertain the context in which they are operating.
| Parameter | Type | Description |
|---|---|---|
cellElement | HTMLElement | The cell in which the widget is rendered. |
record | Model | The record backing the row into which the widget is rendered. |
Predefined named colors (actual color might vary by theme):
CSS variables
20
CSS variables
20| Name | Description |
|---|---|
--b-widget-anchor-width | Inline size of the anchor for an anchored floating widget |
--b-widget-anchor-height | Block size of the anchor for an anchored floating widget |
--b-widget-font-size | Widget font-size. Defaults to 1em = the font size used by the parent element. |
--b-widget-font-weight | Widget font-weight |
--b-widget-icon-font-family | The default themes use Font Awesome 6 Free for icons. If you use a different icon font, you can override this variable. Note that you will also have to override the individual icon classes. |
--b-widget-icon-font-weight | The font-weight used for icons. The default themes use Font Awesome 6 Free solid icons which require font-weight 900. |
--b-widget-sub-menu-icon | Which character of the icon font to use for sub-menu icons |
--b-widget-color | Base color for text etc. Where it is applied may vary depending on theme |
--b-widget-padding | Base padding. Where it is applied may vary depending on theme |
--b-widget-padding-large | Base padding for widgets that want a larger padding. Where it is applied may vary depending on theme |
--b-widget-gap | Base gap. Where it is applied may vary depending on theme |
--b-widget-focus-outline-width | Base focus outline width. Where it is applied may vary depending on theme |
--b-widget-focus-outline-color | Base focus outline color. Where it is applied may vary depending on theme |
--b-widget-floating-box-shadow | Base box shadow used by floating widgets like popups and menus. Where it is applied may vary depending on theme |
--b-aligned-above-floating-box-shadow | Box shadow used by floating widgets which are aligned above their target, so that the shadow extends above. |
--b-widget-floating-border | Base border for floating widgets like popups and menus. Where it is applied may vary depending on theme |
--b-label-color | Base label color. Defined in Widget since some widgets have labels that do not use the Label widget |
--b-default-transition-duration | Default duration for transitions. This is used for transitions resulting from user interaction throughout Bryntum widgets and components. For example, it is used for selection rendition transitions in Grids and for task and event transitions in Scheduler, SchedulerPro, Calendar, Gantt and TaskBoard. This is ignored if user has requested reduced motion in OS settings |
| Disabled | |
--b-widget-disabled-color | Base color for disabled widgets. Where it is applied may vary depending on theme |
--b-widget-disabled-background | Base background for disabled widgets. Where it is applied may vary depending on theme |