type
AccordionType
export type AccordionType = "single" | "multiple";Whether one section is open at a time, or any number of them.
Readiness: Implemented
API reference
Headless, accessible React components whose composition Flow checks, part of the Unified Toolchain for Flow.
Written from the source by uf doc when this site was built: the signature and the comment above each export, grouped by the specifier a program imports it from.
@uniflowed/uitype
AccordionTypeexport type AccordionType = "single" | "multiple";Whether one section is open at a time, or any number of them.
type
AvatarStatusexport type AvatarStatus = "loading" | "loaded" | "error";Where an avatar's image is between having been asked for and being there.
Three members rather than a loaded boolean, because the fallback's whole job is to tell the middle one from the last one: an image that has not arrived *yet* must not be replaced, and one that is never arriving must.
type
DateValueexport type DateValue = PlainDate | string;A date, however the caller had one to hand.
A string is accepted because value="2026-10-14" is what a form field, a URL parameter and a JSON payload all carry, and making every caller construct a PlainDate to pass one in would be ceremony. It is ISO 8601 — the format Temporal.PlainDate.from parses — and not a locale format: parsing 12/03/26 is a locale question that belongs to @uniflowed/temporal rather than to a UI package, and date-picker.js says what that means for a field a reader types into.
type
ActivationModeexport type ActivationMode = "automatic" | "manual";When a tab becomes the selected one.
type
DialogRoleexport type DialogRole = "dialog" | "alertdialog";What a screen reader is told the dialog is.
A union rather than a string, so role="alertdailog" is a type error at the call rather than a dialog announced as a div with a name — which is what a misspelt role produces, silently, in markup that looks correct.
Two members and not the whole of ARIA: these are the two roles that carry aria-modal, and a Dialog.Body that is a region or a complementary is a different component rather than this one with another string.
type
Edgeexport type Edge = "top" | "right" | "bottom" | "left";Which edge of the viewport a sheet is attached to.
Physical, and deliberately not logical: a design that puts a navigation sheet against the left of the screen means the left of the screen in any writing direction, the same way internal/anchor.js's Side does and for the same reason. What the writing direction changes is the reading order inside the sheet, which is the page's business rather than this component's.
A union rather than a string, so a typo is a type error at the call rather than a data-side="lft" no stylesheet matches and no test notices.
type
FieldSourceexport type FieldSource = {|
readonly invalid : boolean,
readonly required: boolean,
readonly disabled: boolean,
readonly busy : boolean,
/** What is wrong, or null while the field is valid. */
readonly message: string | null,
readonly control: Rest,
|};What a form library tells a field about one of its fields.
Facts, and no attributes: see the module header for why an aria-describedby in here would be the collision this type exists to end. control is the binding — the name, the ref the store attaches through, onChange, onBlur and the constraint attributes a progressive form emits — spread onto whatever element Field.Control renders, underneath the attributes the field computes.
# It is declared here and produced there
@uniflowed/form's useFieldSource builds one of these, so this type is the seam between the two packages — and it lives on this side only because the dependency can only run this way today: this package is on npm and that one is not, and tools/release/publishable.sh refuses a published package that depends on an unpublished one.
That is backwards, and ubugeeei-prod/uf#614 says so. It stands because declaring the type twice trades a documented edge for silent drift — a Field.Root accepting a shape useFieldSource no longer produces would type-check on both sides and fail only where they meet — and because the import is type-only, so no project installing @uniflowed/form loads, bundles or runs any of this package. #210 is the trigger: once @uniflowed/form publishes, this moves there and @uniflowed/ui imports it.
type
InputOtpKindexport type InputOtpKind = "numeric" | "alphanumeric";What a code is made of.
A union rather than a pattern string, because the answer decides three things at once — which characters survive typing and pasting, which keyboard a phone shows, and what the field's pattern says — and a caller who writes kind="numberic" should be told at the call rather than discover that their numeric field takes letters.
type
MenuSelectexport type MenuSelect = {
readonly defaultPrevented: boolean,
readonly preventDefault : () => mixed,
...
};The part of a click a menu item's onSelect may read and answer.
Inexact, because what arrives is React's synthetic event and this names only the two members the contract is about: calling preventDefault() keeps the menu open, and the component reads defaultPrevented afterwards to find out. A caller who wants the rest of the event has it — this is the promise, not the object.
component
Separatorexport component Separator(
decorative? : boolean = false,
orientation?: Orientation = "horizontal",
render? : RenderProp,
...rest : Rest
) { ... }A rule between two things, or a line that is only a line.
decorative is the whole component. Without it the element is a role="separator" a reader is told about; with it the element is hidden from the accessibility tree entirely.
<Separator /> <Separator orientation="vertical" /> <Separator decorative />
The decorative one gets aria-hidden and no role, rather than role="presentation" as well: a <div> has nothing to hide behind a presentation role, and one attribute that removes the element from the tree says the whole thing. Breadcrumb.Separator carries both because it is an <li>, whose listitem role would otherwise be counted.
aria-orientation is written out even for the horizontal case, where ARIA would default to it. It is the attribute a reader of this markup is looking for, and a default that is left implicit is a default somebody has to know.
render changes the element carrying that decision, not the decision itself: decorative rules stay hidden, semantic rules keep the separator role and orientation.
type
SidebarSideexport type SidebarSide = "left" | "right";Which side of the layout the sidebar is on.
Two members and not sheet.js's four, because a sidebar is never attached to the top or the bottom: a navigation rail across the top of a page is a header, with different semantics and a different component. <Sidebar.Root side="top"> is a type error, which is the point of naming the union rather than reusing Edge.
type
Sortexport type Sort = {|
readonly column : string,
readonly direction: "ascending" | "descending",
|};Which column a table is sorted by, and which way.
type
Urgencyexport type Urgency = "polite" | "assertive";How loudly a notification interrupts.
type
Notificationexport type Notification = {|
readonly id: string,
/** What a reader is told. A node, so a caller may render their own markup. */
readonly content: React.Node,
readonly urgency: Urgency,
/** How long it stays, in milliseconds, or null for one that never expires. */
readonly duration: number | null,
|};One notification in the queue.
type
ToastOptionsexport type ToastOptions = {|
readonly urgency? : Urgency,
readonly duration?: number | null,
|};What toast accepts beside the message.
type
ToastChangesexport type ToastChanges = {|
readonly content? : React.Node,
readonly urgency? : Urgency,
readonly duration?: number | null,
|};What updateToast may change about a notification already queued.
function
toastexport function toast(content: React.Node, options?: ToastOptions): string { ... }Show a notification, and hand back the id that identifies it later.
Callable from anywhere — an event handler, a catch, a Server Action's error path — because it is a function in a module rather than a hook.
toast("Saved"); toast("Could not save", { urgency: "assertive" }); const id = toast("Uploading…", { duration: null }); updateToast(id, { content: "Uploaded", duration: 4000 });
function
updateToastexport function updateToast(id: string, changes: ToastChanges): void { ... }Change a notification that is already queued.
"Uploading…" becoming "Uploaded" is one notification that changed, not two notifications — and a reader who is told the second thing without the first disappearing has been told the upload is both in progress and finished.
Changing the content of a notification that is on screen re-announces the region it is in, which is the point.
function
dismissToastexport function dismissToast(id: string): void { ... }Take a notification away, whether it expired, was dismissed, or was acted on.
function
dismissAllToastsexport function dismissAllToasts(): void { ... }Empty the queue.
For a route change that makes every pending notification stale, and for a test: the queue is one module-level value, so what one test queued is still there in the next one unless something clears it.
type
ToggleGroupTypeexport type ToggleGroupType = "single" | "multiple";Whether the set holds one answer or any number of them.
component
Checkboxexport component Checkbox(
checked? : boolean,
defaultChecked? : boolean = false,
indeterminate? : boolean = false,
onCheckedChange?: (checked: boolean) => void,
disabled? : boolean = false,
/** Submitted while checked. `"on"` when omitted, which is what a native checkbox sends. */
value? : string = "on",
name? : string,
children?: React.Node,
render? : RenderProp,
...rest : Rest
) { ... }A checkbox, which may also be mixed.
render is the escape hatch, and the implicit submission above is the reason it hands over onKeyDown rather than attaching it: whatever element a caller renders is the one Enter arrives on, and it is that element's form the key walks up to.
component
Progressexport component Progress(
value? : number | null = null,
min? : number = 0,
max? : number = 100,
valueText?: string,
children? : React.Node,
render? : RenderProp,
...rest : Rest
) { ... }How far along something is, or that it is under way at all.
value is null for a bar that does not know — the default, because a bar that has not been told anything genuinely does not know, and the safe answer has to be the honest one rather than "nothing has happened".
A name is the caller's: aria-label="Uploading" or an aria-labelledby pointing at a heading. A progress bar with no name is announced as "progressbar" and a reader is left to guess what is progressing, which is why every example in the documentation carries one.
Nothing here is drawn and nothing is measured for the caller — unlike Slider, whose value may be its own, a progress bar's value arrived as a prop, so the caller already has everything they need to size a bar with and a helpful custom property would only be their own arithmetic handed back.
render changes the element and not the accessibility contract: the progressbar role and value attributes are the props handed to the caller.
component
Switchexport component Switch(
checked? : boolean,
defaultChecked? : boolean = false,
onCheckedChange?: (checked: boolean) => void,
disabled? : boolean = false,
/** Submitted while on. `"on"` when omitted, the same default a checkbox uses. */
value? : string = "on",
name? : string,
children?: React.Node,
render? : RenderProp,
...rest : Rest
) { ... }A two-state switch: on or off.
render is the escape hatch, and on a switch it is what a caller with their own <Pressable> or a <div role="switch"> in a design system reaches for. type="button" is the one thing it does not hand over, because that is true of the element rather than of the switch.
component
Toggleexport component Toggle(
pressed? : boolean,
defaultPressed? : boolean = false,
onPressedChange?: (pressed: boolean) => void,
disabled? : boolean = false,
children? : React.Node,
render? : RenderProp,
...rest : Rest
) { ... }A button whose state stays applied: pressed or not.
render is the escape hatch. A caller-rendered element gets role="button" because it may be a link or a div; the native button branch keeps the role implicit and only adds type="button", which is true of the element rather than of the toggle behaviour.
type
PointerTypeexport type PointerType = "mouse" | "pen" | "touch" | "keyboard" | "virtual";The input that produced an interaction.
type
Modalityexport type Modality = "keyboard" | "pointer" | "virtual";Which kind of input a reader used most recently.
type
PhysicalPointerexport type PhysicalPointer = "mouse" | "pen" | "touch";A pointer with a position: what a hover, a drag or a long press can come from.
type
InteractionEventexport type InteractionEvent = {
readonly type : string,
readonly target : mixed,
readonly currentTarget : mixed,
readonly defaultPrevented: boolean,
readonly nativeEvent? : mixed,
readonly preventDefault : () => mixed,
readonly stopPropagation : () => mixed,
readonly key? : string,
readonly code? : string,
readonly repeat? : boolean,
readonly button? : number,
readonly buttons? : number,
readonly detail? : number,
readonly pointerId? : number,
readonly pointerType? : string,
readonly clientX? : number,
readonly clientY? : number,
readonly width? : number,
readonly height? : number,
readonly pressure? : number,
readonly relatedTarget? : mixed,
readonly altKey? : boolean,
readonly ctrlKey? : boolean,
readonly metaKey? : boolean,
readonly shiftKey? : boolean,
...
};The part of an event these hooks read, from React or from the DOM.
Inexact and named for the reason internal/merge-props.js gives for PartEvent: what arrives is React's synthetic event, uf does not merge Flow's jsx.js environment so nothing models one, and these are the members the handlers here actually read. A handler written for this type accepts a native event as well, which is what lets a listener on the document share its reading of a key or a pointer with a handler on the element.
type
InteractionPropsexport type InteractionProps = { readonly key?: empty, readonly [string]: mixed };Props on their way onto an element, as mergeProps returns them.
key is named out of the indexer for the reason Rest in internal/merge-props.js gives at length: an indexer answers mixed for every name, React's key is string | number, and spreading one onto an element is rejected for a property that cannot be there.
type
PressEventexport type PressEvent = {|
readonly type: "pressstart" | "pressend" | "pressup" | "press",
/** The input that made it. */
readonly pointerType: PointerType,
/** The element the press belongs to. */
readonly target : HTMLElement,
readonly altKey : boolean,
readonly ctrlKey : boolean,
readonly metaKey : boolean,
readonly shiftKey: boolean,
/** Where the pointer was, from the element's left edge; nought for a key or a screen reader. */
readonly x: number,
/** Where the pointer was, from the element's top edge; nought for a key or a screen reader. */
readonly y: number,
/**
* Let a pressable around this one receive the same press.
*
* By default a press belongs to the innermost pressable element; see the
* module header for why that is recorded rather than stopped.
*/
readonly continuePropagation: () => void,
|};A moment in a press.
type
PressOptionsexport type PressOptions = {|
/** Leave text selection alone while a pointer is down. */
readonly allowTextSelectionOnPress?: boolean,
/**
* No press, no hover state, and no activation of the element either: a click
* on a disabled link or submit button is prevented.
*/
readonly isDisabled?: boolean,
/** The press completed, over the element. */
readonly onPress?: (event: PressEvent) => mixed,
/** `isPressed` changed. */
readonly onPressChange?: (isPressed: boolean) => mixed,
/** The press ended, pressed or not: released, left, cancelled or taken away. */
readonly onPressEnd?: (event: PressEvent) => mixed,
/** A press began, or a pointer still down came back over the element. */
readonly onPressStart?: (event: PressEvent) => mixed,
/** A pointer or a key was released over the element, whether or not the press began there. */
readonly onPressUp?: (event: PressEvent) => mixed,
/** Keep focus where it is when a pointer presses the element. */
readonly preventFocusOnPress?: boolean,
/** A pointer that leaves takes the press back for good, rather than until it returns. */
readonly shouldCancelOnPointerExit?: boolean,
|};What usePress is told.
type
PressPropsexport type PressProps = {|
readonly onClick : (event: InteractionEvent) => void,
readonly onDragStart : (event: InteractionEvent) => void,
readonly onKeyDown : (event: InteractionEvent) => void,
readonly onMouseDown : (event: InteractionEvent) => void,
readonly onPointerDown : (event: InteractionEvent) => void,
readonly onPointerEnter: (event: InteractionEvent) => void,
readonly onPointerLeave: (event: InteractionEvent) => void,
readonly onPointerUp : (event: InteractionEvent) => void,
|};The handlers usePress needs on the element.
type
PressResultexport type PressResult = {|
/** Whether a press is under way and over the element. */
readonly isPressed: boolean,
/** Spread onto the element, or merged with other hooks' props by `mergeProps`. */
readonly pressProps: PressProps,
|};What usePress hands back.
hook
usePressexport hook usePress(options?: PressOptions): PressResult { ... }A press, from a pointer, a key or assistive technology, with one set of events.
const { isPressed, pressProps } = usePress({ onPress: () => save() }); return <div {...pressProps} data-pressed={isPressed} role="button" tabIndex={0}>Save</div>;
The module header states every rule and what each one prevents. The events arrive in the order pressstart, pressup, pressend, press, and onPressChange reports every change to isPressed between them.
type
InteractOutsideRefexport type InteractOutsideRef = { readonly current: HTMLElement | null, ... };A ref to an element a press may land in without being "outside".
type
InteractOutsideOptionsexport type InteractOutsideOptions = {|
/** Hear nothing: what an overlay that is closed asks for. */
readonly isDisabled?: boolean,
/** A whole gesture began and ended outside every ref. */
readonly onInteractOutside: (event: Event) => mixed,
/**
* The elements that are not "outside".
*
* The overlay, and whatever opens it: a trigger sits outside the overlay's
* own box and is not "outside" for this purpose, because dismissing there
* and then letting the trigger's own click reopen makes a press on it a
* no-op that flickers.
*
* Read when an event arrives rather than when the listener is attached, so a
* ref that is still null on the commit that opened the overlay is not a
* listener that quietly never worked.
*/
readonly refs: $ReadOnlyArray<InteractOutsideRef>,
|};What useInteractOutside is told.
hook
useInteractOutsideexport hook useInteractOutside(options: InteractOutsideOptions): void { ... }A press that began *and* ended outside an element: what dismisses an overlay.
useInteractOutside({ isDisabled: !open, onInteractOutside: close, refs: [bodyRef, triggerRef], });
The module header says what a bare pointerdown gets wrong and why this waits for the end of the gesture. One hook rather than a copy in each overlay, because a copy is how the answers drift apart: the case that a scroll must not dismiss is one rule, not five.
function
getInteractionModalityexport function getInteractionModality(): Modality | null { ... }The input used most recently, or null when nothing is listening for it.
For an event handler deciding something now — whether focus it is about to move should draw a ring. A render that depends on the answer reads useInteractionModality instead, which also keeps the listening on.
hook
useInteractionModalityexport hook useInteractionModality(): Modality | null { ... }The input used most recently, re-rendering when it changes; null before any.
type
FocusVisibleResultexport type FocusVisibleResult = {|
/** Whether focus, wherever it is, should be drawn: anything but a pointer came last. */
readonly isFocusVisible: boolean,
|};What useFocusVisible hands back.
hook
useFocusVisibleexport hook useFocusVisible(): FocusVisibleResult { ... }Whether a focus ring should be drawn, for the page as a whole.
useFocusRing is the one a control wants — it adds whether the control has focus. This is for something that draws focus elsewhere, or an overlay that decides whether to draw one on what it focused.
type
FocusRingOptionsexport type FocusRingOptions = {|
/** Count focus anywhere inside the element, not only on the element itself. */
readonly within?: boolean,
|};What useFocusRing is told.
type
FocusRingPropsexport type FocusRingProps = {|
readonly onBlur : (event: InteractionEvent) => void,
readonly onFocus: (event: InteractionEvent) => void,
|};The handlers useFocusRing needs on the element.
type
FocusRingResultexport type FocusRingResult = {|
readonly focusProps: FocusRingProps,
/** Whether the element — or, with `within`, something inside it — has focus. */
readonly isFocused: boolean,
/** Whether it has focus and the input that came last was not a pointer. */
readonly isFocusVisible: boolean,
|};What useFocusRing hands back.
hook
useFocusRingexport hook useFocusRing(options?: FocusRingOptions): FocusRingResult { ... }Whether an element has focus, and whether that focus should be drawn.
const { focusProps, isFocusVisible } = useFocusRing(); return <button {...focusProps} data-focus-visible={isFocusVisible || undefined}>Save</button>;
React Aria's version takes isTextInput and autoFocus as well. Neither is needed here: typing into a text field is ignored for the whole document, and focus that arrives before any input is drawn already, because nothing has made it a pointer's.
type
HoverEventexport type HoverEvent = {|
readonly type: "hoverstart" | "hoverend",
/** A mouse or a pen: a finger has no hover. */
readonly pointerType: "mouse" | "pen",
readonly target : HTMLElement,
|};A hover beginning or ending.
type
HoverOptionsexport type HoverOptions = {|
/** No hover; a hover in progress ends. */
readonly isDisabled? : boolean,
readonly onHoverChange?: (isHovering: boolean) => mixed,
readonly onHoverEnd? : (event: HoverEvent) => mixed,
readonly onHoverStart? : (event: HoverEvent) => mixed,
|};What useHover is told.
type
HoverPropsexport type HoverProps = {|
readonly onPointerEnter: (event: InteractionEvent) => void,
readonly onPointerLeave: (event: InteractionEvent) => void,
|};The handlers useHover needs on the element.
type
HoverResultexport type HoverResult = {|
readonly hoverProps: HoverProps,
readonly isHovered : boolean,
|};What useHover hands back.
hook
useHoverexport hook useHover(options?: HoverOptions): HoverResult { ... }Whether a mouse or a pen is over an element — and never a finger.
const { hoverProps, isHovered } = useHover({ onHoverStart: preview });
A touch pointer is ignored, and so is a mouse pointer within half a second of a touch; see the module header for the iOS behaviour that makes the second rule necessary.
type
LongPressEventexport type LongPressEvent = {|
readonly type : "longpressstart" | "longpressend" | "longpress",
readonly pointerType: PhysicalPointer,
readonly target : HTMLElement,
readonly altKey : boolean,
readonly ctrlKey : boolean,
readonly metaKey : boolean,
readonly shiftKey : boolean,
readonly x : number,
readonly y : number,
|};A moment in a long press.
type
LongPressOptionsexport type LongPressOptions = {|
/**
* What a reader is told a long press does, as the element's description.
*
* A long press is invisible. A component that offers one owes a keyboard way
* to do the same thing, and this is where it says what that is — "Long press
* or press Shift+F10 for more actions".
*/
readonly accessibilityDescription?: string,
readonly isDisabled? : boolean,
/** The press lasted long enough. The press underneath is cancelled, and its click refused. */
readonly onLongPress?: (event: LongPressEvent) => mixed,
/** The press that might have been a long one ended, whichever it turned out to be. */
readonly onLongPressEnd?: (event: LongPressEvent) => mixed,
/** A press began that could become a long press. */
readonly onLongPressStart?: (event: LongPressEvent) => mixed,
/**
* Which pointers a long press may come from; every one of them by default.
*
* A context menu's long press is a touch's, because a mouse has a right
* button for it — and a mouse held down on a row is starting a text
* selection or a drag, not asking for a menu.
*/
readonly pointerTypes?: $ReadOnlyArray<PhysicalPointer>,
/** How long, in milliseconds. 500 by default. */
readonly threshold?: number,
|};What useLongPress is told.
type
LongPressPropsexport type LongPressProps = {|
...PressProps,
readonly "aria-describedby"?: string,
|};The handlers and the description useLongPress needs on the element.
type
LongPressResultexport type LongPressResult = {|
readonly longPressProps: LongPressProps,
|};What useLongPress hands back.
hook
useLongPressexport hook useLongPress(options?: LongPressOptions): LongPressResult { ... }A press held long enough to mean something else.
const { longPressProps } = useLongPress({ accessibilityDescription: "Long press or press Shift+F10 for more actions", onLongPress: openMenu, pointerTypes: ["touch", "pen"], });
Merged with a usePress on the same element, a long press cancels the press — onPress does not follow onLongPress. See the module header for why it has no keyboard of its own.
type
MovePointerTypeexport type MovePointerType = PhysicalPointer | "keyboard";The input a move came from.
type
MoveStartEventexport type MoveStartEvent = {|
readonly type : "movestart",
readonly pointerType: MovePointerType,
...Modifiers,
|};A move beginning: the first movement after a pointer went down, or an arrow key.
type
MoveMoveEventexport type MoveMoveEvent = {|
readonly type : "move",
readonly pointerType: MovePointerType,
/** How far right since the last event; negative is left. */
readonly deltaX: number,
/** How far down since the last event; negative is up. */
readonly deltaY: number,
...Modifiers,
|};A movement, in pixels for a pointer and in steps of one for a key.
type
MoveEndEventexport type MoveEndEvent = {|
readonly type : "moveend",
readonly pointerType: MovePointerType,
...Modifiers,
|};A move ending.
type
MoveOptionsexport type MoveOptions = {|
readonly onMove? : (event: MoveMoveEvent) => mixed,
readonly onMoveEnd? : (event: MoveEndEvent) => mixed,
readonly onMoveStart?: (event: MoveStartEvent) => mixed,
|};What useMove is told.
type
MovePropsexport type MoveProps = {|
readonly onKeyDown : (event: InteractionEvent) => void,
readonly onPointerDown: (event: InteractionEvent) => void,
|};The handlers useMove needs on the element.
type
MoveResultexport type MoveResult = {|
readonly moveProps: MoveProps,
|};What useMove hands back.
hook
useMoveexport hook useMove(options?: MoveOptions): MoveResult { ... }How far a pointer or an arrow key moved something, one event at a time.
const { moveProps } = useMove({ onMove: ({ deltaX }) => resizeBy(deltaX) });
A move begins with the first movement rather than with the press, so a click that does not move is not a drag. Physical directions, not reading ones: a caller whose axis runs the other way in a right-to-left page — a slider — turns deltaX round itself, because only it knows that its axis does.
type
KeyboardInteractionexport type KeyboardInteraction = {|
readonly type : "keydown" | "keyup",
readonly key : string,
readonly code : string,
readonly repeat : boolean,
readonly altKey : boolean,
readonly ctrlKey : boolean,
readonly metaKey : boolean,
readonly shiftKey: boolean,
/** The element the key went to, which may be inside the one listening. */
readonly target: mixed,
/** The element listening. */
readonly currentTarget : HTMLElement,
readonly isDefaultPrevented: () => boolean,
readonly preventDefault : () => void,
/**
* Let the key reach the elements around this one.
*
* Stopping is the default, and there is no `stopPropagation` to call: see
* the module header.
*/
readonly continuePropagation: () => void,
|};A key, as useKeyboard hands it to a handler.
type
KeyboardOptionsexport type KeyboardOptions = {|
/** Hear nothing and stop nothing. */
readonly isDisabled?: boolean,
readonly onKeyDown? : (event: KeyboardInteraction) => mixed,
readonly onKeyUp? : (event: KeyboardInteraction) => mixed,
|};What useKeyboard is told.
type
KeyboardPropsexport type KeyboardProps = {|
readonly onKeyDown?: (event: InteractionEvent) => void,
readonly onKeyUp? : (event: InteractionEvent) => void,
|};The handlers useKeyboard needs on the element — only the ones it was given.
type
KeyboardResultexport type KeyboardResult = {|
readonly keyboardProps: KeyboardProps,
|};What useKeyboard hands back.
hook
useKeyboardexport hook useKeyboard(options?: KeyboardOptions): KeyboardResult { ... }Keys on an element, stopped there unless a handler passes them on.
const { keyboardProps } = useKeyboard({ onKeyDown: (event) => { if (event.key === "Delete") remove(); else event.continuePropagation(); }, });
A handler that is not given is not attached, so a useKeyboard with only onKeyDown stops no keyup.
function
mergePropsexport function mergeProps(
...sources: $ReadOnlyArray<?{ readonly [string]: mixed }>
): InteractionProps { ... }Several hooks' props, for one element.
<button {...mergeProps(pressProps, hoverProps, focusProps)}>Save</button>
An event handler — a name that is on and a capital letter — present in more than one is called in the order given, each of them; a className present in more than one is joined; anything else is the last one given, and an undefined does not replace what came before it. See the module header for why this is not internal/merge-props.js.
component
I18nProviderexport component I18nProvider(
children : React.Node,
locale? : string,
direction?: "ltr" | "rtl",
render? : RenderProp,
...rest : Rest
) { ... }An explicit locale keeps server and client output identical. Nested providers form islands.
hook
useCollatorexport hook useCollator(options?: Intl$CollatorOptions): Intl$Collator { ... }Share Intl's language-specific ordering with caller-owned collections.
hook
useFilterexport hook useFilter(): {
startsWith: (text: string, query: string) => boolean,
contains : (text: string, query: string) => boolean,
} { ... }Filtering uses the same collation as typeahead; consumers own the result list.
hook
useDragAndDropexport hook useDragAndDrop(options: {
onDrop : (drop: Drop) => void,
disabled?: boolean,
}): DragAndDrop { ... }Pointer drag data and keyboard lift/drop share one validated payload.
function
parseNumberexport function parseNumber(text: string, formatter: NumberFormatter): number | null { ... }Parse only the symbols the formatter emits, never arbitrary trailing text.
function
parseColorexport function parseColor(value: string): string | null { ... }Canonical #rrggbb or #rrggbbaa, with CSS's short hex forms accepted at the boundary.
component
VisuallyHiddenexport component VisuallyHidden(
children?: React.Node,
/** Show the content while focus is inside it: the skip-link pattern. */
focusable: boolean = false,
render? : RenderProp,
...rest : Rest
) { ... }Content a screen reader reads and a sighted reader does not see.
<button><Icon name="trash" /><VisuallyHidden>Delete draft</VisuallyHidden></button> <VisuallyHidden focusable render={(props) => <a href="#main" {...props} />}> Skip to content </VisuallyHidden>
A caller's style is kept, underneath the hiding, so it applies again the moment a focusable one is shown.
function
announceexport function announce(message: string, options?: AnnounceOptions): void { ... }Say something to a screen reader, from anywhere.
announce(${count} results); announce("Could not save the draft", { politeness: "assertive" });
A function rather than a hook, because what needs announcing comes from event handlers, effects and catch blocks — toast() makes the same choice. An empty message is ignored rather than announced as silence. On the server it returns before scheduling anything.
function
clearAnnouncementsexport function clearAnnouncements(politeness?: Politeness): void { ... }Take every message out, for one politeness or both: the ones in the regions and the ones still waiting to arrive, whose timers are cancelled. After it, nothing announce scheduled for that politeness runs.