On This Page
Web Component Base
WebComponentBase is the base web component class used to create web components with defineComponent. It handles internal utilities related to component lifecycle and other internals of the framework.
Advanced Use Only It is not recommended to use this base class directly except in use cases where you want to create custom web components without
defineComponent
Import
import { WebComponentBase } from '@semantic-ui/component';Static Properties
| Name | Type | Description |
|---|---|---|
| delegatesFocus | boolean | Passed to attachShadow when the element creates its shadow root |
| shadowRootOptions | Object | Shadow root options. lit engine only |
Instance Properties
| Name | Type | Description |
|---|---|---|
| template | Template | Mounted template instance for this element |
| component | Object | Instance object returned by createComponent |
| dataContext | Object | Merged data context used for rendering |
| settings | Proxy | Reactive settings proxy |
| isMounted | boolean | true while a template is mounted on this element |
| isRendered | boolean | true once the template has completed its initial render |
| isLightDOM | boolean | true when mounted onto a plain element via mount() |
| isCustomElement | boolean | true when instantiated as a registered custom element |
| created | Promise | Resolves after onCreated runs |
| rendered | Promise | Resolves after onRendered runs |
| updated | Promise | Resolves after the next onUpdated, or immediately if no update is pending |
| destroyed | Promise | Resolves after onDestroyed runs |
| updateComplete | Promise | Resolves once any scheduled update has flushed |
| isUpdatePending | boolean | true while a requestUpdate() waits for its microtask |
| renderCallbacks | Array | Array of callbacks executed after rendering (lit engine only) |
Static Methods
getProperties
static getProperties({ properties, settings, componentSpec })Defines property configurations for a web component.
Parameters
| Name | Type | Description |
|---|---|---|
| properties | Object | Initial properties configuration |
| settings | Object | Component settings configuration |
| componentSpec | Object | Component specification object |
Returns
An object containing the configured properties.
Example
const properties = WebComponentBase.getProperties({ properties: { value: String, }, settings: { theme: 'light' }, componentSpec: mySpec});getPropertySettings
static getPropertySettings(propertyName, type = String, { propertyOnly = false } = {})Creates property configuration for a single property.
Parameters
| Name | Type | Description |
|---|---|---|
| propertyName | string | Name of the property |
| type | Function | Constructor for property type |
| options | Object | Property configuration options |
Options Object
| Name | Type | Default | Description |
|---|---|---|---|
| propertyOnly | boolean | false | If true, no attribute created |
Returns
Property configuration object.
Example
const propConfig = WebComponentBase.getPropertySettings( 'theme', String, { propertyOnly: false });Instance Methods
mount
mount(template, { signal } = {});Mounts a template into this element’s renderRoot and returns the mounted Template instance.
Parameters
| Name | Type | Description |
|---|---|---|
| template | Template | Prototype or instance template |
| options | Object | Optional mount configuration |
Options
| Name | Type | Description |
|---|---|---|
| signal | AbortSignal | Unmounts the template automatically when the signal aborts |
Returns
Template - The mounted template instance.
unmount
unmount();Tears down the mounted template, fires onDestroyed, clears renderRoot, and restores the element’s original prototype and properties if it was upgraded in light DOM.
Usage
const Row = defineComponent({ template: '<div class="row">{label}</div>', defaultSettings: { label: 'Hello' },});
Row.mount(el, { settings: { label: 'Mounted' } });el.unmount();update
update(data);Brings the template to data, which defaults to the element’s current settings. A declared setting moves through its signal. Every other key is plain data, re-evaluated wherever the template reads it.
Parameters
| Name | Type | Description |
|---|---|---|
| data | Object | Keys to merge, defaults to this.getData() |
requestUpdate
requestUpdate();Schedules an update from the element’s current settings on the next microtask. Repeated calls in the same task coalesce.
addRenderCallback
addRenderCallback(callback)Adds a callback to be executed after rendering. Only available on the lit engine — the native engine, which is the default, does not implement it.
Parameters
| Name | Type | Description |
|---|---|---|
| callback | Function | The callback to be executed |
Example
this.addRenderCallback(() => { console.log('Render complete');});setDefaultSettings
setDefaultSettings({settings, componentSpec})Sets default settings for a component.
Parameters
| Name | Type | Description |
|---|---|---|
| settings | Object | Default settings values |
| componentSpec | Object | Component specification object |
Example
this.setDefaultSettings({ settings: { theme: 'light', size: 'medium' }, componentSpec: mySpec});getSettingsFromConfig
getSettingsFromConfig({componentSpec, properties})Returns current settings including both attributes and properties.
Parameters
| Name | Type | Description |
|---|---|---|
| componentSpec | Object | Component specification object |
| properties | Object | Component properties object |
Returns
Current settings object.
Example
const settings = this.getSettingsFromConfig({ componentSpec: mySpec, properties: this.constructor.properties});createSettingsProxy
createSettingsProxy({componentSpec, properties})Creates a proxy object for reactive settings access.
Parameters
| Name | Type | Description |
|---|---|---|
| componentSpec | Object | Component specification object |
| properties | Object | Component properties object |
Returns
A Proxy object for reactive settings.
Example
this.settings = this.createSettingsProxy({ componentSpec, properties: this.constructor.properties});getUIClasses
getUIClasses({componentSpec, properties})Generates CSS classes based on component attributes.
Parameters
| Name | Type | Description |
|---|---|---|
| componentSpec | Object | Component specification object |
| properties | Object | Component properties object |
Returns
A string of space-separated CSS classes.
Example
const classes = this.getUIClasses({ componentSpec, properties: this.constructor.properties});isDarkMode
isDarkMode()Checks if the component is in dark mode.
Returns
Boolean indicating if dark mode is active, or undefined if server-side.
Example
if (this.isDarkMode()) { this.theme = 'dark';}$(selector, options)
$(selector, { root } = {})Queries the component’s rendered DOM, scoped to the nodes this component owns. Use $$ to descend into nested components’ shadow roots.
Parameters
| Name | Type | Description |
|---|---|---|
| selector | string | CSS selector to query |
| options | Object | Query configuration |
Options Object
| Name | Type | Description |
|---|---|---|
| root | Element | Root to query from |
| pierceShadow | boolean | Descend into nested shadow roots |
Returns
Query result set.
Example
const buttons = el.$('button');$$(selector)
$$(selector)Queries the component’s rendered DOM, descending into nested components’ shadow roots. Use $ to stay inside your own component and $$ to reach an element inside one you render.
Parameters
| Name | Type | Description |
|---|---|---|
| selector | string | CSS selector to query |
Returns
Query result set.
Example
const buried = el.$$('.inside-a-child-component');call
call(func, { firstArg, additionalArgs, args } = {})Calls a function with standard parameters.
Parameters
| Name | Type | Description |
|---|---|---|
| func | Function | Function to call |
| options | Object | Call configuration options |
Options Object
| Name | Type | Default | Description |
|---|---|---|---|
| firstArg | any | undefined | First argument to pass |
| additionalArgs | Array | undefined | Additional arguments |
| args | Array | [component, $] | Default arguments |
Example
this.call(callback, { firstArg: 'value', additionalArgs: ['extra'], args: [this.component, this.$]});