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)
- Namechildren(required)ReactNode
- NameisShown(required)DescriptionWhen true, the dialog is shown. falsetrue
- NameonCancel(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
- NameonConfirm(required)DescriptionFunction that will be called when the confirm button is clicked. This does not close the ModalConfirm. () => void
- NameallowHeightOverflowDescriptionAre modals higher than viewport allowed Defaultfalsetruefalse
- NamecancelLabelDescriptionLabel of the cancel button DefaultstringfalseCancel
- NamecancelTestIdDefaultstringcf-ui-modal-confirm-cancel-button
- NameconfirmLabelDescriptionLabel of the confirm button DefaultstringfalseConfirm
- NameconfirmTestIdDefaultstringcf-ui-modal-confirm-confirm-button
- NameinitialFocusRefDescriptionOptional property to set initial focus RefObject<HTMLElement>
- NameintentDescriptionThe intent of the ModalConfirm. Used for the Button. Default"primary""positive""negative"positive
- NameisConfirmDisabledDescriptionWhen true, the confirm button is set to disabled. Defaultfalsetruefalse
- NameisConfirmLoadingDescriptionWhen true, the confirm button is set to loading. Defaultfalsetruefalse
- NamemodalContentPropsDescriptionOptional props to override ModalContent behaviour Partial<ModalContentProps>
- NamemodalControlsPropsDescriptionOptional props to override ModalControl behaviour Partial<ModalControlsProps>
- NamemodalHeaderPropsDescriptionOptional props to override ModalHeader behaviour Partial<ModalHeaderProps>
- NameshouldCloseOnEscapePressDescriptionBoolean indicating if pressing the esc key should close the overlay. Defaultfalsetruetrue
- NameshouldCloseOnOverlayClickDescriptionBoolean indicating if clicking the overlay should close the overlay. Defaultfalsetruetrue
- NamesizeDescriptionSize of the modal window Defaultstringnumbermedium
- NametestIdDefaultstringcf-ui-modal-confirm
- NametitleDescriptionModal 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 Cancelbutton, 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 Esccloses the modal.
- Scrolling is blocked on the elements behind the modal.