mazey
    Preparing search index...

    Function resolveElementTarget

    • Resolve an element from a direct element, a selector, an optionally unwrapped value, or a component-like object containing an $el element. Selector queries are scoped to the supplied root. Invalid selectors, unmatched selectors, null, and unsupported values return null.

      Usage:

      import { resolveElementTarget } from "mazey";

      const element = resolveElementTarget("#dialog", {
      root: document,
      defaultElement: document.documentElement,
      });
      console.log(element?.id);

      Output:

      dialog
      

      Ref-like values can be supported without coupling Mazey to a framework:

      const elementRef = { value: document.querySelector("#dialog") };
      const element = resolveElementTarget(elementRef, {
      root: document,
      unwrap: value => value?.value,
      });

      Parameters

      • target: unknown

        Direct element, selector, wrapped value, component-like value, or undefined.

      • options: ResolveElementTargetOptions

        Query root, optional default element, and optional unwrap adapter.

      Returns Element | null

      The resolved element, or null when the target cannot be resolved.

      Browser only unless compatible DOM objects are supplied. The function does not query or mutate the DOM when given a direct element. defaultElement is used only when target is undefined; an explicit null target resolves to null.