Navigated to /docs/core/api/components-and-dom

Components, JSX, and DOM API

Component contracts, JSX output, roots, refs, directives, focus, observers, and transitions from the root package.

Components, JSX, and DOM exports

35 public exports, grouped under their canonical import boundary.

@tavojs/core

Canonical import boundary for every symbol in this section.

autoFocus#

autoFocus<T extends HTMLElement = HTMLElement>(options?: FocusOptions | undefined): ElementDirective<T>

Creates a directive that focuses the element after it is mounted.

Related guide

captureFocusRestore#

captureFocusRestore(documentRef?: Document | undefined): () => void

Captures current focus and returns a function that restores it later.

Related guide

Child#

type Child = Primitive | VNode | Child[];

Defines the child contract used by the application runtime.

Related guide

ClassName#

type ClassName = string | string[];

Defines the class name contract used by the application runtime.

Related guide

Component#

type Component<P extends Record<string, unknown> = Record<string, unknown>> = (props: PropsWithChildren<P>) => Child;

Defines the component contract used by the application runtime.

Related guide

createDirective#

createDirective<T extends HTMLElement = HTMLElement>(directive: ElementDirective<T>): ElementDirective<T>

Creates a reusable element directive from a function.

Related guide

createListRefs#

createListRefs<K extends string | number, T extends Element = Element>(): { get(key: K): DomRefObject<T>; delete(key: K): boolean; clear(): void; entries(): IterableIterator<[K, DomRefObject<T>]>; }

Creates a keyed collection of refs for dynamic lists.

Related guide

createRef#

createRef<T extends Element = Element>(): DomRefObject<T>

Creates a mutable DOM ref object for controller-owned element access.

Related guide

createRoot#

createRoot(container: Element | DocumentFragment): Root

Creates root for the application runtime.

Related guide

DomRef#

type DomRef<T extends Element = Element> = DomRefObject<T> | DomRefCallback<T> | null | undefined;

Public DOM ref value accepted by intrinsic JSX elements.

Related guide

DomRefCallback#

type DomRefCallback<T extends Element = Element> = (node: T | null) => void;

Callback ref shape for one-off DOM element access.

Related guide

DomRefObject#

type DomRefObject<T extends Element = Element> = {
    current: T | null;
};

Object ref shape used by MVC controllers to keep direct DOM handles.

Related guide

ElementCleanup#

type ElementCleanup = () => void;

Defines the element cleanup contract used by the application runtime.

Related guide

ElementDirective#

type ElementDirective<T extends HTMLElement = HTMLElement> = (element: T) => void | ElementCleanup;

Defines the element directive contract used by the application runtime.

Related guide

ElementDirectiveInput#

type ElementDirectiveInput<T extends HTMLElement = HTMLElement> = ElementDirective<T> | Array<ElementDirective<T> | null | undefined | false> | null | undefined | false;

Defines the element directive input contract used by the application runtime.

Related guide

ElementTarget#

type ElementTarget<T extends Element = Element> = T | DomRefObject<T>;

Defines the element target contract used by the application runtime.

Related guide

focusFirst#

focusFirst(root: ParentNode, options?: FocusOptions | undefined): HTMLElement | null

Focuses the first focusable descendant inside a root node.

Related guide

focusFirstInvalid#

focusFirstInvalid(root: ParentNode, options?: FocusOptions | undefined): HTMLElement | null

Focuses the first invalid form control inside a root node.

Related guide

Fragment#

Fragment: typeof Fragment

Provides fragment behavior for the application runtime.

Related guide

getFocusableElements#

getFocusableElements(root: ParentNode): HTMLElement[]

Finds focusable descendants in DOM order.

Related guide

h#

h(type: NodeType, props: (Record<string, unknown> & { children?: Child }) | null, ...children: Child[]): VNode

Provides h behavior for the application runtime.

Related guide

mergeRefs#

mergeRefs<T extends Element>(...refs: DomRef<T>[]): DomRefCallback<T>

Combines several refs into one callback ref.

Related guide

observeIntersection#

observeIntersection<T extends Element>(target: ElementTarget<T>, listener: IntersectionObserverCallback, options?: IntersectionObserverInit | undefined): Unsubscribe

Observes element viewport intersection changes and returns an unsubscribe function.

Related guide

observeMutation#

observeMutation<T extends Node>(target: T | { current: T | null; }, listener: MutationCallback, options?: MutationObserverInit | undefined): Unsubscribe

Observes DOM mutations and returns an unsubscribe function.

Related guide

observeResize#

observeResize<T extends Element>(target: ElementTarget<T>, listener: ResizeObserverCallback, options?: ResizeObserverOptions | undefined): Unsubscribe

Observes element size changes and returns an unsubscribe function.

Related guide

PropsWithChildren#

type PropsWithChildren<P extends Record<string, unknown> = Record<string, unknown>> = P & {
    children?: Child;
};

Defines the props with children contract used by the application runtime.

Related guide

render#

render(node: Child, container: Element | DocumentFragment): void

Renders for the application runtime.

Related guide

renderToString#

renderToString(node: Child): string

Renders to string for the application runtime.

Related guide

Root#

type Root = {
    render(node: Child): void;
    hydrate(node: Child): void;
    unmount(): void;
};

Defines the root contract used by the application runtime.

Related guide

setRef#

setRef<T extends Element>(ref: DomRef<T>, node: T | null): void

Sets a ref to a DOM node or null. Useful when writing framework adapters.

Related guide

transition#

transition<T extends HTMLElement = HTMLElement>(options?: TransitionOptions<T> | undefined): ElementDirective<T>

Creates a small class/callback transition directive for mounted elements.

Related guide

TransitionClassNames#

type TransitionClassNames = {
    enter?: string;
    enterActive?: string;
    leave?: string;
    leaveActive?: string;
};

Defines the transition class names contract used by the application runtime.

Related guide

TransitionOptions#

type TransitionOptions<T extends HTMLElement = HTMLElement> = {
    classes?: TransitionClassNames;
    onEnter?: (element: T) => void;
    onLeave?: (element: T) => void;
};

Configures transition in the application runtime.

Related guide

trapFocus#

trapFocus(root: HTMLElement): () => void

Keeps Tab navigation inside a container until the returned cleanup runs.

Related guide

VNode#

type VNode = {
    type: NodeType;
    props: {
        children: Child[];
        [key: string]: unknown;
    };
};

Defines the v node contract used by the application runtime.

Related guide