Skip to Content

Overlay

Overlay provides component developers a way to position elements globally or relative to a anchor element. The overlay wraps the backdrop, position, exit listener and portal to provide a simple API for handling position.

There are five overlay components in the Overlay:

  • ConnectedOverlay - A overlay that is relative to a anchoring element.
  • GlobalOverlay - A overlay that is placed on top of other elements globally.
  • OverlayPortal - A wrapper around the portal component to manage z-indexs.
  • OverlayTrigger - The internal trigger component that the ConnectedOverlay uses.

Examples

Global Overlay

A overlay component typically used by components like Dialogs or Drawers. You can use the Global Ovleray using element APIs.

Use the css variable --color-layer-transparent to set the backdrop color.

// index.css body { --color-layer-transparent: rgba(0, 0, 0, 0.5); }

Dialog Example

Below is an example of a simple dialog component using the global overlay.

Connected Overlay

A overlay component typically used by components like menus.

Tooltip Example

Below is an example of simple tooltip component using the connected overlay.

Below is an example of simple menu component using the connected overlay.

API

GlobalOverlay 

NameTypeDefault
childrenany

The children to be rendered within the global overlay.

openboolean

If true, the global overlay is open.

closeOnBackdropClickboolean

If true, the global overlay will close when the backdrop is clicked.

true
hasBackdropboolean

If true, the global overlay will have a backdrop.

true
backdropClassNamestring

The CSS class name to be applied to the backdrop of the global overlay.

closeOnEscapeboolean

If true, the global overlay will close when the escape key is pressed.

true
onClose() => void

A function that is called when the global overlay is closed.

ConnectedOverlay 

NameTypeDefault
openboolean

Whether the overlay should be visible.

referenceReferenceProp

Reference of the overlay to align to.

childrenany

The content of the overlay.

contentany

Content to render in the overlay.

triggerTriggerTypes | TriggerTypes[]

Type of trigger to open the overlay.

'click'
triggerElementany

Trigger element to open the overlay.

triggerClassNamestring

Trigger classname.

portalClassNamestring

Portal classname.

closeOnBodyClickboolean

Close when the body is clicked or not.

true
closeOnEscapeboolean

Close when escape is pressed or not.

true
appendToBodyboolean

Append the overlay to the body. Almost always want this.

true
elementTypestring

Overlay element type.

modifiersModifiers

Position modifiers.

followCursorboolean

Overlay should follow cursor or not.

placementPlacement

Placement of the overlay.

'bottom'
onOpen(event?: any) => void

Event called when the overlay is opened.

onClose(event?: any) => void

Event called when the overlay is closed.

OverlayTrigger 

NameTypeDefault
childrenany

The children to be rendered within the overlay trigger.

classNamestring

The CSS class name to be applied to the overlay trigger.

elementTypeany

The type of element that will be used as the overlay trigger.

'span'
triggerTriggerTypes | TriggerTypes[]

The type(s) of event(s) that will trigger the overlay. Can be a single trigger type or an array of trigger types.

onOpen(event: OverlayTriggerEvent) => void

A function that is called when the overlay is opened. It receives an object of type OverlayTriggerEvent as an argument.

() => undefined
onClose(event: OverlayTriggerEvent) => void

A function that is called when the overlay is closed. It receives an object of type OverlayTriggerEvent as an argument.

() => undefined

OverlayPortal 

NameTypeDefault
appendToBodyboolean

If true, the overlay portal will be appended to the body.

true
classNamestring

The class name of the overlay portal.

styleCSSProperties

The style of the overlay portal.

idstring

The id of the overlay portal.

children(props: OverlayPortalMountEvent) => any

A function that returns the children of the overlay portal. It receives an object of type OverlayPortalMountEvent as an argument.

onMount(event: OverlayPortalMountEvent) => void

A function that is called when the overlay portal mounts. It receives an object of type OverlayPortalMountEvent as an argument.

onUnmount() => void

A function that is called when the overlay portal unmounts.

Last updated on