Spatial Menu (WIP)
A collection of keyboard-navigable items, that can be displayed in a grid.
































































































Props
Features
Section titled “Features”- 💪 It works
TODO
API Reference
Section titled “API Reference”Constructor Props
The props that are passed when calling
new SpatialMenu()
new SpatialMenu()
export type SpatialMenuProps<T> = { /** * The currently highlighted value. */ highlighted?: MaybeGetter<T | null | undefined>;
/** * Called when the highlighted value changes. */ onHighlightChange?: (highlighted: T | null) => void;
onSelect?: (value: T) => void;
/** * Whether navigation should wrap around when reaching the edges. * @default false */ wrap?: MaybeGetter<boolean>;
/** * Scroll behavior when highlighting an item with the keyboard. * `null` to disable scrolling. * * @default "smooth" */ scrollBehavior?: MaybeGetter<"smooth" | "instant" | "auto" | null>;
/** * The maximum distance a the centerX of an item can be in relation * to the highlighted item when navigating vertically with the keyboard. * * Set to `null` to disable. * * @default null */ maxDistanceX?: MaybeGetter<number | null>;
/** * The maximum distance a the centerY of an item can be in relation * to the highlighted item when navigating horizontally with the keyboard. * * Set to `null` to disable. * * @default 16 */ maxDistanceY?: MaybeGetter<number | null>;};
export type SpatialMenuProps<T> = { /** * The currently highlighted value. */ highlighted?: MaybeGetter<T | null | undefined>;
/** * Called when the highlighted value changes. */ onHighlightChange?: (highlighted: T | null) => void;
onSelect?: (value: T) => void;
/** * Whether navigation should wrap around when reaching the edges. * @default false */ wrap?: MaybeGetter<boolean>;
/** * Scroll behavior when highlighting an item with the keyboard. * `null` to disable scrolling. * * @default "smooth" */ scrollBehavior?: MaybeGetter<"smooth" | "instant" | "auto" | null>;
/** * The maximum distance a the centerX of an item can be in relation * to the highlighted item when navigating vertically with the keyboard. * * Set to `null` to disable. * * @default null */ maxDistanceX?: MaybeGetter<number | null>;
/** * The maximum distance a the centerY of an item can be in relation * to the highlighted item when navigating horizontally with the keyboard. * * Set to `null` to disable. * * @default 16 */ maxDistanceY?: MaybeGetter<number | null>;};
Methods
The methods returned from
new SpatialMenu()
new SpatialMenu()
-
getItem
(value: T,options?: Pick<SpatialMenuItemProps<T>, "onSelect"> | undefined,) => SpatialMenuItem<T>(value: T,options?: Pick<SpatialMenuItemProps<T>, "onSelect"> | undefined,) => SpatialMenuItem<T>
Properties
The properties returned from
new SpatialMenu()
new SpatialMenu()
-
onSelect
((value: T) => void) | undefined((value: T) => void) | undefined -
wrap
booleanboolean -
scrollBehavior
"auto" | "smooth" | "instant" | null"auto" | "smooth" | "instant" | null -
maxDistanceX
number | nullnumber | null -
maxDistanceY
number | nullnumber | null -
selectionMode
"keyboard" | "mouse""keyboard" | "mouse" -
highlighted
T | nullT | null -
root
{readonly [x: symbol]: (node: HTMLElement) => () => voidreadonly "data-melt-spatial-menu-root": ""readonly tabindex: 0readonly onkeydown: (e: KeyboardEvent) => void}{readonly [x: symbol]: (node: HTMLElement) => () => voidreadonly "data-melt-spatial-menu-root": ""readonly tabindex: 0readonly onkeydown: (e: KeyboardEvent) => void}The root element. -
input
{readonly [x: symbol]: (node: HTMLInputElement) => () => voidreadonly "data-melt-spatial-menu-input": ""readonly onkeydown: (e: KeyboardEvent) => void}{readonly [x: symbol]: (node: HTMLInputElement) => () => voidreadonly "data-melt-spatial-menu-input": ""readonly onkeydown: (e: KeyboardEvent) => void}