- Spec files
npm-react-aria
Describes: pkg:npm/react-aria@3.43.x
- Description
- Comprehensive library of unstyled React hooks providing accessible UI primitives with full WAI-ARIA compliance and internationalization support.
- Author
- tessl
- Last updated
overlays-modals.md docs/
1# Overlays and Modals23Overlay components including dialogs, popovers, tooltips, and modals with proper focus management, positioning, and accessibility. All overlays handle escape key, click outside, and focus restoration.45## Capabilities67### Dialog89Provides modal dialog behavior with focus containment and accessibility.1011```typescript { .api }12/**13* Provides dialog behavior and accessibility14* @param props - Dialog configuration15* @param ref - Ref to the dialog element16* @returns Dialog props17*/18function useDialog(props: AriaDialogProps, ref: RefObject<Element>): DialogAria;1920interface AriaDialogProps {21/** Role of the dialog */22role?: 'dialog' | 'alertdialog';23/** ID of the dialog */24id?: string;25/** Accessible name for the dialog */26'aria-label'?: string;27/** ID of element that labels the dialog */28'aria-labelledby'?: string;29/** ID of element that describes the dialog */30'aria-describedby'?: string;31}3233interface DialogAria {34/** Props for the dialog element */35dialogProps: DOMAttributes<Element>;36/** Props for the dialog title element */37titleProps: DOMAttributes<Element>;38}39```4041### Disclosure4243Provides disclosure behavior for expandable/collapsible content sections.4445```typescript { .api }46/**47* Provides disclosure behavior and accessibility48* @param props - Disclosure configuration49* @param ref - Ref to the disclosure element50* @returns Disclosure props and state51*/52function useDisclosure(props: AriaDisclosureProps, ref: RefObject<Element>): DisclosureAria;5354interface AriaDisclosureProps {55/** Whether the disclosure is expanded */56isExpanded?: boolean;57/** Default expanded state (uncontrolled) */58defaultExpanded?: boolean;59/** Handler called when expansion changes */60onExpandedChange?: (isExpanded: boolean) => void;61/** Whether the disclosure is disabled */62isDisabled?: boolean;63}6465interface DisclosureAria {66/** Props for the disclosure button */67buttonProps: ButtonHTMLAttributes<HTMLButtonElement>;68/** Props for the disclosure panel */69panelProps: DOMAttributes<Element>;70/** Whether the disclosure is expanded */71isExpanded: boolean;72}73```7475### Modal7677Provides modal overlay behavior with backdrop and focus management.7879```typescript { .api }80/**81* Provides modal behavior and accessibility82* @param options - Modal configuration options83* @returns Modal props and state84*/85function useModal(options?: AriaModalOptions): ModalAria;8687/**88* Provides modal overlay behavior89* @param props - Modal overlay configuration90* @param state - Modal state91* @param ref - Ref to the overlay element92* @returns Modal overlay props93*/94function useModalOverlay(props: AriaModalOverlayProps, state: OverlayTriggerState, ref: RefObject<Element>): ModalOverlayAria;9596/**97* Provides modal provider context98* @param props - Modal provider configuration99* @returns Modal provider props and state100*/101function useModalProvider(props: ModalProviderProps): ModalProviderAria;102103interface AriaModalOptions {104/** Whether the modal is open */105isOpen?: boolean;106/** Handler called when the modal should close */107onClose?: () => void;108/** Whether the modal is keyboard modal */109isKeyboardDismissDisabled?: boolean;110/** Whether to disable outside clicks */111isDismissable?: boolean;112}113114interface ModalAria {115/** Props for the modal element */116modalProps: DOMAttributes<Element>;117/** Props for the underlay element */118underlayProps: DOMAttributes<Element>;119}120121interface AriaModalOverlayProps {122/** Whether the overlay is open */123isOpen?: boolean;124/** Handler called when the overlay should close */125onClose?: () => void;126/** Whether the overlay is dismissable */127isDismissable?: boolean;128/** Whether keyboard dismissal is disabled */129isKeyboardDismissDisabled?: boolean;130/** Whether to prevent scrolling */131shouldCloseOnBlur?: boolean;132}133134interface ModalOverlayAria {135/** Props for the modal overlay element */136modalProps: DOMAttributes<Element>;137/** Props for the underlay element */138underlayProps: DOMAttributes<Element>;139}140```141142### Popover143144Provides popover behavior with positioning and trigger management.145146```typescript { .api }147/**148* Provides popover behavior and accessibility149* @param props - Popover configuration150* @param state - Popover state151* @param ref - Ref to the popover element152* @returns Popover props153*/154function usePopover(props: AriaPopoverProps, state: PopoverState, ref: RefObject<Element>): PopoverAria;155156interface AriaPopoverProps {157/** Type of popover */158triggerRef: RefObject<Element>;159/** Whether the popover is non-modal */160isNonModal?: boolean;161/** Trigger source for the popover */162triggerSource?: string;163/** Whether keyboard dismissal is disabled */164isKeyboardDismissDisabled?: boolean;165/** Whether the popover should close on blur */166shouldCloseOnBlur?: boolean;167/** Whether to flip placement when space is limited */168shouldFlip?: boolean;169/** Boundary element for flipping */170boundaryElement?: Element;171/** Scroll ref for repositioning */172scrollRef?: RefObject<Element>;173/** Whether the popover should update position */174shouldUpdatePosition?: boolean;175/** Arrow boundary offset */176arrowBoundaryOffset?: number;177/** Placement of the popover */178placement?: Placement;179/** Container padding */180containerPadding?: number;181/** Offset from trigger */182offset?: number;183/** Cross offset */184crossOffset?: number;185/** Whether the popover should close on interact outside */186shouldCloseOnInteractOutside?: (element: Element) => boolean;187/** Max height of the popover */188maxHeight?: number;189/** Arrow size */190arrowSize?: number;191/** Arrow boundary offset */192arrowBoundaryOffset?: number;193}194195interface PopoverAria {196/** Props for the popover element */197popoverProps: DOMAttributes<Element>;198/** Props for the arrow element */199arrowProps: DOMAttributes<Element>;200/** Placement that was actually used */201placement: PlacementAxis;202/** Arrow props */203arrowProps: DOMAttributes<Element>;204/** Props for the underlay element */205underlayProps: DOMAttributes<Element>;206}207```208209### Overlay210211Provides base overlay behavior and positioning.212213```typescript { .api }214/**215* Provides overlay behavior and accessibility216* @param props - Overlay configuration217* @param ref - Ref to the overlay element218* @returns Overlay props219*/220function useOverlay(props: AriaOverlayProps, ref: RefObject<Element>): OverlayAria;221222/**223* Provides overlay positioning behavior224* @param props - Position configuration225* @param ref - Ref to the overlay element226* @returns Position props and placement227*/228function useOverlayPosition(props: AriaPositionProps, ref: RefObject<Element>): PositionAria;229230/**231* Provides overlay trigger behavior232* @param props - Overlay trigger configuration233* @param state - Overlay trigger state234* @param ref - Ref to the trigger element235* @returns Overlay trigger props236*/237function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref?: RefObject<Element>): OverlayTriggerAria;238239interface AriaOverlayProps {240/** Whether the overlay is open */241isOpen?: boolean;242/** Handler called when the overlay should close */243onClose?: () => void;244/** Whether the overlay should close on blur */245shouldCloseOnBlur?: boolean;246/** Whether the overlay is dismissable */247isDismissable?: boolean;248/** Whether keyboard dismissal is disabled */249isKeyboardDismissDisabled?: boolean;250/** Whether to prevent scrolling */251shouldCloseOnInteractOutside?: (element: Element) => boolean;252}253254interface OverlayAria {255/** Props for the overlay element */256overlayProps: DOMAttributes<Element>;257/** Props for the underlay element */258underlayProps: DOMAttributes<Element>;259}260261interface AriaPositionProps extends PositionProps {262/** Element to position relative to */263targetRef: RefObject<Element>;264/** Element to position */265overlayRef: RefObject<Element>;266/** Scroll refs for repositioning */267scrollRef?: RefObject<Element>;268/** Placement preference */269placement?: Placement;270/** Container padding */271containerPadding?: number;272/** Offset from target */273offset?: number;274/** Cross-axis offset */275crossOffset?: number;276/** Whether to flip when space is limited */277shouldFlip?: boolean;278/** Boundary element */279boundaryElement?: Element;280/** Whether position should update */281shouldUpdatePosition?: boolean;282/** Whether the overlay is open */283isOpen?: boolean;284/** Handler called when the overlay should close */285onClose?: () => void;286/** Max height */287maxHeight?: number;288/** Arrow size for popover arrows */289arrowSize?: number;290/** Arrow boundary offset */291arrowBoundaryOffset?: number;292}293294interface PositionAria {295/** Props for the overlay element */296overlayProps: DOMAttributes<Element>;297/** Props for the arrow element */298arrowProps: DOMAttributes<Element>;299/** Placement that was used */300placement: PlacementAxis;301/** Update position manually */302updatePosition(): void;303}304305interface OverlayTriggerProps {306/** Type of overlay */307type: 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid';308/** Whether the overlay is open */309isOpen?: boolean;310/** Default open state (uncontrolled) */311defaultOpen?: boolean;312/** Handler called when open state changes */313onOpenChange?: (isOpen: boolean) => void;314}315316interface OverlayTriggerAria {317/** Props for the trigger element */318triggerProps: ButtonHTMLAttributes<HTMLButtonElement>;319/** Props for the overlay element */320overlayProps: DOMAttributes<Element>;321}322```323324### Tooltip325326Provides tooltip behavior with hover and focus triggers.327328```typescript { .api }329/**330* Provides tooltip behavior and accessibility331* @param props - Tooltip configuration332* @param state - Tooltip trigger state333* @returns Tooltip props334*/335function useTooltip(props: AriaTooltipProps, state: TooltipTriggerState): TooltipAria;336337/**338* Provides tooltip trigger behavior339* @param props - Tooltip trigger configuration340* @param state - Tooltip trigger state341* @param ref - Ref to the trigger element342* @returns Tooltip trigger props343*/344function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTriggerState, ref?: RefObject<Element>): TooltipTriggerAria;345346interface AriaTooltipProps {347/** Whether the tooltip is open */348isOpen?: boolean;349/** ID for the tooltip */350id?: string;351}352353interface TooltipAria {354/** Props for the tooltip element */355tooltipProps: DOMAttributes<Element>;356}357358interface TooltipTriggerProps {359/** Whether the tooltip is disabled */360isDisabled?: boolean;361/** Delay before showing tooltip */362delay?: number;363/** Close delay */364closeDelay?: number;365/** Trigger events */366trigger?: 'focus' | 'focus+hover';367/** Whether the tooltip is open */368isOpen?: boolean;369/** Default open state (uncontrolled) */370defaultOpen?: boolean;371/** Handler called when open state changes */372onOpenChange?: (isOpen: boolean) => void;373}374375interface TooltipTriggerAria {376/** Props for the trigger element */377triggerProps: DOMAttributes<Element>;378/** Props for the tooltip element */379tooltipProps: DOMAttributes<Element>;380}381```382383### Toast384385Provides toast notification behavior with timeout and positioning.386387```typescript { .api }388/**389* Provides toast behavior and accessibility390* @param props - Toast configuration391* @param state - Toast state392* @param ref - Ref to the toast element393* @returns Toast props394*/395function useToast(props: AriaToastProps, state: ToastState, ref: RefObject<Element>): ToastAria;396397/**398* Provides toast region behavior for managing multiple toasts399* @param props - Toast region configuration400* @param state - Toast region state401* @param ref - Ref to the toast region element402* @returns Toast region props403*/404function useToastRegion(props: AriaToastRegionProps, state: ToastRegionState, ref: RefObject<Element>): ToastRegionAria;405406interface AriaToastProps {407/** Toast priority level */408priority?: 'low' | 'normal' | 'high';409/** Whether the toast should auto-dismiss */410shouldCloseOnAction?: boolean;411/** Handler called when the toast is closed */412onClose?: () => void;413}414415interface ToastAria {416/** Props for the toast element */417toastProps: DOMAttributes<Element>;418/** Props for the title element */419titleProps: DOMAttributes<Element>;420/** Props for the description element */421descriptionProps: DOMAttributes<Element>;422/** Props for the close button */423closeButtonProps: ButtonHTMLAttributes<HTMLButtonElement>;424}425426interface AriaToastRegionProps {427/** Accessible label for the toast region */428'aria-label'?: string;429/** ID of element that labels the toast region */430'aria-labelledby'?: string;431}432433interface ToastRegionAria {434/** Props for the toast region element */435regionProps: DOMAttributes<Element>;436}437```438439### Prevent Scroll440441Provides scroll prevention behavior for modal overlays.442443```typescript { .api }444/**445* Provides scroll prevention behavior446* @param options - Scroll prevention options447* @returns Scroll prevention state448*/449function usePreventScroll(options?: { isDisabled?: boolean }): void;450```451452### Overlay Components453454```typescript { .api }455/**456* Button for dismissing overlays457*/458function DismissButton(props: DismissButtonProps): JSX.Element;459460/**461* Provider for modal context462*/463function ModalProvider(props: { children: ReactNode }): JSX.Element;464465/**466* Base overlay component467*/468function Overlay(props: OverlayProps): JSX.Element;469470/**471* Container for overlay portals472*/473function OverlayContainer(props: OverlayContainerProps): JSX.Element;474475/**476* Provider for overlay context477*/478function OverlayProvider(props: { children: ReactNode }): JSX.Element;479480/**481* Portal provider (marked as unsafe)482*/483function UNSAFE_PortalProvider(props: { children: ReactNode; getContainer?: () => Element }): JSX.Element;484485interface DismissButtonProps {486/** Handler called when button is pressed */487onDismiss?: () => void;488}489490interface OverlayProps {491/** Children to render in overlay */492children: ReactNode;493/** Whether the overlay is open */494isOpen?: boolean;495/** Container to render overlay in */496container?: Element;497/** Handler called when overlay should close */498onClose?: () => void;499}500501interface OverlayContainerProps {502/** Container element to render portals in */503portalContainer?: Element;504/** Children to render */505children: ReactNode;506}507```508509## Types510511```typescript { .api }512type Placement =513| 'bottom'514| 'bottom left'515| 'bottom right'516| 'bottom start'517| 'bottom end'518| 'top'519| 'top left'520| 'top right'521| 'top start'522| 'top end'523| 'left'524| 'left top'525| 'left bottom'526| 'start'527| 'start top'528| 'start bottom'529| 'right'530| 'right top'531| 'right bottom'532| 'end'533| 'end top'534| 'end bottom';535536type PlacementAxis = 'top' | 'bottom' | 'left' | 'right' | 'center';537538interface OverlayTriggerState {539/** Whether the overlay is open */540isOpen: boolean;541/** Set the open state */542setOpen(isOpen: boolean): void;543/** Open the overlay */544open(): void;545/** Close the overlay */546close(): void;547/** Toggle the overlay */548toggle(): void;549}550551interface PopoverState extends OverlayTriggerState {552/** Trigger source */553triggerSource?: string;554/** Set trigger source */555setTriggerSource(source: string): void;556}557558interface TooltipTriggerState extends OverlayTriggerState {559/** Whether the tooltip is immediately open */560isWarmupFinished: boolean;561/** Warm up the tooltip globally */562warmUp(): void;563/** Cool down the tooltip globally */564coolDown(): void;565}566567interface ToastState {568/** Whether the toast is visible */569isVisible: boolean;570/** Whether the toast is paused */571isPaused: boolean;572/** Remaining time before auto-dismiss */573remainingTime: number;574/** Pause the toast */575pause(): void;576/** Resume the toast */577resume(): void;578/** Close the toast */579close(): void;580}581582interface ToastRegionState {583/** List of toasts in the region */584toasts: Toast[];585/** Add a toast */586add(toast: Toast): void;587/** Remove a toast */588remove(key: string): void;589/** Pause all toasts */590pauseAll(): void;591/** Resume all toasts */592resumeAll(): void;593}594595interface Toast {596/** Unique key for the toast */597key: string;598/** Toast content */599content: ReactNode;600/** Toast priority */601priority?: 'low' | 'normal' | 'high';602/** Auto-dismiss timeout */603timeout?: number;604/** Handler called when closed */605onClose?: () => void;606}607608interface PositionProps {609/** Container padding */610containerPadding?: number;611/** Offset from target */612offset?: number;613/** Cross-axis offset */614crossOffset?: number;615/** Whether to flip placement */616shouldFlip?: boolean;617/** Boundary element */618boundaryElement?: Element;619/** Max height */620maxHeight?: number;621}622```