giggles
Focus

API Reference

API reference for the focus system

useFocusScope()

Creates a scope node in the focus tree and returns a reactive handle. Wrap children with <FocusScope handle={scope}> so nested hooks know their parent.

Type Signature
function useFocusScope(options?: FocusScopeOptions): FocusScopeHandle

FocusScopeOptions

Prop

Type

FocusScopeHandle

Prop

Type

hasFocus is how a container knows it's in the active focus path — use it for visual feedback, conditional rendering, or any logic that depends on whether the user's attention is inside this scope. isPassive reflects the current navigation mode: when true, this scope has yielded and the parent's bindings are active — surface it so the user knows which level they're navigating.

The navigation methods (next, prev, drillIn, etc.) are stable references, safe to call from event handlers. Call them imperatively, not during render.

FocusScopeHelpers

The subset of FocusScopeHandle passed as the argument to the keybindings factory function.

Prop

Type

FocusScope

Sets the parent scope for all children rendered inside it. Children that call useFocusNode() or useFocusScope() without an explicit parent option register under this scope.

Every useFocusScope() call must have exactly one corresponding <FocusScope> rendered. Omitting it throws a GigglesError — without it, children silently register under the wrong parent scope and navigation breaks.

Type Signature
function FocusScope({ handle, children }: {
  handle: FocusScopeHandle;
  children: React.ReactNode;
}): JSX.Element

Prop

Type

useFocusNode()

Registers a component as a leaf node in the focus tree. Use this when the component itself is the focusable target — a list item, a form field, a button. If the component contains other focusable children, use useFocusScope instead.

Type Signature
function useFocusNode(options?: FocusNodeOptions): FocusNodeHandle

FocusNodeOptions

Prop

Type

FocusNodeHandle

Prop

Type

The FocusNodeHandle type can be imported for typing component props:

Typing Props
import type { FocusNodeHandle } from 'giggles';

function MyComponent({ focus }: { focus: FocusNodeHandle }) {
  return <Text color={focus.hasFocus ? 'green' : 'white'}>Item</Text>;
}

On this page