ModalConfirm
is a convenience wrapper on top of Modal. It is intended to use for showing confirmation dialogs.
Import
import { ModalConfirm } from '@contentful/f36-components';// orimport { ModalConfirm } from '@contentful/f36-modal';
Examples
Basic
ModalConfirm
has 3 different intents: positive
, primary
and negative
. Changing this property changes the variant of the primary button.
Here is an example of a modal with a positive intent:
Changing button labels
You can change action button labels by using cancelLabel
and confirmLabel
.
Changing sizes
There are 4 different sizes for modals: small
, medium
, large
, fullWidth
. Pick a size based on the amount of content you have to present in them.
ModalConfirm
behavior is exacly the same as Modal. Please, refer to Modal documentation for code example.
Using ModalLauncher
When you want to open a modal from a function (outside of React component code), use ModalLauncher.
Props (API reference)
- Name
children(required)
ReactNode - Name
isShown(required)
DescriptionWhen true, the dialog is shown.
falsetrue - Name
onCancel(required)
DescriptionFunction that will be called when the cancel button is clicked. This does not close the ModalConfirm.
(event: MouseEvent<Element, MouseEvent> | KeyboardEvent<Element>) => void - Name
onConfirm(required)
DescriptionFunction that will be called when the confirm button is clicked. This does not close the ModalConfirm.
() => void - Name
allowHeightOverflow
DescriptionAre modals higher than viewport allowed
Defaultfalsetruefalse - Name
cancelLabel
DescriptionLabel of the cancel button
DefaultstringfalseCancel - Name
cancelTestId
Defaultstringcf-ui-modal-confirm-cancel-button - Name
confirmLabel
DescriptionLabel of the confirm button
DefaultstringfalseConfirm - Name
confirmTestId
Defaultstringcf-ui-modal-confirm-confirm-button - Name
initialFocusRef
DescriptionOptional property to set initial focus
RefObject<HTMLElement> - Name
intent
DescriptionThe intent of the ModalConfirm. Used for the Button.
Default"primary""positive""negative"positive - Name
isConfirmDisabled
DescriptionWhen true, the confirm button is set to disabled.
Defaultfalsetruefalse - Name
isConfirmLoading
DescriptionWhen true, the confirm button is set to loading.
Defaultfalsetruefalse - Name
modalContentProps
DescriptionOptional props to override ModalContent behaviour
Partial<ModalContentProps> - Name
modalControlsProps
DescriptionOptional props to override ModalControl behaviour
Partial<ModalControlsProps> - Name
modalHeaderProps
DescriptionOptional props to override ModalHeader behaviour
Partial<ModalHeaderProps> - Name
shouldCloseOnEscapePress
DescriptionBoolean indicating if pressing the esc key should close the overlay.
Defaultfalsetruetrue - Name
shouldCloseOnOverlayClick
DescriptionBoolean indicating if clicking the overlay should close the overlay.
Defaultfalsetruetrue - Name
size
DescriptionSize of the modal window
Defaultstringnumbermedium - Name
testId
Defaultstringcf-ui-modal-confirm - Name
title
DescriptionModal title that is used in header
DefaultstringAre you sure?
Content guidelines
Please, refer to Modal documentation.
Accessibility
- When the modal opens, focus is trapped within it.
- When the modal opens, focus is automatically set to the
Cancel
button, or the element frominitialFocusRef
. - When the modal closes, focus returns to the element that was focused before the modal activated.
- By default, clicking on the overlay closes the modal.
- By default, pressing
Esc
closes the modal. - Scrolling is blocked on the elements behind the modal.