Skip to main content
In progress

Modal

Modal displays content in a centered overlay that blocks interaction with the underlying interface until the user completes or dismisses the task. Modal is responsible for overlay, focus management, keyboard handling, and scroll behavior, and it typically contains a Dialog component for structured content.

Modal Title

Modal content goes here

Code example
import { Modal, useModal, Dialog, Button, Dialog } from '@yleisradio/yds-components-react';

const { modalRef, openModal, closeModal } = useModal();

<>
<Button onClick={openModal}>Open Modal</Button>
<Modal modalRef={modalRef}>
<Dialog
title="Modal Title"
actions={
<>
<Button variant="text" text="Cancel" onClick={closeModal} />
<Button text="OK" onClick={closeModal} />
</>
}
>
<p>Modal content goes here</p>
</Dialog>
</Modal>
</>

Why to use

Use Modal when you need to interrupt the user’s current flow to request a decision, confirmation, or focused input. Modal ensures consistent overlay behavior, focus trapping, keyboard interaction, and accessibility across all dialog-based interfaces in YDS. It standardizes how blocking dialogs behave and prevents common accessibility and usability issues related to custom modal implementations.

When to use

Use Modal when the user must complete or explicitly dismiss a task before continuing.

Do
  • Use Modal for confirmations, critical information, and forms that require focused attention.
  • Use Modal together with Dialog to structure content consistently.
  • Use Modal for desktop and tablet experiences.
Don't
  • Don’t use Modal for non-critical or purely informational content.
  • Don’t use Modal for mobile-first interactions — use BottomSheet instead.
  • Don’t stack or nest modals.

Content Guidelines

Use these guidelines when placing content inside a Modal. They apply especially when Modal contains a Dialog.

Do
  • Ensure the modal has a clear title describing the task.
  • Keep content concise and focused on a single goal.
  • Use clear primary and secondary actions.
Don't
  • Don’t overload the modal with long or multi-step flows.
  • Don’t include unnecessary secondary content.
  • Don’t use vague action labels like “OK” or “Kyllä”.

Anatomy

Modal anatomy

A modal dialog is composed of two distinct parts: the Modal and the Dialog. Together they form a complete, accessible modal dialog pattern where responsibilities are clearly separated between container behavior and content structure.

  1. Close button – Optional control used to dismiss the modal.
  2. Modal container – The surface that holds the dialog content and visually separates it from the backdrop while managing focus and interaction.

Dialog

  1. Dialog title – Required heading that communicates the purpose of the modal.
  2. Content area – The main content section for text, forms, or other components. Supports internal scrolling when content overflows.
  3. Actions area – Optional footer containing one or more action buttons, typically a primary and a secondary action.

Key Modal Props

Use these props to configure the Modal component.

modalRef

Ref handle for controlling the modal (open/close). Use with useModal hook.

TypeExampleDescription
React.RefObject<ModalHandle>

Modal title

Modal content goes here
Ref handle for programmatic control
Code example
const { modalRef, openModal, closeModal } = useModal();

<Modal modalRef={modalRef}>
<div>Content here</div>
<Button onClick={closeModal}>Close</Button>
</Modal>

scrollBehavior

Scroll behavior for the modal content.

ValueExampleDescription
content
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
Restricts scrolling to modal content (default)
body
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
Allows entire page to scroll
Code example
const { modalRef, openModal, closeModal } = useModal();
<Modal scrollBehavior="content" modalRef={modalRef}>
<div>Content here</div>
<Button onClick={closeModal}>Close</Button>
</Modal>
<Modal scrollBehavior="body" modalRef={modalRef}>
<div>Content here</div>
<Button onClick={closeModal}>Close</Button>
</Modal>

Behavior

  • Modal opens when openModal() is called or when the ref’s open() method is invoked.
  • Modal closes when closeModal() is called, the close button is clicked, or the Escape key is pressed.
  • While open, Modal blocks interaction with background content and traps focus within the modal.
  • Body scroll is disabled by default (scrollBehavior="content") to prevent background scrolling, and the page scroll position is preserved when the modal opens.
  • Clicking the backdrop does not close the modal by default (native <dialog> behavior).
  • The onClose callback fires when the modal’s close event is triggered.

Accessibility

Implementation Examples

Email verification Modal with Dialog

Vahvista sähköpostiosoitteesi

Olemme lähettäneet vahvistusviestin osoitteeseen etunimi.sukunimi@example.com. Avaa sähköposti ja seuraa ohjeita. Tarkista myös roskapostikansio, jos viestiä ei näy.
Code example
import { Button, Modal, Dialog, useModal } from '@yleisradio/yds-components-react';
import { IllustrativeMail } from '@yleisradio/yds-icons-react';

export const ModalEmailVerification = () => {
const { modalRef, openModal, closeModal } = useModal();

return (
<>
<Modal modalRef={modalRef}>
<Dialog
title="Vahvista sähköpostiosoitteesi"
illustrativeIcon={<IllustrativeMail />}
actions={
<>
<Button text="Avaa sähköposti" onClick={closeModal} />
</>
}
>
Olemme lähettäneet vahvistusviestin osoitteeseen etunimi.sukunimi@example.com. Avaa
sähköposti ja seuraa ohjeita.{' '}
<strong>Tarkista myös roskapostikansio, jos viestiä ei näy.</strong>
</Dialog>
</Modal>
<Button onClick={openModal}>Open Modal</Button>
</>
);
};

Nickname Modal with custom content

Aseta itsellesi nimimerkki

Nimimerkin pitää olla asiallinen ja noudattaa hyvää makua.
Code example
import { Modal, useModal, Button, TextInput } from '@yleisradio/yds-components-react';

export const ModalSetNickName = () => {
const { modalRef, openModal, closeModal } = useModal();

return (
<>
<Modal modalRef={modalRef}>
<div
style={{
padding: '2rem 1.5rem 1.5rem',
display: 'flex',
flexDirection: 'column',
gap: '1rem',
width: '100%',
}}
>
<h2 style={{ margin: 0 }}>Aseta itsellesi nimimerkki</h2>
<div>Nimimerkin pitää olla asiallinen ja noudattaa hyvää makua.</div>
<TextInput label="Nimimerkki" placeholder="Aseta nimimerkki" />
<Button onClick={closeModal}>Hyväksy</Button>
</div>
</Modal>
<Button onClick={openModal}>Open Modal</Button>
</>
);
};

API Reference

Props

The Modal component accepts all standard HTML <dialog> attributes in addition to the following props:

PropTypeRequiredDefaultDescription
modalRefReact.RefObject<ModalHandle>NoRef handle for controlling the modal
onClose() => voidNoCallback fired when modal closes
scrollBehavior'content' | 'body'No'content'Scroll behavior for modal content
childrenReact.ReactNodeNoContent displayed inside the modal

Type Definitions

export interface ModalDSProps {
modalRef?: React.RefObject<ModalHandle>;
onClose?: () => void;
children?: React.ReactNode;
scrollBehavior?: 'content' | 'body';
}

export type ModalProps = HTMLAttributes<HTMLDialogElement> & ModalDSProps;

export type ModalHandle = {
open: () => void;
close: () => void;
};

useModal Hook

The useModal hook provides a convenient way to manage modal state.

Returns

PropertyTypeDescription
modalRefReact.RefObject<ModalHandle>Ref object to pass to the Modal component
openModal() => voidFunction to open the modal
closeModal() => voidFunction to close the modal
  • Dialog – Often used inside Modal for content structure
  • BottomSheet – Alternative component for mobile-friendly modals
  • useModal – Hook for managing modal state