Disruptive, action-blocking overlays used to display important, task-relevant information
When rendering multiple modals on a single page you can reduce your markup size by using a single CdrModal instance to launch all of the modals.
In the above example the cdr-modal role
property of the "Terms and Conditions" modal has been changed to alertdialog
.
This role will notify users of critical information requiring their immediate attention.
<cdr-modal role="alertdialog" aria-describedby="description" label="modal title">
<div id="description">
modal content description
</div>
</cdr-modal>
Generally they have at least a Confirmation and close button but can have additional interactive controls as needed. Like a traditional modal dialog, alert dialogs move and capture the users focus to the blocking overlay window. By default focus will be placed on the modal window however for alert dialogs you should alter this to be placed on the most appropriate interactive control
The alertdialog
role should only be used when an alert occurs.
Additionally, an alert dialog may only be used for alert messages which have associated interactive controls.
Review alert for requirements on an alert which only contains static content and has no interactive controls.
Ensure that usage of this component complies with accessibility guidelines:
aria-haspopup="dialog"
to the button element:<cdr-button
aria-haspopup="dialog"
>Launch modal</cdr-button>
aria-describedby
prop to point to an element that describes what the modal does: <cdr-modal aria-describedby="description" label="modal title">
<div id="description">
modal content description
</div>
</cdr-modal>
This component complies with WCAG guidelines by:
label
prop to set the aria-labelaria-hidden
and tabindex="-1"
on focusable items for all content outside of the modalopened
name
Boolean
type
N/A
default
Toggles the state of the modal. Required.
label
name
string
type
N/A
default
Text used to generate the `aria-label` attribute as well as the modal title text, if `labelSlot` is empty. Required.
showTitle
name
boolean
type
true
default
Toggles the modal title text, which comes from `label` or `labelSlot`.
ariaDescribedby
name
string
type
'medium'
default
Text for the `aria-describedby` attribute.
id
name
string
type
null
default
Unique id for modal.
role
name
string
type
dialog
default
Overrides the `role` attribute on the modal content element. Possible values: { 'dialog' | 'alertdialog' }
overlayClass
name
string
type
N/A
default
Adds a custom class to the `cdr-modal__overlay` div.
wrapperClass
name
string
type
N/A
default
Add a custom class to the `cdr-modal__outerWrap` div.
contentClass
name
string
type
N/A
default
Add a custom class to the `cdr-modal__innerWrap` div.
animationDuration
name
number
type
300
default
Sets animation duration for when the modal is closed.
Find more information about using Slots in the article Installing Cedar.
default
name
Slot for CdrModal content.
title
name
Slot for CdrModal title.
modal
name
Slot to override the entire CdrModal content.
closed
name
$emit event fired when closing the modal.
If the title
slot is left empty, the label
prop will be rendered as the title. The title can be hidden altogether by setting showTitle
to false
.
When using the label
slot, add CdrText to use the appropriate header styles.
<template #title>
<cdr-text
tag="h1"
class="custom-text-class"
>Add to Cart
</cdr-text>
</template>
modal
Override SlotThe modal
override slot provides teams a way to work from essentially a blank slate when creating their modal content. This is useful for situations where more art-direction or custom functionality is required. It is important to note that creating a clear way to close the modal is still required to meet user-experience and accessibility standards (i.e. relying only on the esc key is not enough).
<cdr-modal
v-if="opened"
:opened="opened"
label="Fancy modal"
@closed="closed"
aria-describedby="description"
role="dialog"
>
...
<template #modal>
...fancy modal code
<cdr-button @click="close">Close modal</cdr-button>
</template>
</cdr-modal>
The modal has a default width of 640px
which converts to a fullscreen view at xs
screen sizes.
The modal content area will scroll vertically if there's enough content. The modal title does not scroll; it stays affixed to the top of the modal.
Do not use v-if
with CdrModal unless the component is wrapped with keep-alive
. CdrModal handles showing and hiding itself when toggling, so v-if
should be unneeded in most cases.
<keep-alive>
<cdr-modal
v-if="opened"
:opened="opened"
label="Add to Cart"
@closed="closed"
aria-describedby="description"
>
...
</cdr-modal>
</keep-alive>