To let a user interact with the application without jumping to a new page and interrupting the user's workflow.
Content
Provide enough information for the user to be able to take a decision in the spot, or a way to come back to the choice later.
Not use complex layouts, modals are not pages. Consider using a page when a modal layout is getting too complex.
Not rely on images or illustrations in order to provide essential information to the user.
Not ask the user a question right above the button(s).
Accessibility
Make sure to autofocus on the first interactive element in the modal, except if it’s a destructive action as it could trigger unwanted behavior.
Prioritize dismissible modals whenever possible in order to give control to the user.
Use modals sparingly as it disrupt the user's flow.
Modal vs Alert
If your modal has no way to be dismissed and requires the user to make a choice use an Alert.
Usage
Default
A modal must have an heading and a content.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Heading>Cloud City</Heading>
<Content>
<Paragraph>
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
</Modal>
</ModalTrigger>
Image
A modal can have a side banner image. Make sure the image has no essential information as it could be cropped in mobile view. Images should not prevent a user from seeing the close button, be conscious of this.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Image
src={{
base:SpacePortraitHorizontal,
sm:SpacePortrait
}}
alt="City over clouds"
/>
<Heading>Cloud City</Heading>
<Content>
<Paragraph>
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
</Modal>
</ModalTrigger>
Or an illustration. Prefer 1:1 ratio for illustrations to prevent them to render a Modal too high on small resolutions, alternatively in mobile use another illustration that has a 1:1 ratio.
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
</Modal>
</ModalTrigger>
Choice
A modal can offer a choice between 2 options. Keep the copy not too long in order to help the user quickly make his choice.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Heading>Which of the following movie is the greatest space movie?</Heading>
<Content>
<Card>
<Imagesrc={ET}alt="E.T. poster"/>
<Heading>E.T.</Heading>
<Content>
"E.T. phone home,"" mutters the titular character as he attempts to contact his
home planet, and audiences around the world fell in love. The timeless story of
an intimate friendship between a boy and his alien friend, “E.T.” has resonated
with generations of families, and is widely considered one of the greatest films
of all time.
</Content>
<Buttonvariant="secondary">Choose</Button>
</Card>
<Card>
<Imagesrc={TheMartian}alt="The Martian poster"/>
<Heading>The Martian</Heading>
<Content>
Based on the popular novel, “The Martian” is about mankind joining for a
singular mission: save astronaut Mark Watney, who was abandoned on Mars after
the rest of his crew made an emergency exit during a dust storm.
</Content>
<Buttonvariant="secondary">Choose</Button>
</Card>
</Content>
</Modal>
</ModalTrigger>
Header
Use an header to provide additional information usually in the form of a link or a tooltip that provides more context to the task at hand. Links should open in a new window.
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
</Modal>
</ModalTrigger>
Footer
Use a footer to provide trivial information about content present in the modal, like a step : 1/3.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Heading>Cloud City</Heading>
<Content>
<Paragraph>
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
<Footer>Copyright 2021</Footer>
</Modal>
</ModalTrigger>
Buttons
A modal can have a single button. Use a primary button to provide the main action.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Heading>Cloud City</Heading>
<Content>
<Paragraph>
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
<Button>Choose</Button>
</Modal>
</ModalTrigger>
Or a group of button. A maximum of 3 buttons are allowed in a modal, when necessary. The secondary and tertiary actions should be using a secondary variant.
Editable example
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<Modal>
<Heading>Cloud City</Heading>
<Content>
<Paragraph>
Cloud City was a completely man-made tibanna gas mining colony staff hovering over
the gas giant Bespin, occupied by millions of workers, tourists and support staff.
Located in Bespin's Life Zone, the station had no need for airlocks or life support
systems, with the atmosphere comprised mostly of oxygen and acceptable levels of
gravity and temperature.
</Paragraph>
<Paragraph>
The station was situated 59,000 kilometers above Bespin's core, while its disk was
approximately 16.2 kilometers in diameter. 36,000 repulsorlift engines and tractor
beam generators kept the giant city floating above the planet. It contained 392
levels, along with platforms and rooms for residents and visitors.
</Paragraph>
</Content>
<ButtonGroup>
<Buttonvariant="secondary">Select</Button>
<Button>Next</Button>
</ButtonGroup>
</Modal>
</ModalTrigger>
Modal context
A modal isOpen state or close function can be retrieved from useModalTriggerContext.
Apollo 11 is a 2019 American documentary film edited, produced and directed by
Todd Douglas Miller. It focuses on the 1969 Apollo 11 mission, the first
spaceflight from which men walked on the Moon.
</Paragraph>
<Paragraph>
The film consists solely of archival footage, including 70 mm film previously
unreleased to the public, and does not feature narration, interviews or modern
recreations. The Saturn V rocket, Apollo crew consisting of Buzz Aldrin, Neil
Armstrong, and Michael Collins, and Apollo program Earth-based mission
operations engineers are prominently featured in the film.
</Paragraph>
</Content>
<ButtononClick={close}variant="secondary">
Close
</Button>
</Modal>
);
});
render(()=>{
return(
<ModalTrigger>
<Buttonvariant="secondary">Open</Button>
<ApolloModal/>
</ModalTrigger>
);
});
Dismissable
By default, a modal will dismiss on outside interactions and esc keydown. However, in some cases, you might want to force the user to explicitly dismiss the modal with a targeted call to action. This is what the dismissable prop is for.
You can set the dismissable prop to false and render a call to action which will manually dismiss the popover by calling a close function retrieved from the useModalTriggerContext hook.
Inlining the call to useModalTriggerContext in ModalTrigger will not work.
Apollo 11 is a 2019 American documentary film edited, produced and directed
by Todd Douglas Miller. It focuses on the 1969 Apollo 11 mission, the first
spaceflight from which men walked on the Moon.
</Paragraph>
<Paragraph>
The film consists solely of archival footage, including 70 mm film
previously unreleased to the public, and does not feature narration,
interviews or modern recreations. The Saturn V rocket, Apollo crew
consisting of Buzz Aldrin, Neil Armstrong, and Michael Collins, and Apollo
program Earth-based mission operations engineers are prominently featured in
the film.
</Paragraph>
</Content>
<ButtononClick={handleClose}variant="secondary">
Close
</Button>
</Modal>
</ModalTrigger>
);
};
Custom trigger
You don't have to use a ModalTrigger component if it doesn't fit your needs. A modal component can be used on it's own with any custom trigger which follow a few rules:
The custom trigger provide a valid <DialogTriggerContext> with a close function.
The custom trigger is responsible of show/hide the modal. This is usually done in combination with an overlay component.