Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preventDefault option #926

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/docs/src/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ Boolean: prevent the popper from overflowing the `boundary`.
<VDropdown :prevent-overflow="false" />
```

### `preventDefault`

Boolean: prevent default event when click on outside elements.

```vue
<VDropdown :prevent-default="true" />
```

### `overflowPadding`

Virtual padding in the `boundary` used to prevent the popper overflow (pixels).
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/src/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export const config: FloatingVueConfig = {
strategy: 'absolute',
// Prevent overflow
preventOverflow: true,
// Prevent default event when click on outside elements
preventDefault: false,
// Flip to the opposite placement if needed
flip: true,
// Shift on the cross axis to prevent the popper from overflowing
Expand Down
6 changes: 6 additions & 0 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export default () => defineComponent({
type: Boolean,
default: defaultPropFactory('noAutoFocus'),
},

preventDefault: {
type: Boolean,
default: defaultPropFactory('preventDefault'),
},
},

emits: [
Expand Down Expand Up @@ -335,6 +340,7 @@ export default () => defineComponent({
},
result: this.positioningDisabled ? null : this.result,
attrs: this.$attrs,
preventDefault: this.preventDefault,
}
},

Expand Down
15 changes: 15 additions & 0 deletions packages/floating-vue/src/components/PopperMask.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div class="v-popper__mask"></div>
</template>


<style>
.v-popper__mask {
position: fixed;
z-index: 9999;
top: 0;
left: 0;
bottom:0;
right: 0;
}
</style>
5 changes: 5 additions & 0 deletions packages/floating-vue/src/components/PopperWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
onResize,
classes,
result,
preventDefault,
}"
:theme="finalTheme"
:target-nodes="getTargetNodes"
Expand Down Expand Up @@ -47,13 +48,16 @@
:hide="hide"
/>
</PopperContent>

<PopperMask v-if="isShown && preventDefault"/>
</Popper>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import Popper from './Popper.vue'
import PopperContent from './PopperContent.vue'
import PopperMask from './PopperMask.vue'
import PopperMethods from './PopperMethods'
import ThemeClass from './ThemeClass'

Expand All @@ -63,6 +67,7 @@ export default defineComponent({
components: {
Popper,
PopperContent,
PopperMask,
},

mixins: [
Expand Down
2 changes: 2 additions & 0 deletions packages/floating-vue/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const config: FloatingVueConfig = {
strategy: 'absolute',
// Prevent overflow
preventOverflow: true,
// Prevent default event when click on outside elements
preventDefault: false,
// Flip to the opposite placement if needed
flip: true,
// Shift on the cross axis to prevent the popper from overflowing
Expand Down