Skip to main content

Modal

A modal is a type of dialog that prevents the user from interacting with other content on the page. Usually, when an active modal is displayed, all other content on the screen is dimmed. The user is unable to move focus to other windows or dialogs. This forces the user to deal with the modal before moving to other work on the application.

By default, the modal starts in a closed state.

Use cases:

  • displaying content in a window over other main page content
  • controlling user interactions
  • submission confirmations
  • alerting users
  • requiring some user action before closing
  • preventing interaction with content outside the modal

Example

Open modalOpen modal with top slotOpen modal with bottom slotOpen modal positioned leftOpen modal positioned rightOpen draggable modalOpen draggable and resizable modal
Modal example

Top slot

Modal example with top slot
Modal example with bottom slot
Slotted content in the bottom

This is a modal. It is positioned to the left.

This is a modal. It is positioned to the right.

Draggable modal

This modal can be dragged.

Resizable modal

This modal can be resized by dragging the edges or corners. Clicking the edges expands it to the edge of the window.

Resizable modal

This modal can be dragged and resized by dragging the edges or corners. Clicking the edges expands it to the edge of the window.

Declaration

<rapid-modal></rapid-modal>

Usage

@customElement({
name: 'my-element',
template: html`
<rapid-button @click=${x => x.modal.show()}>Open Modal</rapid-button>
<rapid-modal
${ref('modal')}
:onShowCallback=${x => () => x.showCallback}
:onCloseCallback=${x => () => x.closeCallback}
>
<h3 slot="top">Top slot</h3>
Main content in the modal
<div slot="bottom">
<i>Slotted content in the bottom</i>
</div>
</rapid-modal>
`,
})
export class MyElement extends GenesisElement {
modal: Modal
showCallback() {
console.log('modal shown');
}
closeCallback() {
console.log('modal closed');
}
}

DOM API

The sections below provide property and attribute binding examples for Genesis Component syntax. The HTML closing tag is not included.

Attributes

AttributeTypeUseExample
typedefault alert error successThe type of dialog, one of default, error or success or alert. Defaults to default. This changes the background color of the modal.
<rapid-modal type="success">
positioncenter left rightDetermines the position of the modal. Defaults to center.
<rapid-modal position="right">
show-close-iconbooleanEnables the close icon in the top right corner of the modal. Defaults to 'true'.
<rapid-modal show-close-icon="false">
draggablebooleanEnables dragging the modal. Defaults to 'false'.
<rapid-modal draggable="true">
resizablebooleanEnables resizing the modal. Defaults to 'false'.
<rapid-modal resizable="true">
initial-widthnumberSets the initial width, in pixels, of the modal when it is first opened.
<rapid-modal initial-width="500">
initial-heightnumberSets the initial height, in pixels, of the modal when it is first opened.
<rapid-modal initial-height="400">
min-widthnumberSets the minimum width, in pixels, that the modal can be resized to. Only applies when resizable is set to true.
<rapid-modal resizable="true" min-width="300">
min-heightnumberSets the minimum height, in pixels, that the modal can be resized to. Only applies when resizable is set to true.
<rapid-modal resizable="true" min-height="200">
note

If you set position to be left or right, the modal will assume height: 100% by default. To change this, make the appropriate css modifications.

Properties

PropertyTypeUseExample
onShowCallback() => voidFunction that runs before modal is opened.
<rapid-modal :onShowCallback="${() => () => console.log('shown')}">
onCloseCallback() => voidFunction that is called after the modal is closed.
<rapid-modal :onCloseCallback="${() => () => console.log('hide')}">

Component Methods

MethodTypeUseExample
show() => voidWhen called, shows the modal.modal.show()
close() => voidWhen called, closes the modal.modal.close()

Slots

SlotUse
DefaultThe default slot for the main content of the modal.
topThe header section at the top of the modal.
bottomThe footer section at the bottom of the modal.

Parts

PartUse
dialogThe container element containing the modal dialog.
contentThe content container element
topThe top part of the modal, which contains the modal dialog header.
close-iconThe close icon in the top right hand corner of the modal dialog.
bottomThe footer section of the modal dialog.

Events fired

EventTypeDescriptionExample
closevoidFired when the dialog is closed, either through the close button, escape key, or programmatic close.<rapid-modal @close="${(x) => x.handleDialogClose()}">

Events listened to

This component doesn't listen to any events.