Modal
An overlay that appears in front of all other content, and requires a user to take an action before continuing.
Props
heading
string
The heading text displayed at the top of the modal.
closable
boolean
Show close icon and allow clicking the background to close the modal.
Defaults to
false.
open
boolean
Controls if modal is visible or not.
Defaults to
false.
transition
fast | slow | none
Sets the animation transition when opening/closing. 'fast' or 'slow' for animated, 'none' for instant.
Defaults to
none.
calloutVariant
CalloutVariant | null
Define the context and colour of the callout modal. It is required when type is set to callout.
maxWidth
string
Set the max allowed width of the modal.
Defaults to
60ch.
testId
string
Sets a data-testid attribute for automated testing.
Defaults to
modal.
version
1 | 2
The design system version for styling purposes.
Defaults to
1.
width
string
Use maxwidth instead.
Events
onClose
(event: Event) => void
_close
CustomEvent
Slots
heading
Named slot for content
content
Named slot for content
actions
Named slot for content
const [open, setOpen] = useState(false);
const [type, setType] = useState<string>();
const [name, setName] = useState<string>();
const [description, setDescription] = useState<string>();<GoabButton type="tertiary" leadingIcon="add" onClick={() => setOpen(true)}>
Add another item
</GoabButton>
<GoabModal
heading="Add a new item"
open={open}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="tertiary" size="compact" onClick={() => setOpen(false)}>
Cancel
</GoabButton>
<GoabButton type="primary" size="compact" onClick={() => setOpen(false)}>
Save new item
</GoabButton>
</GoabButtonGroup>
}
>
<p>Fill in the information to create a new item</p>
<GoabFormItem label="Type" mt="l">
<GoabDropdown onChange={(e) => setType(e.value)} value={type}>
<GoabDropdownItem value="1" label="Option 1" />
<GoabDropdownItem value="2" label="Option 2" />
</GoabDropdown>
</GoabFormItem>
<GoabFormItem label="Name" mt="l">
<GoabInput
onChange={(e) => setName(e.value)}
value={name}
name="name"
width="100%"
/>
</GoabFormItem>
<GoabFormItem label="Description" mt="l">
<GoabTextarea
name="description"
rows={3}
width="100%"
onChange={(e) => setDescription(e.value)}
value={description}
/>
</GoabFormItem>
</GoabModal>Confirm a change
const [open, setOpen] = useState(false);
const [effectiveDate, setEffectiveDate] = useState<Date | undefined>(new Date());
const onChangeEffectiveDate = (detail: GoabDatePickerOnChangeDetail) => {
setEffectiveDate(detail.value as Date);
};<GoabButton onClick={() => setOpen(true)}>Save and continue</GoabButton>
<GoabModal
heading="Address has changed"
open={open}
onClose={() => setOpen(false)}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="secondary" size="compact" onClick={() => setOpen(false)}>
Undo address change
</GoabButton>
<GoabButton type="primary" size="compact" onClick={() => setOpen(false)}>
Confirm
</GoabButton>
</GoabButtonGroup>
}>
<GoabContainer type="non-interactive" accent="filled" padding="compact" width="full">
<GoabText as="h4" mt="none" mb="s">Before</GoabText>
<GoabText mt="none">123456 78 Ave NW, Edmonton, Alberta</GoabText>
<GoabText as="h4" mt="none" mb="s">After</GoabText>
<GoabText mt="none" mb="none">881 12 Ave NW, Edmonton, Alberta</GoabText>
</GoabContainer>
<GoabFormItem label="Effective date" mt="l">
<GoabDatePicker
onChange={onChangeEffectiveDate}
name="effectiveDate"
value={effectiveDate}
/>
</GoabFormItem>
</GoabModal>Confirm a destructive action
const [open, setOpen] = useState(false);<GoabButton
type="tertiary"
leadingIcon="trash"
onClick={() => setOpen(true)}>
Delete record
</GoabButton>
<GoabModal
heading="Are you sure you want to delete this record?"
open={open}
onClose={() => setOpen(false)}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="tertiary" size="compact" onClick={() => setOpen(false)}>
Cancel
</GoabButton>
<GoabButton
type="primary"
variant="destructive"
size="compact"
onClick={() => setOpen(false)}>
Delete record
</GoabButton>
</GoabButtonGroup>
}>
<p>This action cannot be undone.</p>
</GoabModal>Confirm before navigating away
const [open, setOpen] = useState(false);
const handleChangeRoute = () => {
setOpen(false);
// In a real app, you would use your router's navigate function
// setTimeout(() => navigate("/some-path"), 300);
console.log("Navigating to new route...");
};<GoabButton onClick={() => setOpen(true)}>Open</GoabButton>
<GoabModal
heading="Are you sure you want to change route?"
open={open}
onClose={() => setOpen(false)}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="secondary" size="compact" onClick={() => setOpen(false)}>
Cancel
</GoabButton>
<GoabButton type="primary" size="compact" onClick={handleChangeRoute}>
Change route
</GoabButton>
</GoabButtonGroup>
}
/>Require user action before continuing
const [open, setOpen] = useState(false);<GoabButton onClick={() => setOpen(true)}>Open Basic Modal</GoabButton>
<GoabModal
heading="Are you sure you want to continue?"
open={open}
onClose={() => setOpen(false)}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="secondary" size="compact" onClick={() => setOpen(false)}>
Back
</GoabButton>
<GoabButton type="primary" size="compact" onClick={() => setOpen(false)}>
Continue
</GoabButton>
</GoabButtonGroup>
}
>
<p>You cannot return to this page.</p>
</GoabModal>Warn a user of a deadline
const [open, setOpen] = useState(false);<GoabButton type="secondary" onClick={() => setOpen(true)}>
Save for later
</GoabButton>
<GoabModal
heading="Complete submission prior to 1PM"
calloutVariant="important"
open={open}
onClose={() => setOpen(false)}
actions={
<GoabButtonGroup alignment="end">
<GoabButton type="primary" onClick={() => setOpen(false)}>
I understand
</GoabButton>
</GoabButtonGroup>
}
>
<p>
You've selected to adjourn a matter that is required to appear today. This Calgary court
location does not accept adjournment requests past 1PM MST. Please submit your
adjournment request as soon as possible.
</p>
</GoabModal>
);
}Content
Do
Use descriptive language in both modal content and button text to inform users of the resulting destructive action.
Submitting the assessment will inform the proponent and email a copy of the report.
Do
Use a concise and descriptive modal title that spans less than one line.
Are you sure that you want to cancel your application? This action will permanently cancel your application and delete any information collected.
Do
Use descriptive language in content and button text for destructive actions.
Types
Do
Use the destructive button variant for actions that cannot be easily undone, like permanently deleting data or removing a user from a system.
Don't
Don't use a destructive button to trigger a confirmation. Reserve destructive styling for the final action inside the modal.