Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dev/docs/pages/react-aria/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ This is a quick way to get started, but you can also create your own custom clas
--origin: translateY(-8px);
}

&:not([data-open]) {
opacity: 0;
}

&[data-entering] {
animation: slide 200ms;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/dev/docs/pages/react-aria/home/ExampleApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ function PlantModal(props: ModalOverlayProps) {
${isEntering ? 'animate-in fade-in duration-200 ease-out' : ''}
${isExiting ? 'animate-out fade-out duration-200 ease-in' : ''}
`}>
{({isEntering, isExiting}) => (
{({isEntering, isExiting, isOpen}) => (
<>
{/* Inner position: sticky div sized to the visual viewport
height so the modal appears in view.
Expand All @@ -799,6 +799,7 @@ function PlantModal(props: ModalOverlayProps) {
<div
data-react-aria-top-layer="true"
className={`absolute top-0 left-0 w-full h-(--visual-viewport-height) z-30 hidden sm:flex items-center justify-center pointer-events-none [filter:drop-shadow(0_0_3px_white)] dark:filter-none
${!isOpen ? 'opacity-0' : ''}
${isEntering ? 'animate-in zoom-in-105 ease-out duration-200' : ''}
${isExiting ? 'animate-out zoom-out-95 ease-in duration-200' : ''}
`}>
Expand Down
4 changes: 4 additions & 0 deletions packages/react-aria-components/docs/Modal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ import {DialogTrigger, Modal, Dialog, Button, Heading, TextField, Label, Input}
width: max-content;
max-width: 300px;

&:not([data-open]) {
opacity: 0;
}

&[data-entering] {
animation: modal-zoom 300ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/react-aria-components/docs/Popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ import {DialogTrigger, Popover, Dialog, Button, OverlayArrow, Heading, Switch} f
stroke-width: 1px;
}

&:not([data-open]) {
opacity: 0;
}

&[data-entering],
&[data-exiting] {
transform: var(--starting-scale) var(--origin);
Expand Down Expand Up @@ -447,6 +451,10 @@ Popovers also support entry and exit animations via states exposed as data attri
transition: opacity 300ms, scale 300ms;
transform-origin: var(--trigger-anchor-point);

&:not([data-open]) {
opacity: 0;
}

&[data-entering],
&[data-exiting] {
opacity: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function CommandPaletteExample() {
>
<div className="sticky top-0 left-0 w-full h-(--visual-viewport-height) flex items-start sm:items-center justify-center p-4 box-border text-center">
<Modal
className={({ isEntering, isExiting }) => `
className={({ isEntering, isExiting, isOpen }) => `
${!isOpen ? 'opacity-0' : ''}
${isEntering ? 'animate-in zoom-in-95 ease-out duration-300' : ''}
${isExiting ? 'animate-out zoom-out-95 ease-in duration-200' : ''}
`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ function ModalExample() {
${isEntering ? 'animate-in fade-in duration-300 ease-out' : ''}
${isExiting ? 'animate-out fade-out duration-200 ease-in' : ''}
`}>
<Modal className={({isEntering, isExiting}) => `
<Modal className={({isEntering, isExiting, isOpen}) => `
sticky top-0 left-0 w-full h-(--visual-viewport-height) flex items-center justify-center p-4 box-border text-center
${!isOpen ? 'opacity-0' : ''}
${isEntering ? 'animate-in zoom-in-95 ease-out duration-300' : ''}
${isExiting ? 'animate-out zoom-out-95 ease-in duration-200' : ''}
`}>
Expand Down
12 changes: 12 additions & 0 deletions packages/react-aria-components/docs/styling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ Overlay components such as [Popover](Popover.html) and [Modal](Modal.html) suppo
.react-aria-Popover {
transition: opacity 300ms;

&:not([data-open]) {
opacity: 0;
}

&[data-entering],
&[data-exiting] {
opacity: 0;
Expand All @@ -295,6 +299,10 @@ Note that the `[data-entering]` state is only applied for one frame when using C
/* entry transition */
transition: transform 300ms, opacity 300ms;

&:not([data-open]) {
opacity: 0;
}

Comment on lines +302 to +305

@nwidynski nwidynski Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly concerned about user land style, when transitions are used for enter animation. Now that entering is delayed by at least a frame, users should be adding something like this to avoid a flash of content. This would be an existing issue in our Popover example styling as well, due opacity not being 0 while awaiting placement, if it were not for the early resize in Popover's layout effect.

I haven't thought of a way to avoid this without forcing an opinionated hidden inline style. Maybe somebody else got ideas?

/* starting state of the entry transition */
&[data-entering] {
opacity: 0;
Expand All @@ -315,6 +323,10 @@ Note that the `[data-entering]` state is only applied for one frame when using C
For more complex animations, you can also apply CSS keyframe animations using the same `[data-entering]` and `[data-exiting]` states.

```css render=false
.react-aria-Popover:not([data-open]) {
opacity: 0;
}

.react-aria-Popover[data-entering] {
animation: slide 300ms;
}
Expand Down
43 changes: 37 additions & 6 deletions packages/react-aria-components/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

import {AriaModalOverlayProps, useModalOverlay} from 'react-aria/useModalOverlay';

import {
ClassNameOrFunction,
ContextValue,
Expand All @@ -34,9 +33,19 @@ import {
useOverlayTriggerState
} from 'react-stately/useOverlayTriggerState';
import {OverlayTriggerStateContext} from './Dialog';
import React, {createContext, ForwardedRef, forwardRef, useContext, useMemo, useRef} from 'react';
import React, {
createContext,
ForwardedRef,
forwardRef,
useContext,
useMemo,
useRef,
useState
} from 'react';
import {runAfterKeyboard} from 'react-aria/private/utils/runAfterKeyboard';
import {useEnterAnimation, useExitAnimation} from 'react-aria/private/utils/animation';
import {useIsSSR} from 'react-aria/SSRProvider';
import {useLayoutEffect} from 'react-aria/private/utils/useLayoutEffect';
import {useObjectRef} from 'react-aria/useObjectRef';
import {useViewportSize} from 'react-aria/private/utils/useViewportSize';

Expand Down Expand Up @@ -75,6 +84,7 @@ export interface ModalOverlayProps
interface InternalModalContextValue {
modalProps: DOMAttributes;
modalRef: RefObject<HTMLDivElement | null>;
isOpen: boolean;
isExiting: boolean;
isDismissable?: boolean;
}
Expand All @@ -83,6 +93,12 @@ export const ModalContext = createContext<ContextValue<ModalOverlayProps, HTMLDi
const InternalModalContext = createContext<InternalModalContextValue | null>(null);

export interface ModalRenderProps {
/**
* Whether the modal is ready to be displayed. Use this to avoid layout shift.
*
* @selector [data-open]
*/
isOpen: boolean;
/**
* Whether the modal is currently entering. Use this to apply animations.
*
Expand Down Expand Up @@ -229,11 +245,13 @@ function ModalOverlayInner({UNSTABLE_portalContainer, ...props}: ModalOverlayInn
let {state} = props;
let {modalProps, underlayProps} = useModalOverlay(props, state, modalRef);

let entering = useEnterAnimation(props.overlayRef) || props.isEntering || false;
let [isOpen, setIsOpen] = useState(false);
let entering = useEnterAnimation(props.overlayRef, isOpen) || props.isEntering || false;
let renderProps = useRenderProps({
...props,
defaultClassName: 'react-aria-ModalOverlay',
values: {
isOpen,
isEntering: entering,
isExiting: props.isExiting,
state
Expand Down Expand Up @@ -262,20 +280,31 @@ function ModalOverlayInner({UNSTABLE_portalContainer, ...props}: ModalOverlayInn
'--page-height': pageHeight !== undefined ? pageHeight + 'px' : undefined
};

// Since an auto-focused input may open the OSK, we defer the reveal, as a courtesy, to avoid layout shift.
// TODO: This can cause native focus scroll-into-view to abort, so we might want to do that manually?
useLayoutEffect(() => runAfterKeyboard(() => setIsOpen(true)), []);

return (
<Overlay isExiting={props.isExiting} portalContainer={UNSTABLE_portalContainer}>
<dom.div
{...mergeProps(filterDOMProps(props, {global: true}), underlayProps)}
{...renderProps}
style={style}
ref={props.overlayRef}
data-open={isOpen || undefined}
data-entering={entering || undefined}
data-exiting={props.isExiting || undefined}>
<Provider
values={[
[
InternalModalContext,
{modalProps, modalRef, isExiting: props.isExiting, isDismissable: props.isDismissable}
{
modalProps,
modalRef,
isExiting: props.isExiting,
isOpen,
isDismissable: props.isDismissable
}
],
[OverlayTriggerStateContext, state]
]}>
Expand All @@ -299,16 +328,17 @@ interface ModalContentProps
}

function ModalContent(props: ModalContentProps) {
let {modalProps, modalRef, isExiting, isDismissable} = useContext(InternalModalContext)!;
let {modalProps, modalRef, isExiting, isOpen, isDismissable} = useContext(InternalModalContext)!;
let state = useContext(OverlayTriggerStateContext)!;
let mergedRefs = useMemo(() => mergeRefs(props.modalRef, modalRef), [props.modalRef, modalRef]);

let ref = useObjectRef(mergedRefs);
let entering = useEnterAnimation(ref);
let entering = useEnterAnimation(ref, isOpen);
let renderProps = useRenderProps({
...props,
defaultClassName: 'react-aria-Modal',
values: {
isOpen,
isEntering: entering,
isExiting,
state
Expand All @@ -320,6 +350,7 @@ function ModalContent(props: ModalContentProps) {
{...mergeProps(filterDOMProps(props, {global: true}), modalProps)}
{...renderProps}
ref={ref}
data-open={isOpen || undefined}
data-entering={entering || undefined}
data-exiting={isExiting || undefined}>
{isDismissable && <DismissButton onDismiss={state.close} />}
Expand Down
14 changes: 11 additions & 3 deletions packages/react-aria-components/src/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import React, {
useRef,
useState
} from 'react';
import {runAfterKeyboard} from 'react-aria/private/utils/runAfterKeyboard';
import {useEnterAnimation, useExitAnimation} from 'react-aria/private/utils/animation';
import {useIsHidden} from 'react-aria/private/collections/Hidden';
import {useLayoutEffect} from 'react-aria/private/utils/useLayoutEffect';
Expand Down Expand Up @@ -221,6 +222,9 @@ function PopoverInner({
let groupCtx = useContext(PopoverGroupContext);
let isSubPopover = groupCtx && props.trigger === 'SubmenuTrigger';

let [isOpen, setIsOpen] = useState(false);
let [isDialog, setIsDialog] = useState(false);

let {popoverProps, underlayProps, arrowProps, placement, triggerAnchorPoint} = usePopover(
{
...props,
Expand All @@ -234,7 +238,7 @@ function PopoverInner({
);

let ref = props.popoverRef as RefObject<HTMLDivElement | null>;
let isEntering = useEnterAnimation(ref, !!placement) || props.isEntering || false;
let isEntering = useEnterAnimation(ref, !!placement && isOpen) || props.isEntering || false;
let renderProps = useRenderProps({
...props,
defaultClassName: 'react-aria-Popover',
Expand All @@ -249,10 +253,9 @@ function PopoverInner({
// Automatically render Popover with role=dialog except when isNonModal is true,
// or a dialog is already nested inside the popover.
let shouldBeDialog = !props.isNonModal || props.trigger === 'SubmenuTrigger';
let [isDialog, setDialog] = useState(false);
useLayoutEffect(() => {
if (ref.current) {
setDialog(shouldBeDialog && !ref.current.querySelector('[role=dialog]'));
setIsDialog(shouldBeDialog && !ref.current.querySelector('[role=dialog]'));
}
}, [ref, shouldBeDialog]);

Expand Down Expand Up @@ -301,6 +304,10 @@ function PopoverInner({
'--trigger-width': renderProps.style?.['--trigger-width'] || triggerWidth
};

// Since an auto-focused input may open the OSK, we defer the reveal, as a courtesy, to avoid layout shift.
// TODO: This can cause native focus scroll-into-view to abort, so we might want to do that manually?
useLayoutEffect(() => runAfterKeyboard(() => setIsOpen(true)), []);

let overlay = (
<dom.div
{...mergeProps(filterDOMProps(props, {global: true}), popoverProps)}
Expand All @@ -315,6 +322,7 @@ function PopoverInner({
dir={props.dir}
data-trigger={props.trigger}
data-placement={placement}
data-open={(!!placement && isOpen) || undefined}
data-entering={isEntering || undefined}
data-exiting={isExiting || undefined}>
{!props.isNonModal && <DismissButton onDismiss={state.close} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {runAfterKeyboard, runAfterKeyboardTransition} from '../../../src/utils/runAfterKeyboard';
5 changes: 3 additions & 2 deletions packages/react-aria/src/overlays/calculatePosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ function getMaxHeight(
(position.top != null
? position.top
: containerDimensions[TOTAL_SIZE.height] - (position.bottom ?? 0) - overlayHeight) -
(containerDimensions.scroll.top ?? 0);
// calculate the dimentions of the "boundingRect" which is most restrictive top/bottom of the boundaryRect and the visual view port
(containerDimensions.scroll.top ?? 0) +
(visualViewport?.offsetTop ?? 0);

@nwidynski nwidynski Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snowystinger This was the core culprit to the positional issue. A scroll into view motion may divide delta between container scroll and viewport scroll, but only the former was accounted for. See this animation for an explainer https://www.w3.org/TR/cssom-view-1/#example-vvanimation

// calculate the dimensions of the "boundingRect" which is most restrictive top/bottom of the boundaryRect and the visual view port
let boundaryToContainerTransformOffset = isContainerDescendentOfBoundary
? containerOffsetWithBoundary.top
: 0;
Expand Down
Loading