OverlayMask

Beta

OverlayMask create a highlight area on some DOM element with overlay.

installyarn add @clayui/core
versionNPM Version
useimport {OverlayMask} from '@clayui/core';

Example

Introduction

Create a highlight area for some element in the DOM. The component can place the highlight automatically when passing a component with forwardRef support as children, it is also possible to set the highlighted area if there is no children component.

Area highlight

React component

There are two different ways to create the highlighted area for a component, this allows the component to determine the highlight area and keep updating when there is scroll on the page. The first, set the component as the component’s children.

Snippet

Another option is for cases where it is not possible to define the component as the only child of the <OverlayMask />, define the children as a function and the ref object is passed via render props to add to the element that should get the highlight.

Snippet

Non-React component

The component can be controlled ie define a highlight area for a non-React element that is not managed by React, the difference is that you need to keep the area (bounds) updated if the page exists scroll.

Snippet

API Reference

OverlayMask

<T>({ defaultBounds, bounds, children, onClick, onBoundsChange, padding, visible, }: Props<T>) => JSX.Element
Parameters
Properties

bounds

Bounds | undefined

Sets the current value of bounds to define the highlight area (controlled).

children

React.ReactNode | ((ref: React.RefObject<T>) => React.ReactNode)

Sets the element that will receive the highlight.

onClick

((event: React.MouseEvent<SVGRectElement>) => void) | undefined

Callback is called when the overlay is clicked.

padding

number | undefined= 10

Set the highlight padding.

visible

boolean | undefined

Sets the current visibility of the overlay.

defaultBounds

Bounds | undefined= {"height":0,"width":0,"x":0,"y":0}

Sets the default value of bounds (uncontrolled).

onBoundsChange

InternalDispatch<Bounds> | undefined

Callback is called when the bounds changes (controlled).

Returns
Element
Edit this page on GitHub

Contributors

Matuzalém Teles

Last edited May 11, 2025 at 5:57:01 PM