DisplayReact
An element that stays on screen while it animates out.
Rendered by React 19.3.1
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<Presence />Examples
Keep Mounted
The same panel with keepMounted, so it stays in the document, hidden, and a status line reads what onPresentChangeComplete reported.
API reference
3 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
PresencePresence
Renders the app's element while present is true, plays its enter animation, and keeps it through its exit animation when present turns false. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
presentrequiredWhether the element is shown. | boolean | — |
keepMountedWhether the element stays in the document, hidden, while not present. | boolean | false |
onPresentChangeCompleteCalled once the enter or exit animation of a change of present has finished. | ((present: boolean) => void) | — |
| Data attribute | Description |
|---|---|
data-open | Present while present is true. |
data-closed | Present while present is false: during the exit and while keepMounted keeps it hidden. |
data-starting-style | Present when the element begins animating in. |
data-ending-style | Present while the element is animating out. |
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
Presence takes no focus and has no keys. The buttons in the examples are plain buttons: Enter and Space press them.
Accessibility
| Part | Sets | So that |
|---|---|---|
| Presence | no role or ARIA; an open or closed mark; inert from the start of an exit; hidden with keepMounted | a leaving element cannot be reached while it fades, and a hidden one is not read |
Focus order
- Presence is not focusable; its focusable children are tab stops while it is present.
- A leaving element is
inert: focus passes over it, and an element that held focus when the exit started loses it to the document body. - A
keepMountedelement that is hidden has no tab stops.