useClickableContainer @astryx-svelte/core v0.3.0 · hooks

Usage

Makes a container element clickable while preserving nested interactive element behavior. Solves the "nested interactive elements" problem: when a card is clickable but contains buttons/links, clicking those should NOT trigger the card's action. Detects interactive ancestors between the click target and the container, and ignores text selections. Supports href navigation (including middle-click and Ctrl/Cmd+click for new tabs).
ts
import { hooks } from '@astryx-svelte/core/hooks';

Best practices

GuidancePractices
DoAttach both onClick and onMouseUp to the container element for full click handling including middle-click.
DoUse inside ClickableCard or SelectableCard for the standard card interaction pattern.
Don'tUse when the entire container is a single interactive element; just use a <button> or <a> directly.

Parameters

ParameterTypeDefaultDescription
options Required () => UseClickableContainerOptionsConfiguration object for the clickable container.
options.container Required upstream: options.containerRefHTMLElement | nullRef to the outer container element.
options.interactive upstream: options.interactiveRefHTMLElement | nullRef to the primary interactive element inside (link, button). If no onClick or href is provided, clicks are proxied to this element.
options.onclick upstream: options.onClick(event: MouseEvent) => voidClick handler fired when the container surface (not a nested interactive element) is clicked.
options.href stringNavigation URL. When provided, clicking the container navigates to this URL.
options.target stringLink target (e.g., '_blank'). Used with href for navigation behavior.
options.disabled booleanfalseWhether the container is disabled.

Returns

FieldTypeDefaultDescription
onclick upstream: onClick(event: MouseEvent) => voidClick handler to attach to the container element.
onmouseup upstream: onMouseUp(event: MouseEvent) => voidMouse up handler to attach to the container (handles middle-click navigation for href).