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:

  • Display content in a window over other main page content
  • Control user interactions
  • Submission confirmations
  • Alert users
  • Require some action before closing
  • Prevent interacting with content outside the modal

Example

Open modalOpen modal with top slotOpen modal with bottom slotOpen modal positioned leftOpen modal positioned right
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.

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

Property and attribute binding examples for Genesis Component syntax. Closing tag omitted.

Attributes

AttributeTypeUseExample
typestringThe type of dialog on of default, alert or success. Defaults to default. This changes the styling depending on value.
<rapid-modal type="success">
positionstringDetermines the position of the modal. Possible options 'right', 'left', 'center' or 'left'.
<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">
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 will show the modal.modal.show()
close() => voidWhen called will close 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

This component doesn't fire any events.

Events listened to

This component doesn't listen to any events.