---
title: Modal
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, PropsTable, TokensTable } from '../../src/components'
import { Modal as BaseDocs } from 'docs/@telus-uds/components-base'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# Modal

<LibraryInfo figmaLink="https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2F4zJn2Qn6uXOqPP1GVDipy6%2F%25F0%259F%258D%2580-Allium-Components%3Fnode-id%3D3756%253A44766" />

```jsx live
function ModalExample() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <>
      <Button onPress={() => setIsOpen(true)}>Open "Modal"</Button>
      <Modal isOpen={isOpen} onClose={() => setIsOpen(false)}>
        <Typography variant={{ size: 'h2' }}>This is a Modal</Typography>
        <Box vertical={4}>
          <Typography>
            This is some modal content. You can pass any children to the Modal to achieve your
            desired look.
          </Typography>
        </Box>
      </Modal>
    </>
  )
}
```

## Introduction

A modal window is a secondary window that opens on top of the main one.

Users have to interact with it before they can carry out their task and return to the main window.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

Use to reveal additional information to a user after they have performed an explicit interaction.

They are a strongly discouraged pattern; it's preferred to have all relevant information within a page,
and irrelevant information either linked externally or omitted.

- Must only appear after a customer interaction, not on page load or any other circumstance
- Open a modal based on explicit customer action e.g. clicking on a button/link/form field
- Only one modal should be "current" at any time
- Read [WebAIM's documentation](https://www.w3.org/TR/wai-aria-practices/examples/dialog-modal/dialog.html) to create accessible modals
- Don’t use modals to reinforce or repeat information already available in the parent page or view
- Don’t use modals consecutively
- Default modal width is 576px, except for the XS / SM viewports where the modal takes up 100% of the screen

On the web, `Modal` component has a set of web only properties that applies some specific decisions about content structure and styling to the base Modal component that is exported from `@telus-uds/components-base`.

:::caution

ContentModal and DialogModal are web only recipes.

:::

## ContentModal

A content modal provides a way for the customer to access additional information without leaving the current page or view, and maintain context.
It’s also an effective technique to catch the customer's attention to something vital, a specific task, or set of information.

```jsx live
function ContentModalExample() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <>
      <Button onPress={() => setIsOpen(true)}>Open "Content Modal"</Button>
      <Modal
        isOpen={isOpen}
        onClose={() => setIsOpen(false)}
        heading="Make a statement for a content modal"
        subHeading="Subheading for context"
        subHeadingSize="large"
        bodyText="Use a content modal for dismissible content. A content modal provides a way for the user to access additional information without leaving the current page or view, and maintain context"
        confirmButtonText="Continue"
        onConfirm={() => setIsOpen(false)}
      />
    </>
  )
}
```

## DialogModal

A dialog modal provides information to the customer and prompts them for a response.

- Use dialog modals as a means for customers to safely make actions that require their full attention, such as confirmations of destructive actions
- The copy on the modal should clearly lead to confirm or reject an impending decision and if possible the outcomes
- Avoid dialog modals:
  - if there are more than 2 options for customer consideration
  - as alerts to display errors, warnings, and success messages
  - being shown consecutively

```jsx live
function DialogModalExample() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <>
      <Button onPress={() => setIsOpen(true)}>Open "Dialog Modal"</Button>
      <Modal
        isOpen={isOpen}
        onClose={() => setIsOpen(false)}
        onCancel={() => setIsOpen(false)}
        heading="Ask a question that confirms the customer action which initiated the dialog modal"
        bodyText="Use a dialog modal to provide information and prompt for a response to customer action, which may lead to a significant impact on account or lead to unrecoverable states."
        confirmButtonText="Confirm"
        onConfirm={() => setIsOpen(false)}
        cancelButtonText="Cancel"
      />
    </>
  )
}
```

## Custom Footer

You can pass a custom footer to the modal, which will override the default footer content

```jsx live
function ModalWithCustomFooterExample() {
  const [isOpen, setIsOpen] = useState(false)
  return (
    <>
      <Button onPress={() => setIsOpen(true)}>Open "Modal with custom footer"</Button>
      <Modal
        isOpen={isOpen}
        onClose={() => setIsOpen(false)}
        heading="This is a Modal with custom footer"
        footer={
          <StackView direction="row" space={2}>
            <Button variant={{ priority: 'high' }}>Accept</Button>
            <Button variant={{ priority: 'low' }} onPress={() => setIsOpen(false)}>
              Cancel
            </Button>
            <ChevronLink
              href="https://www.telus.com"
              tokens={{
                alignSelf: 'center'
              }}
            >
              Learn more
            </ChevronLink>
          </StackView>
        }
      >
        <Box vertical={4}>
          <Typography>
            This is some modal content. You can pass any children to the Modal to achieve your
            desired look.
          </Typography>
        </Box>
      </Modal>
    </>
  )
}
```

### Accessibility

- Be aware that a modal's appearance will put users of assistive technology in a new focus context. This may be
  disorientating, so be sure to ensure a modal's content and role is easy to understand and easy to get out of.
- Long `bodyText` may scroll within the modal. Not all devices and operating systems make it visually apparent that
  scrollable sections of a page are scrollable, so try to avoid long text that might overflow.

### Platform considerations

The `Modal` component is currently only supported on web.

The `BaseModal` component is available on both native platforms and web.

## Props

<PropsTable base={BaseDocs} />

## Tokens

<TokensTable base={BaseDocs} component="Modal" />

## Variants

### Width

Use corresponding `width` variant to specify the desired width of the modal:

```jsx live
function ModalExample() {
  const [isOpen, setIsOpen] = useState(false)

  return (
    <>
      <Button onPress={() => setIsOpen(true)}>Open "Modal"</Button>
      <Modal isOpen={isOpen} onClose={() => setIsOpen(false)} variant={{ width: 's' }}>
        <Typography variant={{ size: 'h2' }}>This is a Modal</Typography>
        <Box vertical={4}>
          <Typography>
            This is some modal content. You can pass any children to the Modal to achieve your
            desired look.
          </Typography>
        </Box>
        <Button onPress={() => setIsOpen(false)}>Close Modal</Button>
      </Modal>
    </>
  )
}
```

Currently available widths are the following:

- `'s'`: 320px,
- `'m'`: 480px (also max-width on MD viewports),
- `'l'`: 630px (also max-width on LG viewports),
- `'xl'`: 768px (also max-width on XL viewports)

## Feedback

<Feedback component="Modal" />
