@bodil/dom
    Preparing search index...

    Class ComponentAbstract

    Base class for web components.

    Hierarchy (View Summary)

    Implements

    Advanced

    renderOptions: RenderOptions = ...
    renderRoot: HTMLElement | ShadowRoot = ...
    shadowRootOptions: ShadowRootInit = ...
    • get abortSignal(): AbortSignal

      An AbortSignal which will trigger when this component is disconnected from the DOM.

      This can be passed along to asynchronous tasks such as fetch initiated by this component, which will then be aborted automatically if the component is removed from the DOM.

      Returns AbortSignal

    • Adds a controller to the host, which sets up the controller's lifecycle methods to be called with the host's lifecycle.

      Parameters

      Returns void

    • Create the component's render root.

      By default, this creates a ShadowRoot and attaches it to the component.

      If you don't want to use a shadow DOM, you can override this method to just return this, which causes the component's contents to render as direct children of the component itself.

      Returns HTMLElement | ShadowRoot

    • Register a function which will be executed whenever an instance of this class is constructed.

      Parameters

      Returns void

    Declarations

    emits: object

    Declares the events this element can emit.

    deps: Deps = []

    Declare the web components this element will be using.

    This is a convenient place to make sure these web components will be defined when your component is rendered. It has no effect otherwise.

    class MyComponent extends Component {
    static deps: Deps = [ MySubcomponent, MyOtherSubcomponent ];
    }

    Declare CSS style sheets which will be installed for this web component.

    Style sheets can be either CSSStyleSheet objects, Lit template CSSResults, or strings.

    If a superclass also declares the styles property, this list will be appended to the superclass's list.

    class MyComponent extends Component {
    static styles = css`
    :host {
    border: 2px solid red;
    }
    `;
    }

    Events

    • Construct an event using the provided name and constructor.

      The constructor will be called with the name as its first argument, followed by any subsequent arguments provided after the constructor.

      Type Parameters

      • K extends never
      • E extends never
      • C extends new (type: string, ...args: Args) => E
      • Args extends any[]

      Parameters

      • name: K
      • constructor: C
      • ...args: Args

      Returns E

      this.emitEvent("click", MouseEvent, { button: 2 });
      // emits: new MouseEvent("click", { button: 2 });

    Lifecycle

    • This lifecycle callback is called each time this component is connected to the DOM.

      Returns void

    • This lifecycle callback is called each time this component is disconnected from the DOM.

      Returns void

    • This lifecycle callback is called every time a property decorated with the @require decorator has changed, but only when every property marked as such is not undefined.

      Returns void

    • This lifecycle callback is called each time an update has completed.

      Returns void

    Queries

    • If an element that is either inside this element's shadow root or is a child of this element (ie. slotted) currently has focus, return that element. Otherwise, return null.

      Returns Element | null

    Render

    • get hasStabilised(): Promise<void>

      A Promise which resolves when this component has completed its first update and considers itself stabilised, according to the Component.stabilise method.

      By default, a component considers itself stabilised when all of its children which are also Components are reporting as stabilised.

      Returns Promise<void>

    • get isUpdatePending(): boolean

      True if this component had scheduled an update which has not yet started.

      Returns boolean

    • Render the component's contents.

      This function should return a Lit renderable value, usually an html template.

      Returns unknown

      class MyComponent extends Component {
      protected override render() {
      return html`
      <h1>Hello Joe!</h1>
      `;
      }
      }
    • Return a Promise which resolves when this component considers itself to have stabilised.

      The default implementation waits for any children which are also Components to report that they have also stabilised.

      Returns Promise<void>

    Resources

    • Register a Disposable for automatic disposal when this component is disposed.

      Parameters

      • disposifiable: undefined

      Returns undefined

    • Register a Disposable for automatic disposal when this component is disposed.

      Parameters

      • disposifiable: null

      Returns null

    • Register a Disposable for automatic disposal when this component is disposed.

      Parameters

      • disposifiable: Disposifiable

      Returns Disposable

    • Register a Disposable for automatic disposal when this component is disposed.

      Parameters

      • disposifiable: Disposifiable | undefined

      Returns Disposable | undefined

    • Register a Disposable for automatic disposal when this component is disposed.

      Parameters

      • disposifiable: Disposifiable | null | undefined

      Returns Disposable | null | undefined

    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: Disposifiable
      • secondDisposable: Disposifiable
      • ...disposifiables: Disposifiable[]

      Returns Disposable[]

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }
    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: undefined

      Returns undefined

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }
    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: null

      Returns null

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }
    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: Disposifiable

      Returns Disposable

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }
    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: Disposifiable | undefined

      Returns Disposable | undefined

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }
    • Attach a Disposable to the component's connected/disconnected lifecycle state.

      This causes the Disposable to be disposed automatically when the component is disconnected. The common pattern for this is for resources, such as event listeners, allocated in Component.connectedCallback to be registered for automatic deallocation during Component.disconnectedCallback.

      Parameters

      • disposifiable: Disposifiable | null | undefined

      Returns Disposable | null | undefined

      protected override connectedCallback() {
      super.connectedCallback();
      this.useWhileConnected(this.on("click", this.handleClick.bind(this)));
      }