AisModal
Modals are streamlined, but flexible dialog prompts powered by JavaScript and CSS. They support a number of use cases from user notification to completely custom content and feature a handful of helpful sizes, variants, and more.
The content of an AisModal is an AisCard. Like the card, there is no header or footer by default, just the body. Use the header and/or footer props or slots to create a header and/or footer.
Basic
A basic modal using only the body of the underlying card. Notice how the triggering button activates the keep-focus property. This allows the modal to return focus to the trigger when it is closed. If the original button blurs and loses focus, focus will be reset to the top of the page when the modal closes.
Header & Footer
The modal has logic built-in to handle a header-level icon. This icon can be used via the icon prop or by using the icon slot.
Props
Use icon and status props to easily customize your card header. Likewise, you can use footer-icon and footer-status to easily customize your card footer. You can also use icon-class, status-class, footer-icon-class, footer-status-class to further customize your styles. modal.
Slots
For custom content use the header and/or footer slots.
Or just customize the right side of the header and/or footer with the headerRight and/or footerRight slots.
Variants
Use the variant prop to change the look of your modal. The accepted values are: default, primary, secondary, info, success, warning, danger, plain.
Sizes
The size prop controls the modal size. The accepted values are: sm, md, lg, and xl. The default value is md.
Rounded
Use the rounded prop to specify the border radius for the modal. The accepted values are: true, false, sm, rounded, md, lg, xl, 2xl, 3xl, and full. The default is 2xl.
Custom Styles
You can control the styles of the modal via a few of the props. The class prop adds the passed-in classes to the modal container. The title-class prop adds the passed-in classes to the modal title. The dismiss-class adds the passed-in classes to the dismiss icon.
dismissible
dismissible is a Boolean prop with a default value of true. When true, AisModal can be dismissed/closed. To prevent the modal from closing, use :dismissible="false". You can still dismiss the modal by setting the v-model of the modal to false.
click-away
click-away is a Boolean prop with a default value of true. When true, AisModal will close when a click event is triggered outside of the modal. To prevent the modal from closing when a click event is triggered outside of the modal, use :click-away="false".
Clicking the dismiss button and pressing esc will still close the modal.
Notice: AisModal is configured to ignore a click-away on any element with the class .ais-ignore-click-away. You can use AisModal's clickAwayOptions prop to customize the click-away behavior, and the example below shows how to configure the default behavior. See VueUse's useClickAway for details on the available options.
no-body
AisModal is built with AisCard, so you can add the no-body boolean prop for the same results. This can be useful with tables and list groups, for example.
Table
Nested AisTable, similar to the "Nested Table" Example in AisCard
List Group
Nested AisListGroup, similar to the "Inside AisCard" Example in AisListGroup
Events
The modal emits four events:
showemits just before the modal is shown.shownemits immediately after the modal is shown.hideemits just before the modal is hidden.hiddenemits immediately after the modal is hidden.
Component Reference
Props
Property | Type(s) | Required | Default | Description | Deprecated |
|---|---|---|---|---|---|
| class | Array, String | 'bg-white' | CSS classes for modal body | false | |
| clickAway | Boolean | true | When true, the modal closes when a click event happens outside of the modal | false | |
| clickAwayOptions | Object | {
ignore: ['.ais-ignore-click-away']
} | Options to configure click-away behavior. This object will be passed to VueUses' onClickOutside function.
See useClickAway for details. | false | |
| descr | String | '' | Text for the aria-describedby for the modal | false | |
| dismissButton | Boolean | true | When true, the close button is displayed in the upper right corner of the header (or body, if no header) | false | |
| dismissClass | Array, String | [] | Class(es) applied to the dismiss button | false | |
| dismissible | Boolean | true | When true, the modal can be closed. When false, the modal will stay open and the dismiss
button (if visible) will be hidden | false | |
| enter | Array, String | '' | Classes to add to the transitioning element during the entire enter phase. | false | |
| enterFrom | Array, String | '' | Classes to add to the transitioning element before the enter phase starts. | false | |
| enterTo | Array, String | '' | Classes to add to the transitioning element immediately after the enter phase starts. | false | |
| entered | Array, String | '' | Classes to add to the transitioning element once the transition is done. These classes will persist after that,
until it's time to leave. | false | |
| header | String | '' | The title of the modal | false | |
| headerClass | Array, Object, String | undefined | Classes to be applied to the modal header | false | |
| leave | Array, String | '' | Classes to add to the transitioning element during the entire leave phase. | false | |
| leaveFrom | Array, String | '' | Classes to add to the transitioning element before the leave phase starts. | false | |
| leaveTo | Array, String | '' | Classes to add to the transitioning element immediately after the leave phase starts. | false | |
| modelValue | Boolean | false | Controls whether the modal is shown/visible | false | |
| rounded | Boolean, String | undefined | Applies rounded corners using
TailwindCSS's rounded classes | false | |
| size | String | 'md' | Set the size of the modal's width. Valid values: sm, md, lg, or xl | false | |
| title | String | | Text content to place in the title | false |
Slots
Name | Scoped | Description |
|---|---|---|
| default | No | Slot for custom rendering the content of the modal |
| footer | No | Slot for custom rendering the modal footer |
| footerRight | No | Slot for custom rendering the right side of the modal footer. Note: this slot will be ignored if the footer slot is used |
| header | No | Slot for custom rendering the modal header |
| headerRight | No | Slot for custom rendering the right side of the modal header. Note: this slot will be ignored if the header slot is used |
Events
Event | Arguments | Description |
|---|---|---|
| hidden |
| Emitted immediately after the modal is hidden |
| hide |
| Emitted immediately before the modal is hidden |
| show |
| Emitted immediately before the modal is shown |
| shown |
| Emitted immediately after the modal is shown |
| update:modelValue |
| Emitted when the modal is shown or hidden |