Modal

Modal

import Modal, { ModalSection } from "@kiwicom/orbit-components/lib/Modal";
<Modal>
<ModalSection>Hello World!</ModalSection>
</Modal>

Props

NameTypeDefaultDescription
childrenReact.NodeThe content of the Modal. See Subcomponents
lockScrollingbooleantrueWhether to prevent scrolling of the rest of the page while Modal is open. This is on by default to provide a better user experience.
scrollingElementRefref (object or function)The scrolling element, which depends on the viewport.
dataTeststringOptional prop for testing purposes.
idstringSet id for Modal.
fixedFooterbooleanfalseIf true the ModalFooter will be fixed to the bottom of window.
isMobileFullPagebooleanfalseIf true the Modal will look like a page on mobile devices.
sizeenum"normal"The maximum width of the Modal on desktop viewport.
onCloseevent => void \| PromiseFunction for handling onClose event. If you don’t pass any function the Close button will not be displayed and it will not be possible to close the Modal. See Functional specs.
preventOverlayClosebooleanProperty for preventing closing of modal when there is a action on overlay. BEWARE: This should be used only in very specials edge-cases! It breaks user experience.
hasCloseButtonbooleantrueDefines whether the Modal displays a close button. If you disable this, we recommend adding some kind of an alternative.
autoFocusbooleantrueThe autofocus attribute of the Modal, see this docs.
disableAnimationbooleanfalseDefines whether the Modal performs the slide in animation on mobile. If you want to improve your CLS score, you might want to set this to true.
mobileHeaderbooleantrueIf false the ModalHeader will not have MobileHeader and CloseContainer.
labelClosestringCloseThe label for the close button.
onScrollevent => void \| PromiseFunction for handling onScroll event. See Functional specs.

Modal enum

size
"extraSmall"
"small"
"normal"
"large
"extraLarge"

Functional specs

  • const modalRef = React.useRef<React.ElementRef<typeof Modal> | null>(null)
  • class Component extends React.Component {
    const modalRef = React.useRef<React.ElementRef<typeof Modal> | null>(null)
    const getScroll = () => {
    if (modalRef.current) {
    setLocalScrollPosition(modalRef.current.getScrollPosition());
    }
    };
    render() {
    return (
    <Modal ref={modalRef}>
    Some content.
    </Modal>
    );
    }
    }
  • class Component extends React.Component {
    const modalRef = React.useRef<React.ElementRef<typeof Modal> | null>(null)
    setScroll = () => {
    if (modalRef.current) {
    modalRef.current.setScrollPosition(100);
    }
    };
    render() {
    return (
    <Modal ref={modalRef}>
    <ModalSection>Example usage of setting up the scrollTop position</ModalSection>
    <ModalFooter>
    <Button onClick={this.setScroll}>Change scrollTop</Button>
    </ModalFooter>
    </Modal>
    );
    }
    }

Subcomponents

ModalSection

import Modal, { ModalSection } from "@kiwicom/orbit-components/lib/Modal";

Usage

<Modal>
<ModalSection suppressed>Hello World!</ModalSection>
</Modal>

Props

NameTypeDefaultDescription
childrenReact.NodeContent of the ModalSection component.
dataTeststringOptional prop for testing purposes.
suppressedbooleanfalseIf true the ModalSection will have cloudy background.

ModalHeader

import Modal, { ModalHeader } from "@kiwicom/orbit-components/lib/Modal";

Usage

<Modal>
<ModalHeader title="Orbit design system">Hello World!</ModalHeader>
</Modal>

Props

NameTypeDefaultDescription
childrenReact.NodeThe content of the ModalHeader.
dataTeststringOptional prop for testing purposes.
descriptionReact.NodeThe displayed description of the ModalHeader.
illustrationReact.Element<typeof Illustration>The displayed Illustration of the ModalHeader.
suppressedbooleanfalseIf true the ModalHeader will have cloudy background.
titleReact.NodeThe displayed title of the ModalHeader.

ModalFooter

import Modal, { ModalFooter } from "@kiwicom/orbit-components/lib/Modal";
// and probably Button
import Button from "@kiwicom/orbit-components/lib/Button";

Usage:

<Modal fixedFooter>
<ModalFooter flex={["0 0 auto", "1 1 100%"]}>
<Button type="secondary" iconLeft={<ChevronBackward />}>
Back
</Button>
<Button block>Continue to Payment</Button>
</ModalFooter>
</Modal>

Props

NameTypeDefaultDescription
childrenReact.NodeThe content of the ModalFooter.
dataTeststringOptional prop for testing purposes.
flexstring or Array<string>"0 1 autoThe flex attribute(s) for children of the ModalFooter. See Functional specs

ModalFooter Functional specs

  • You can set up different flex attribute for every children, or use one for all. See flex property docs for more information.

Use cases

Wrapper ModalSections

// good
<Modal fixedFooter>
<CustomWrapper>
<ModalHeader />
<ModalSection>
My content
</ModalSection>
<ModalSection>
My content
</ModalSection>
<ModalFooter />
</CustomWrapper>
</Modal>
// bad, the CSS styles will be broken
<Modal fixedFooter>
<ModalHeader />
<CustomWrapper>
<ModalSection>
My content
</ModalSection>
<ModalSection>
My content
</ModalSection>
</CustomWrapper>
<ModalFooter />
</Modal>

Accessibility

  • When Modal is closed return focus to the element that opened the modal. You can use onClose callback function to achieve this.