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

Usage

Shows an ephemeral "← → to navigate" hint anchored to the focused item the first time a roving-tabindex composite (Toolbar, TabList, SegmentedControl, etc.) receives keyboard focus. It teaches sighted keyboard users that arrow keys move within the group. The hint renders arrow keys with Kbd in the top layer (popover="manual") and is CSS-anchor-positioned to the focused element, so overflow containers never clip it. It auto-dismisses on the first arrow press, on timeout, or on blur, and does not re-show for that instance. Toolbar, TabList, and SegmentedControl wire this in automatically; reach for the hook directly only when building a custom roving-tabindex widget.
ts
import { hooks } from '@astryx-svelte/core/hooks';

Best practices

GuidancePractices
DoCompose the returned onFocus/onKeyDown with your existing focus handlers rather than replacing them: call onKeyDown first (it only dismisses, never prevents), then your navigation handler.
DoRender hintElement as the last child of the composite container; it is position:fixed in the top layer and aria-hidden, so it never affects layout or the accessibility tree.
DoMatch orientation to the arrow keys your widget actually responds to so the hint shows the correct icons.
Don'tUse for single controls or widgets without roving-tabindex navigation; the hint only makes sense where arrows move focus within a group.

Parameters

ParameterTypeDefaultDescription
options () => UseKeyboardHintOptionsConfiguration object for the keyboard hint.
options.orientation 'horizontal' | 'vertical' | 'both''horizontal'Which arrow-key axis the composite navigates, controlling which arrow icons the hint shows (← → for horizontal, ↑ ↓ for vertical, all four for both).
options.dismissAfterMs number3000Milliseconds before the hint auto-dismisses after appearing.
options.isEnabled booleantrueWhether the hint is enabled. Set to false to suppress it for a specific instance (e.g. a disabled or read-only widget).

Returns

FieldTypeDefaultDescription
hintElement string | SnippetThe popover hint element to render inside the composite container (as the last child). Portals to the top layer via popover="manual", renders arrow keys with Kbd, and manages its own visibility; render it unconditionally.

A Svelte hook cannot return markup. This hook returns state only; render its companion component and pass the hook’s value to it.Upstream declares ReactNode.

onFocus (e: FocusEvent) => voidAttach to the container onFocus. Shows the hint on the first keyboard-focus (:focus-visible) entry from outside the composite.
onBlur (e: FocusEvent) => voidAttach to the container onBlur. Hides the hint when focus leaves the composite entirely, and re-anchors when focus moves within.
onKeyDown (e: KeyboardEvent) => voidAttach to the container onKeyDown. Dismisses the hint on the first arrow press (the user has discovered the interaction). Never prevents default or stops propagation.

Examples

Common configurations, variations, and states.
useKeyboardHint — Arrow-key Hint
Toolbar shows an ephemeral "← → to navigate" hint on first keyboard focus via useKeyboardHint, teaching sighted keyboard users that arrows move within the group.