Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Merged
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
5 changes: 5 additions & 0 deletions .changeset/brave-ties-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Fixed `Modal` missing `FrameContext` error
33 changes: 21 additions & 12 deletions polaris-react/src/components/Modal/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useRef, useEffect} from 'react';
import React, {useContext, useRef, useEffect} from 'react';
import type {SetStateAction, Dispatch} from 'react';
import {Transition, CSSTransition} from 'react-transition-group';
import {motion} from '@shopify/polaris-tokens';
Expand All @@ -8,8 +8,8 @@ import {focusFirstFocusableNode} from '../../../../utilities/focus';
import {Key} from '../../../../types';
import {KeypressListener} from '../../../KeypressListener';
import {TrapFocus} from '../../../TrapFocus';
import {useFrame} from '../../../../utilities/frame';
import {Text} from '../../../Text';
import {FrameContext} from '../../../../utilities/frame';

import styles from './Dialog.scss';

Expand Down Expand Up @@ -47,7 +47,12 @@ export function Dialog({
...props
}: DialogProps) {
const containerNode = useRef<HTMLDivElement>(null);
const {toastMessages} = useFrame();
const frameContext = useContext(FrameContext);
let toastMessages;

if (frameContext) {
toastMessages = frameContext.toastMessages;
}

const classes = classNames(
styles.Modal,
Expand Down Expand Up @@ -77,6 +82,18 @@ export function Dialog({
onClose();
};

const ariaLiveAnnouncements = (
<div aria-live="assertive">
{toastMessages
? toastMessages.map((toastMessage) => (
<Text visuallyHidden as="p" key={toastMessage.id}>
{toastMessage.content}
</Text>
))
: null}
</div>
);

return (
<TransitionChild
{...props}
Expand Down Expand Up @@ -111,15 +128,7 @@ export function Dialog({
<KeypressListener keyCode={Key.Escape} handler={handleKeyUp} />
{children}
</div>
<div aria-live="assertive">
{toastMessages
? toastMessages.map((toastMessage) => (
<Text visuallyHidden as="p" key={toastMessage.id}>
{toastMessage.content}
</Text>
))
: null}
</div>
{ariaLiveAnnouncements}
</div>
</TrapFocus>
</div>
Expand Down