Adds a keyboard shortcut to the component. It works while the focus
is in the component, and while the focus is nowhere if this component
is the last one with shortcuts that had it: of two views that are shown
together, the one the user works in answers.
A key that a child has used (it prevented its default, or stopped its
propagation) is not a shortcut. Nor is a key typed in a field, unless
editable is set.
Parameters
keys: string|string[]
"Mod+C", "Shift+Mod+Z", "Delete"... or several of them. Mod is Ctrl, or Cmd on a Mac.
Appends content to the end of the component's DOM element.
Content can be a single Component, an array of Components, a string, an array of strings,
raw HTML, an array of raw HTML, a number, or a boolean.
Enables or disables the component.
This sets or removes the disabled and inert attributes of the component itself. Its children
are not changed: the browser makes all that is inside an inert element inactive.
Parameters
ena: boolean = true
If true, the component is enabled; if false, it's disabled. Defaults to true.
Dispatches an event with a given name and payload to all registered listeners.
If no listeners are registered for the event name, or if no EventSource has been initialized, this method does nothing.
Retrieves the computed style for the component's DOM element.
Returns CSSStyleDeclaration
A CSSStyleDeclaration object representing the computed styles.
getData
getData(name:string):string
Retrieves the value of a data-* attribute from the component's DOM element.
Parameters
name: string
The suffix of the data- attribute (e.g., for data-foo, use "foo").
Returns string
The string value of the data-* attribute, or null if not present.
See
Component.setIntData
Component.getIntData
Component.setInternalData
Component.getInternalData
getIntData
getIntData(name:string):number
Retrieves the integer value of a data-* attribute from the component's DOM element.
Returns undefined if the attribute is not present or cannot be parsed as a number.
Parameters
name: string
The suffix of the data- attribute.
Returns number
The integer value of the data-* attribute, or undefined.
Retrieves the computed inline CSS style value for a specific property.
This only returns styles explicitly set via setStyle or setStyleValue, not inherited or stylesheet-defined styles.
Registers an event listener for a specific event name.
The listener will be invoked when an event with the given name is fired.
Returns an object with an off() method, which can be used to conveniently remove this specific listener.
Attaches a listener for global messages dispatched by the application.
The listener is automatically removed when the component's DOM element is removed.
Prepends content to the beginning of the component's DOM element.
Content can be a single Component, an array of Components, a string, an array of strings,
raw HTML, an array of raw HTML, a number, or a boolean.
Removes one or more CSS classes from the component's DOM element.
If * is passed as the class name, all classes will be removed.
Multiple classes can be provided as a space-separated string.
Parameters
cls: string
The CSS class(es) to remove, or * to clear all.
Returns void
removeClassEx
removeClassEx(re:RegExp):void
Removes all CSS classes from the component's DOM element that match a given regular expression.
Parameters
re: RegExp
The regular expression to match against class names.
Sets an interval that repeatedly executes a callback function after a specified delay.
If a timeout with the same name already exists, it will be cleared before the new one is set.
Parameters
name: string
A unique string identifier for this timeout.
ms: number
The delay in milliseconds before the callback is executed.
Sets multiple inline CSS styles on the component's DOM element.
Numeric values for properties like width or height will automatically append "px" unless they are unitless.
Sets a single inline CSS style property on the component's DOM element.
Numeric values for properties like width or height will automatically append "px" unless they are unitless.
Sets a timeout that executes a callback function after a specified delay.
If a timeout with the same name already exists, it will be cleared before the new one is set.
Parameters
name: string
A unique string identifier for this timeout.
ms: number
The delay in milliseconds before the callback is executed.
callback: ()=>void
The function to execute after the delay.
Returns void
setWidth
setWidth(w:string|number):void
Sets the width of the component.
Parameters
w: string|number
The width value. Can be a number (interpreted as pixels) or a string (e.g., "100px", "50%").
Returns void
show
show(vis?:boolean):this
Shows or hides the component.
It toggles the x4hidden CSS class.
Parameters
vis: boolean = true
If true, the component is shown; if false, it's hidden. Defaults to true.
Returns this
The component instance for chaining.
toggleClass
toggleClass(cls:string):void
Toggles the presence of one or more CSS classes on the component's DOM element.
If a class is present, it's removed; otherwise, it's added.
Multiple classes can be provided as a space-separated string.
Creates a new Component or an array of Components from JSX elements.
This method is typically called by the TypeScript/JavaScript compiler when JSX is transpiled.
Creates a fragment, which is an array of components without a parent DOM element.
Used for grouping multiple children in JSX without introducing an extra DOM node.
A generic container component for grouping and laying out child components. *
Cssvar
refsobject is a typed directory of the children you need to reachrefsas you build the content: theExample
Type Parameters
Hierarchy (View Summary)
Index
Constructors
Properties
Methods
Constructors
constructor
P extends BoxProps = BoxProps,
E extends ComponentEvents = ComponentEvents,
>(
props: P,
): Box<P, E>
Type Parameters
Parameters
Returns Box<P, E>
Properties
ProtectedReadonlyclsprefixReadonlydomThe underlying DOM element of the component.
ReadonlypropsThe properties passed to the component's constructor.
ProtectedrefsStaticclassMethods
add Class
Adds one or more CSS classes to the component's DOM element. Multiple classes can be provided as a space-separated string.
Parameters
The CSS class(es) to add.
Returns void
add Cleanup
add a cleanup function to the cleanup list
Parameters
Returns void
See
cleanUp
add DOM Event
name: K,
listener: GlobalDOMEvents[K],
prepend?: boolean,
): void
Adds a DOM event listener to the component's DOM element.
Type Parameters
Parameters
The name of the DOM event (e.g.,
'click','mouseover').The event handler function.
If
true, the listener is added to the beginning of the event listener list. Defaults tofalse.Returns void
add Shortcut
keys: string | string[],
callback: ShortcutCallback,
options?: ShortcutOptions,
): this
Adds a keyboard shortcut to the component. It works while the focus is in the component, and while the focus is nowhere if this component is the last one with shortcuts that had it: of two views that are shown together, the one the user works in answers.
A key that a child has used (it prevented its default, or stopped its propagation) is not a shortcut. Nor is a key typed in a field, unless
editableis set.Parameters
"Mod+C", "Shift+Mod+Z", "Delete"... or several of them. Mod is Ctrl, or Cmd on a Mac.
Optionaloptions: ShortcutOptionsReturns this
See
Application.addShortcut for the shortcuts of the whole application
Example
animate
Animates the component's DOM element using the Web Animations API.
Parameters
An array of keyframe objects or a
Keyframeobject.The duration of the animation in milliseconds, or a
KeyframeAnimationOptionsobject.Returns void
append Content
Appends content to the end of the component's DOM element. Content can be a single Component, an array of Components, a string, an array of strings, raw HTML, an array of raw HTML, a number, or a boolean.
Parameters
The content to append.
Returns void
Remarks
for simplicity, null is also allowed: setContent( [ optional ? myControl : null, ])
child Count
Returns number
clean Up
called when element is removed from dom
Returns void
clear Content
Removes all child nodes from the component's DOM element.
Returns void
clear Interval
Clears a previously set interval.
Parameters
The name of the interval to clear.
Returns void
See
setInterval
clear Timeout
Clears a previously set timeout.
Parameters
The name of the timeout to clear.
Returns void
See
setTimeout
clear Timeouts
Clears all timeouts and intervals currently managed by this instance. This stops all scheduled callbacks and removes their references.
Returns void
See
setTimeout
closest
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(
selector: string,
): T
The nearest component whose element matches a css selector: this one, or one of its ancestors.
Type Parameters
Parameters
Returns T
null when there is none
contains
true when a node, or the element of a component, is the element of this one or inside it
Parameters
Returns boolean
disable
Disables the component.
Returns this
The component instance for chaining.
enable
Enables or disables the component. This sets or removes the
disabledandinertattributes of the component itself. Its children are not changed: the browser makes all that is inside aninertelement inactive.Parameters
If
true, the component is enabled; iffalse, it's disabled. Defaults totrue.Returns this
The component instance for chaining.
enum Child Components
recursive: boolean,
): Component<ComponentProps, ComponentEvents>[]
Enumerates all child components of this component.
Parameters
If
true, searches all descendants; otherwise, only direct children.Returns Component<ComponentProps, ComponentEvents>[]
An array of child Component instances.
enum Child Nodes
Enumerates all child DOM nodes of this component. Not all nodes may be components.
Parameters
If
true, searches all descendant nodes; otherwise, only direct children.Returns Node[]
An array of child DOM nodes.
fire
Dispatches an event with a given name and payload to all registered listeners. If no listeners are registered for the event name, or if no EventSource has been initialized, this method does nothing.
Type Parameters
Parameters
The name of the event to fire.
The payload (event object) to pass to the listeners.
Returns void
See
first Child
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(): T
Returns the first child element as a Component instance.
Type Parameters
Returns T
The first child component, or
nullif none exists.focus
Gives focus to the component's DOM element.
Returns this
The component instance for chaining.
get Attribute
Retrieves the value of an HTML attribute from the component's DOM element.
Parameters
The name of the attribute.
Returns string
The string value of the attribute, or
nullif not present.get Bounding Rect
Returns the size and position of the component's DOM element relative to the viewport.
Returns Rect
A
Rectobject containing the bounding rectangle.get Computed Style
Retrieves the computed style for the component's DOM element.
Returns CSSStyleDeclaration
A
CSSStyleDeclarationobject representing the computed styles.get Data
Retrieves the value of a
data-*attribute from the component's DOM element.Parameters
The suffix of the
data-attribute (e.g., fordata-foo, use"foo").Returns string
The string value of the
data-*attribute, ornullif not present.See
get Int Data
Retrieves the integer value of a
data-*attribute from the component's DOM element. Returnsundefinedif the attribute is not present or cannot be parsed as a number.Parameters
The suffix of the
data-attribute.Returns number
The integer value of the
data-*attribute, orundefined.get Internal Data
Type Parameters
Parameters
Returns T
get Style Value
name: K,
): CSSStyleDeclaration[K]
Retrieves the computed inline CSS style value for a specific property. This only returns styles explicitly set via
setStyleorsetStyleValue, not inherited or stylesheet-defined styles.Type Parameters
Parameters
The name of the CSS property.
Returns CSSStyleDeclaration[K]
The value of the inline CSS property.
get Style Variable
Retrieves the value of a CSS custom property (CSS variable) for the component. The computed style of the element is used.
Parameters
The name of the CSS variable.
Returns string
The string value of the CSS variable.
has Class
Checks if the component's DOM element has a specific CSS class.
Parameters
The CSS class name to check.
Returns boolean
trueif the class is present,falseotherwise.has Focus
Checks if the component's DOM element currently has focus.
Returns boolean
trueif the component is focused,falseotherwise.hide
Hides the component by applying the
x4hiddenCSS class.Returns this
The component instance for chaining.
is Disabled
Checks if the component is marked as disabled. This checks for the presence of the
disabledattribute.Returns string
The string value of the
disabledattribute, ornullif not present.is Visible
Checks if the component's DOM element is currently visible (i.e., not hidden by
display: none).Returns boolean
trueif the component is visible,falseotherwise.last Child
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(): T
Returns the last child element as a Component instance.
Type Parameters
Returns T
The last child component, or
nullif none exists.ProtectedloadParameters
Returns any
next Element
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(): T
Returns the next sibling element as a Component instance.
Type Parameters
Returns T
The next sibling component, or
nullif none exists.off
name: K,
listener: (ev: E[K]) => void,
): void
Removes a previously registered event listener. If the listener was not found or no events were registered, this method does nothing.
Type Parameters
Parameters
The name of the event from which to remove the listener.
The specific listener function to remove.
Returns void
See
on
name: K,
listener: (ev: E[K]) => void,
): { off: () => void }
Registers an event listener for a specific event name. The listener will be invoked when an event with the given name is fired. Returns an object with an
off()method, which can be used to conveniently remove this specific listener.Type Parameters
Parameters
The name of the event to listen for.
The callback function to execute when the event is fired.
Returns { off: () => void }
An object containing an
off()method to unsubscribe the listener.See
fire attach to an event
on Global Event
Attaches a listener for global messages dispatched by the application. The listener is automatically removed when the component's DOM element is removed.
Parameters
The callback function to execute when a global message is received.
Returns void
parent Element
cls?: Constructor<T>,
): T
Searches up the DOM tree for a parent element that is a Component and optionally matches a specific constructor.
Type Parameters
Parameters
Optionalcls: Constructor<T>Optional. The constructor of the Component type to match.
Returns T
The matching parent Component instance, or
nullif not found.prepend Content
Prepends content to the beginning of the component's DOM element. Content can be a single Component, an array of Components, a string, an array of strings, raw HTML, an array of raw HTML, a number, or a boolean.
Parameters
The content to prepend.
Returns void
prev Element
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(): T
Returns the previous sibling element as a Component instance.
Type Parameters
Returns T
The previous sibling component, or
nullif none exists.query
T extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(
selector: string,
): T
Queries the first descendant DOM element matching a CSS selector and wraps it as a Component instance.
Type Parameters
Parameters
The CSS selector string.
Returns T
The first matching Component instance, or
nullif no match is found.query All
Queries all descendant DOM elements matching a CSS selector and wraps them as Component instances.
Parameters
The CSS selector string.
Returns Component<ComponentProps, ComponentEvents>[]
An array of Component instances.
query Interface
Queries for a specific system or application-defined interface on the component. Common system interfaces include "form-element" and "tab-handler".
Type Parameters
Parameters
The name of the interface to query.
Returns T
An object conforming to the requested interface, or
nullif not supported.release Capture
Releases pointer capture on the component's DOM element for a specific pointer.
Parameters
The unique ID of the pointer.
Returns void
remove Child
Removes a specific child component from this component's DOM element.
Parameters
The child component instance to remove.
Returns void
See
clearContent
remove Class
Removes one or more CSS classes from the component's DOM element. If
*is passed as the class name, all classes will be removed. Multiple classes can be provided as a space-separated string.Parameters
The CSS class(es) to remove, or
*to clear all.Returns void
remove Class Ex
Removes all CSS classes from the component's DOM element that match a given regular expression.
Parameters
The regular expression to match against class names.
Returns void
scroll Into View
Scrolls the component's DOM element into the visible area of the browser window.
Parameters
Optionalarg: boolean | ScrollIntoViewOptionsOptional. A boolean (
truefor smooth scroll) or an object specifying scroll options.Returns void
set Aria
Sets an ARIA attribute on the component's DOM element.
Parameters
The name of the ARIA attribute (e.g.,
'aria-label').The value of the ARIA attribute.
Returns this
The component instance for chaining.
set Attribute
Sets a single HTML attribute on the component's DOM element. If
valueisnull,undefined, orfalse, the attribute will be removed.Parameters
The name of the attribute.
The value of the attribute.
Returns void
set Attributes
Sets multiple HTML attributes on the component's DOM element.
Parameters
An object where keys are attribute names and values are their corresponding values.
Returns this
The component instance for chaining.
set Capture
Sets pointer capture on the component's DOM element for a specific pointer.
Parameters
The unique ID of the pointer.
Returns void
Example
set Class
Sets or removes a CSS class based on a boolean condition.
Parameters
The CSS class to manage.
If
true, the class is added; iffalse, it's removed. Defaults totrue.Returns this
The component instance for chaining.
set Content
Replaces the entire content of the component's DOM element with new content. Any existing content will be cleared before the new content is added.
Parameters
The new content to set. Can be a single item or an array of items.
Returns void
set Data
Sets the value of a
data-*attribute on the component's DOM element.Parameters
The suffix of the
data-attribute.The string value to set.
Returns void
set DOM Events
Sets multiple DOM event listeners on the component's DOM element.
Parameters
An object where keys are event names and values are their corresponding handler functions.
Returns void
set Height
Sets the height of the component.
Parameters
The height value. Can be a number (interpreted as pixels) or a string (e.g.,
"100px","50%").Returns void
set Internal Data
idem as setData but onot on dom, you can store anything
Type Parameters
Parameters
Returns this
set Interval
Sets an interval that repeatedly executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.
Parameters
A unique string identifier for this timeout.
The delay in milliseconds before the callback is executed.
The function to execute after the delay.
Returns void
set Style
Sets multiple inline CSS styles on the component's DOM element. Numeric values for properties like
widthorheightwill automatically append"px"unless they are unitless.Parameters
An object where keys are CSS property names and values are their corresponding styles.
Returns this
The component instance for chaining.
set Style Value
name: K,
value: number | CSSStyleDeclaration[K],
): this
Sets a single inline CSS style property on the component's DOM element. Numeric values for properties like
widthorheightwill automatically append"px"unless they are unitless.Type Parameters
Parameters
The name of the CSS property.
The value of the CSS property.
Returns this
The component instance for chaining.
set Style Variable
Sets a CSS custom property (CSS variable) on the component's DOM element.
Parameters
The name of the CSS variable (e.g.,
'--my-color').The value to set for the CSS variable.
Returns void
set Timeout
Sets a timeout that executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.
Parameters
A unique string identifier for this timeout.
The delay in milliseconds before the callback is executed.
The function to execute after the delay.
Returns void
set Width
Sets the width of the component.
Parameters
The width value. Can be a number (interpreted as pixels) or a string (e.g.,
"100px","50%").Returns void
show
Shows or hides the component. It toggles the
x4hiddenCSS class.Parameters
If
true, the component is shown; iffalse, it's hidden. Defaults totrue.Returns this
The component instance for chaining.
toggle Class
Toggles the presence of one or more CSS classes on the component's DOM element. If a class is present, it's removed; otherwise, it's added. Multiple classes can be provided as a space-separated string.
Parameters
The CSS class(es) to toggle.
Returns void
visit Children
Visits all descendant components of this component, executing a callback function for each. The traversal stops if the callback returns
true.Parameters
The callback function to execute for each component.
Returns void
StaticclosestT extends
Component<ComponentProps, ComponentEvents> = Component<
ComponentProps,
ComponentEvents,
>,
>(
dom: Element,
selector: string,
): T
The nearest component whose element matches a css selector: the one of dom, or one of its ancestors.
Type Parameters
Parameters
Returns T
null when there is none
Example
StaticcreateclsOrTag:
| string
| symbol
| ComponentConstructor
| CreateComponentCallBack,
attrs: any,
...children: Component<ComponentProps, ComponentEvents>[],
):
| Component<ComponentProps, ComponentEvents>
| Component<ComponentProps, ComponentEvents>[]
Creates a new Component or an array of Components from JSX elements. This method is typically called by the TypeScript/JavaScript compiler when JSX is transpiled.
Parameters
The class constructor of the component, an HTML tag name string, a symbol for fragments, or a callback.
An object containing attributes and properties for the component.
Any child components or content passed within the JSX.
Returns
| Component<ComponentProps, ComponentEvents>
| Component<ComponentProps, ComponentEvents>[]
A Component instance or an array of Components.
StaticcreateCreates a fragment, which is an array of components without a parent DOM element. Used for grouping multiple children in JSX without introducing an extra DOM node.
Returns Component<ComponentProps, ComponentEvents>[]
An array of components.
Staticparentdom: Node,
cls?: Constructor<T>,
): T
Static method to search up the DOM tree for a parent element that is a Component and optionally matches a specific constructor. *
Type Parameters
Parameters
The starting DOM node from which to search upwards. *
Optionalcls: Constructor<T>Optional. The constructor of the Component type to match. *
Returns T
The matching parent Component instance, or
nullif not found.Settings
On This Page
Constructors
Properties
Methods