Skip to Content
ModalLayer

ModalLayer

ModalLayer is a helper component intended to wrap components that are rendered inside portals inside other dialogs or popovers.

#

Documentation

#

Usage

Dialog and popover components internally use focus managers to ensure focus trapping works consistently across browsers. This works for all elements inside the DOM tree of the dialog/popover, but elements rendered via portals are not automatically tracked.

All of our components automatically handle this focus management when being rendered inside dialogs/popovers - but third party portalled components need to be manually wrapped in the ModalLayer component.

"use client"; import { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTrigger, theme, } from "@optiaxiom/react"; import ReactSelect from "react-select"; import { MenuPortal } from "./MenuPortal"; const options = [ { label: "Chocolate", value: "chocolate" }, { label: "Strawberry", value: "strawberry" }, { label: "Vanilla", value: "vanilla" }, ]; export function App() { return ( <Dialog> <DialogTrigger>Open Dialog</DialogTrigger> <DialogContent> <DialogHeader>ModalLayer Demonstration</DialogHeader> <DialogBody> <ReactSelect components={{ MenuPortal }} menuPortalTarget={ typeof document !== "undefined" ? document.body : undefined } options={options} styles={{ control: (styles) => ({ ...styles, backgroundColor: theme.colors["bg.default"], borderColor: theme.colors["border.default"], }), input: (styles) => ({ ...styles, color: theme.colors["fg.default"], }), menu: (styles) => ({ ...styles, backgroundColor: theme.colors["bg.default"], }), menuPortal: (styles) => ({ ...styles, zIndex: theme.zIndex.popover, }), option: (styles, state) => ({ ...styles, backgroundColor: state.isFocused ? theme.colors["bg.default.hovered"] : "transparent", color: theme.colors["fg.default"], }), placeholder: (styles) => ({ ...styles, color: theme.colors["fg.tertiary"], }), singleValue: (styles) => ({ ...styles, color: theme.colors["fg.default"], }), }} /> </DialogBody> <DialogFooter> <DialogClose appearance="primary">Done</DialogClose> </DialogFooter> </DialogContent> </Dialog> ); }

Nested Overlays

Render third-party menus and dialogs inside Axiom overlays without breaking stacking or focus.

Dialog

Display a modal dialog box.

Popover

Display arbitrary rich content inside a non-modal dialog triggered by a button.

#

Props

#

ModalLayer

import { ModalLayer } from "@optiaxiom/react"; // or import { ModalLayer } from "@optiaxiom/react/modal";

Renders a <div> element.

Prop

asChild

Change the default rendered element for the one passed as a child, merging their props and behavior.

Read the Composition guide for more details.

false | true

children

ReactNode

onEscapeKeyDown

Event handler called when the escape key is down. Can be prevented.

(event: KeyboardEvent) => void

#

Changelog

#

0.7.8

  • Added component
Last updated on