Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13eafc2
fix: modal layout shift when auto-focusing input
nwidynski May 25, 2026
64a2d76
chore: remove comments
nwidynski May 25, 2026
8bf7085
chore: lint
nwidynski May 25, 2026
2ed61d1
Merge branch 'main' into fix-ios-modal
nwidynski Jun 2, 2026
522b02e
feat: generic keyboard observation and transition hooks
nwidynski Jun 10, 2026
c9fbf32
chore: lint
nwidynski Jun 10, 2026
c93b460
Merge branch 'main' into fix-ios-modal
nwidynski Jun 11, 2026
9bcbdf4
feat: cleanup support and placement consideration
nwidynski Jun 11, 2026
2d6fc45
chore: migrate usepreventscroll
nwidynski Jun 11, 2026
70a2394
fix: typo and use cleanup function
nwidynski Jun 19, 2026
9ac2c05
Merge branch 'main' into fix-ios-modal
nwidynski Jun 20, 2026
aef324f
chore: update exports
nwidynski Jun 20, 2026
2d2649d
chore: update remaining imports to new export
nwidynski Jun 20, 2026
77c36bf
chore: run oxfmt
nwidynski Jun 20, 2026
f20c922
chore: apply dom helpers to shadow dom and move event + style utils
nwidynski Jun 21, 2026
d0638df
chore: oxlint
nwidynski Jun 21, 2026
47bc548
feat: add render props to popover
nwidynski Jun 22, 2026
d492b1b
fix: typo in jsdocs
nwidynski Jun 22, 2026
3bcc076
fix: style cleanup
nwidynski Jun 23, 2026
04cb377
Merge branch 'main' into fix-ios-modal
snowystinger Jun 26, 2026
939c182
Merge branch 'main' into fix-ios-modal
nwidynski Jun 27, 2026
09afbff
chore: cleanup
nwidynski Jun 27, 2026
c71dc1d
chore: review comments
nwidynski Jun 27, 2026
e98643c
fix: review comments and enforce hidden style prior to entry
nwidynski Jun 27, 2026
760df6b
chore: fmt
nwidynski Jun 27, 2026
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
7 changes: 6 additions & 1 deletion packages/@react-aria/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ export {
useLoadMoreSentinel as UNSTABLE_useLoadMoreSentinel
} from 'react-aria/private/utils/useLoadMoreSentinel';
export {inertValue} from 'react-aria/private/utils/inertValue';
export {isCtrlKeyPressed, willOpenKeyboard} from 'react-aria/private/utils/keyboard';
export {
isCtrlKeyPressed,
isKeyboardOpen,
isKeyboardVisible,
willOpenKeyboard
} from 'react-aria/private/utils/keyboard';
export {useEnterAnimation, useExitAnimation} from 'react-aria/private/utils/animation';
export {isFocusable, isTabbable} from 'react-aria/private/utils/isFocusable';
export {getNonce} from 'react-aria/private/utils/getNonce';
Expand Down
4 changes: 4 additions & 0 deletions packages/@react-spectrum/s2/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const modalOverlayStyles = style({
isolation: 'isolate',
backgroundColor: 'transparent-black-500',
opacity: {
default: 0,
isOpen: 1,
isEntering: 0,
isExiting: 0
},
Expand Down Expand Up @@ -148,6 +150,8 @@ export const Modal = forwardRef(function Modal(props: ModalProps, ref: DOMRef<HT
},
backgroundColor: '--s2-container-bg',
opacity: {
default: 0,
isOpen: 1,
isEntering: 0,
isExiting: 0
},
Expand Down
14 changes: 14 additions & 0 deletions packages/@react-types/shared/src/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
import {FocusableElement} from './dom';
import {FocusEvent, MouseEvent, KeyboardEvent as ReactKeyboardEvent, SyntheticEvent} from 'react';

// Type helper to extract the target element type from an event
export type EventTargetType<T> = T extends SyntheticEvent<infer E, any> ? E : EventTarget;

// Type helper to extract the event map from a target
export type EventMapType<T extends EventTarget> = T extends Window
? WindowEventMap
: T extends Document
? DocumentEventMap
: T extends Element
? HTMLElementEventMap
: T extends VisualViewport
? VisualViewportEventMap
: GlobalEventHandlersEventMap;

// Event bubbling can be problematic in real-world applications, so the default for React Spectrum components
// is not to propagate. This can be overridden by calling continuePropagation() on the event.
export type BaseEvent<T extends SyntheticEvent> = T & {
Expand Down
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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will think about this more now that we have a concrete example of what happens #10102 (comment)

I think as it is, we'd consider this breaking

@nwidynski nwidynski Jun 27, 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.

Yeah, I figured. I added back the hidden styling for now until someone has a better idea. Kinda makes the data attribute obsolete, although there may be an argument to keep it, to encourage migration to safe styling.

You can test that this gets the job done by removing the changes in Modal.css and verifying that no flash of content is happening in /react-aria/Modal.html

/* 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doc is a little particular to the issue you're solving, but not really a great example of when to use without the knowledge of this PR and Issue. Have any ideas how we can improve this?

@nwidynski nwidynski Jun 26, 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.

Suggestions welcome 😅 Maybe something like ”[…] Use this to hide the modal while it is not yet ready to enter."

*
* @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,6 +280,10 @@ 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)), []);

// oxlint-disable react/react-compiler
return (
<Overlay isExiting={props.isExiting} portalContainer={UNSTABLE_portalContainer}>
Expand All @@ -270,13 +292,20 @@ function ModalOverlayInner({UNSTABLE_portalContainer, ...props}: ModalOverlayInn
{...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 @@ -301,16 +330,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 @@ -322,6 +352,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
22 changes: 19 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 @@ -125,6 +126,12 @@ export interface PopoverRenderProps {
* @selector [data-placement="left | right | top | bottom"]
*/
placement: PlacementAxis | null;
/**
* Whether the popover is ready to be displayed. Use this to avoid layout shift.
*
* @selector [data-open]
*/
isOpen: boolean;
/**
* Whether the popover is currently entering. Use this to apply animations.
*
Expand Down Expand Up @@ -173,6 +180,7 @@ export const Popover = /*#__PURE__*/ (forwardRef as forwardRefType)(function Pop
children = children({
trigger: props.trigger || null,
placement: 'bottom',
isOpen: false,
isEntering: false,
isExiting: false,
defaultChildren: null
Expand Down Expand Up @@ -223,6 +231,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 @@ -237,7 +248,7 @@ function PopoverInner({

let ref = props.popoverRef as RefObject<HTMLDivElement | null>;
// oxlint-disable-next-line react/react-compiler
let isEntering = useEnterAnimation(ref, !!placement) || props.isEntering || false;
let isEntering = useEnterAnimation(ref, !!placement && isOpen) || props.isEntering || false;
// oxlint-disable-next-line react/react-compiler
let renderProps = useRenderProps({
// oxlint-disable-next-line react/react-compiler
Expand All @@ -248,6 +259,7 @@ function PopoverInner({
// oxlint-disable-next-line react/react-compiler
trigger: props.trigger || null,
placement,
isOpen: !!placement && isOpen,
// oxlint-disable-next-line react/react-compiler
isEntering,
isExiting
Expand All @@ -258,10 +270,9 @@ function PopoverInner({
// or a dialog is already nested inside the popover.
// oxlint-disable-next-line react/react-compiler
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 @@ -315,6 +326,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)), []);

// oxlint-disable react/react-compiler
let overlay = (
<dom.div
Expand All @@ -331,6 +346,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}>
{/* oxlint-disable-next-line react/react-compiler */}
Expand Down
7 changes: 6 additions & 1 deletion packages/react-aria/exports/private/utils/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export {isCtrlKeyPressed, willOpenKeyboard} from '../../../src/utils/keyboard';
export {
Comment thread
nwidynski marked this conversation as resolved.
isCtrlKeyPressed,
isKeyboardOpen,
isKeyboardVisible,
willOpenKeyboard
} from '../../../src/utils/keyboard';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {runAfterKeyboard, runAfterKeyboardTransition} from '../../../src/utils/runAfterKeyboard';
Loading