@serenity-is/corelib / PrefixedContext
Class: PrefixedContext
Defined in: src/ui/widgets/prefixedcontext.ts:11
Provides a scoped context for resolving elements and widgets by an id prefix within a given DOM node. Useful for panels and dialogs that need to look up their child elements and widgets by short, prefix-relative ids.
Constructors
Constructor
new PrefixedContext(
prefixOrWidget,context?):PrefixedContext
Defined in: src/ui/widgets/prefixedcontext.ts:25
Creates a new prefixed context.
Parameters
prefixOrWidget
Either a string id prefix, or an object exposing
idPrefix and domNode (such as a widget) from which the prefix and
context are derived.
string | { domNode: HTMLElement; idPrefix: string; }
context?
HTMLElement
Optional DOM node to scope lookups to; defaults to the
domNode of prefixOrWidget when an object is provided.
Returns
PrefixedContext
Properties
context
readonlycontext:HTMLElement
Defined in: src/ui/widgets/prefixedcontext.ts:15
The DOM node that acts as the scope for lookups.
idPrefix
readonlyidPrefix:string
Defined in: src/ui/widgets/prefixedcontext.ts:13
The id prefix used to resolve child element ids.
Methods
byId()
byId(
id):Fluent
Defined in: src/ui/widgets/prefixedcontext.ts:49
Resolves an element by its prefix-relative id.
Parameters
id
string
The id relative to the context's id prefix.
Returns
A Fluent wrapper for the matching element, or an empty Fluent object if no element matches.
initialize()
protectedinitialize():void
Defined in: src/ui/widgets/prefixedcontext.ts:40
Hook for subclasses to perform additional initialization.
Returns
void
w()
w<
TWidget>(id,type):TWidget
Defined in: src/ui/widgets/prefixedcontext.ts:61
Resolves a widget by its prefix-relative id and expected type.
Type Parameters
TWidget
TWidget
Parameters
id
string
The id relative to the context's id prefix.
type
(...args) => TWidget
The widget type to look up.
Returns
TWidget
The matching widget instance.
Throws
When there is no such widget; the error tells so if the widget of the context, e.g. a dialog, defers its initialization and doesn't have its form yet.