Overlay
Demos
Custom positioning
Overlays can be positioned with custom styles.
<template>
<article>
<veui-button
ref="toggle"
@click="open = !open"
>
Toggle
</veui-button>
<veui-overlay
:open.sync="open"
overlay-class="centered-overlay"
>
<div v-outside:toggle="hide">
Centered
</div>
</veui-overlay>
</article>
</template>
<script>
import { Overlay, Button, outside } from 'veui'
export default {
components: {
'veui-overlay': Overlay,
'veui-button': Button
},
directives: { outside },
data () {
return {
open: false
}
},
methods: {
hide () {
this.open = false
}
}
}
</script>
<style lang="less" scoped>
.centered-overlay {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
height: 100px;
}
.centered-overlay {
line-height: 100px;
text-align: center;
border: 1px solid #dbdbdb;
background-color: #fff;
}
</style>
Position relative to an element
Overlays can also be positioned relative to an existing DOM element in the page.
<template>
<article>
<veui-button
ref="toggle"
@click="open = !open"
>
Toggle
</veui-button>
<veui-overlay
target="toggle"
position="top-start"
:open.sync="open"
overlay-class="relative-overlay"
>
<div v-outside:toggle="hide">
Relatively Positioned
</div>
</veui-overlay>
</article>
</template>
<script>
import { Overlay, Button, outside } from 'veui'
export default {
components: {
'veui-overlay': Overlay,
'veui-button': Button
},
directives: { outside },
data () {
return {
open: false
}
},
methods: {
hide () {
this.open = false
}
}
}
</script>
<style lang="less" scoped>
.veui-overlay {
display: none;
}
.relative-overlay {
width: 200px;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #dbdbdb;
background-color: #fff;
.veui-button {
margin-left: 10px;
}
}
</style>
Stacking order
For sibling overlays with same priority, the ones opened later have a higher stacking order.
<template>
<article>
<veui-button
ref="a"
@click="aOpen = !aOpen"
>
Toggle A
</veui-button>
<veui-overlay
target="a"
position="top-start"
:open.sync="aOpen"
overlay-class="relative-overlay"
>
A
</veui-overlay>
<veui-button
ref="b"
@click="bOpen = !bOpen"
>
Toggle B
</veui-button>
<veui-overlay
target="b"
position="top-start"
:open.sync="bOpen"
overlay-class="relative-overlay"
>
B
</veui-overlay>
<veui-button
ref="c"
@click="cOpen = !cOpen"
>
Toggle C
</veui-button>
<veui-overlay
target="c"
position="top-start"
:open.sync="cOpen"
overlay-class="relative-overlay"
>
C
</veui-overlay>
<veui-button
ui="xs"
@click="aOpen = bOpen = cOpen = false"
>
Hide all
</veui-button>
</article>
</template>
<script>
import { Overlay, Button } from 'veui'
export default {
components: {
'veui-overlay': Overlay,
'veui-button': Button
},
data () {
return {
aOpen: false,
bOpen: false,
cOpen: false
}
}
}
</script>
<style lang="less" scoped>
.veui-overlay {
display: none;
}
.relative-overlay {
width: 200px;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #dbdbdb;
background-color: #fff;
.veui-button {
margin-left: 10px;
}
}
</style>
Opened overlays will establish new stacking contexts and overlays opened inside those overlays will have higher stacking order than their parents.
<template>
<article>
<veui-button
ref="parent"
@click="parentOpen = !parentOpen"
>
Toggle
</veui-button>
<veui-overlay
target="parent"
position="top-start"
:open.sync="parentOpen"
overlay-class="relative-overlay"
>
<veui-button
ref="child"
@click="childOpen = !childOpen"
>
Toggle
</veui-button>
<veui-overlay
target="child"
position="top-start"
:open.sync="childOpen"
overlay-class="relative-overlay"
>
Child Overlay
</veui-overlay>
</veui-overlay>
<veui-button
ui="xs"
@click="parentOpen = childOpen = false"
>
Hide all
</veui-button>
</article>
</template>
<script>
import { Overlay, Button } from 'veui'
export default {
components: {
'veui-overlay': Overlay,
'veui-button': Button
},
data () {
return {
parentOpen: false,
childOpen: false
}
},
watch: {
parentOpen (val) {
if (!val) {
this.childOpen = false
}
}
}
}
</script>
<style lang="less" scoped>
.veui-overlay {
display: none;
}
.relative-overlay {
width: 200px;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #dbdbdb;
background-color: #fff;
.veui-button {
margin-left: 10px;
}
}
</style>
The stacking order of child overlays a affected by their parent overlays.
<template>
<article>
<veui-button
ref="a"
@click="aOpen = !aOpen"
>
Toggle A
</veui-button>
<veui-overlay
target="a"
position="top-start"
:open.sync="aOpen"
overlay-class="relative-overlay"
>
A
</veui-overlay>
<veui-button
ref="b"
@click="bOpen = !bOpen"
>
Toggle B
</veui-button>
<veui-overlay
target="b"
position="top-start"
:open.sync="bOpen"
overlay-class="relative-overlay"
>
B
<veui-button
ref="b-a"
ui="s"
@click="bAOpen = !bAOpen"
>
Toggle B-A
</veui-button>
<veui-overlay
target="b-a"
position="top-start"
:open.sync="bAOpen"
overlay-class="relative-overlay"
>
B-A
</veui-overlay>
</veui-overlay>
<veui-button
ref="c"
@click="cOpen = !cOpen"
>
Toggle C
</veui-button>
<veui-overlay
target="c"
position="top-start"
:open.sync="cOpen"
overlay-class="relative-overlay"
>
C
</veui-overlay>
<veui-button
ui="xs"
@click="aOpen = bOpen = cOpen = bAOpen = false"
>
Hide all
</veui-button>
</article>
</template>
<script>
import { Overlay, Button } from 'veui'
export default {
components: {
'veui-overlay': Overlay,
'veui-button': Button
},
data () {
return {
aOpen: false,
bOpen: false,
cOpen: false,
bAOpen: false
}
}
}
</script>
<style lang="less" scoped>
.veui-overlay {
display: none;
}
.relative-overlay {
width: 200px;
height: 100px;
line-height: 100px;
text-align: center;
border: 1px solid #dbdbdb;
background-color: #fff;
.veui-button {
margin-left: 10px;
}
}
</style>
API
Props
Name | Type | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ui | string= | - | Style variants. Not defined by veui-theme-dls but can be customized. | ||||||||||||||||||||
open | boolean | false |
Whether the overlay is displayed. | ||||||||||||||||||||
target | string | Vue | HTMLElement | - | Either of a valid
| ||||||||||||||||||||
priority | number | - | The stacking order priority of current overlay. For all overlays under same parent overlay in the stacking context tree, the overlay with higher priority will be displayed over those with lower priority. | ||||||||||||||||||||
autofocus | boolean | - | Whether to automatically focus the first focusable element in the overlay. | ||||||||||||||||||||
modal | boolean | false | Whether the overlay will preempt focus and trap focus upon keyboard navigation (will return focus when closed). | ||||||||||||||||||||
inline | boolean | false | Whether to render the overlay as inline content. | ||||||||||||||||||||
local | boolean | false | Whether to keep the overlay in it's original DOM location, instead of moving it to the global scope and participates in the global overlay management. | ||||||||||||||||||||
overlay-class | string | Array | Object= | - | The class expression applied to the root element of the overlay. Supports all values defined by Vue's | ||||||||||||||||||||
overlay-style | string | Array | Object= | - | The style expression applied to the root element of the overlay. Supports all values defined by Vue's Slots
Events
Configs
| ||||||||||||||||||||
options | Object | - | Configuration object passed to the modifiers option of the underlying Popper.js implementation. See here for more details. |