vue-universal-modal
A light Universal modal Component for Vue 3.
Introduction
vue-universal-modal
plugin is based on the teleport.
It is very light and simple, but it provides essential features for modal use in applications.
(Such as Add & Remove, Visible & Hidden, Transition, Auto bind keyboard and mouse to close, Support SSR, A11Y...)
Here is the Demo
Features
- Based on the teleport
- Provides essential features for modal
- A11Y
- Support SSR (Insert rendering source into SSR context, Mount from Client-side)
Install plugin
Insert teleport element in your html
Because SSR cannot be implemented by dynamically creating and ref referencing teleport elements, teleport targets must be inserted into html first.
And install plugin in vue application
Options
name | type | detault | description |
---|---|---|---|
teleportTarget (required) | string |
Teleport target | |
modalComponent | string |
'Modal' |
Global modal component name |
Usage modal
Insert the component wrapped with the modal component. (Slot based)
v1.0.x -> v1.1.x change point
- Use
v-model
instead of v-if for modal component insertion- If you control the insertion of components with v-if, the close animation will not work.
emitClose
slot argument was deprecated.
props
name | type | detault | description |
---|---|---|---|
close | function |
() => {} |
Function to close a modal (apply when click dimmed) |
disabled | boolean |
false |
Handle just visibility (as in v-show) |
options | object |
{} |
props.options
name | type | detault | description |
---|---|---|---|
transition | number | false |
300 |
transition duration |
closeClickDimmed | boolean |
true |
Closes the modal when dimmed is clicked |
closeKeyCode | number | false |
27 (esc) |
Closes the modal when press key |
styleModalContent | object |
{} |
Inject modal content style (.vue-universal-modal-content ) |
emit events
Supports emit properties for all transition events.
Handle global CSS
You can change it directly to your own style by referring to the source