Skip to content

Commit

Permalink
Fix calendar position in right sidebar on small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Apr 25, 2023
1 parent ca6eefb commit e430a6a
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<date-picker ref="datePicker" class="oc-datepicker" v-bind="$attrs">
<date-picker ref="datePicker" class="oc-datepicker" v-bind="$attrs" :popover="popperOpts">
<template #default="args">
<!-- @slot Default slot to use as the popover anchor for datepicker -->
<!-- args is undefined during initial render, hence we check it here -->
Expand All @@ -14,7 +14,7 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { computed, defineComponent } from 'vue'
import { DatePicker } from 'v-calendar'
import 'v-calendar/dist/style.css'
Expand All @@ -30,7 +30,33 @@ export default defineComponent({
components: { DatePicker },
inheritAttrs: true,
setup() {
const popperOpts = computed(() => {
return {
modifiers: [
{
name: 'fixVerticalPosition',
enabled: true,
phase: 'beforeWrite',
requiresIfExists: ['offset', 'flip'],
fn({ state }) {
const dropHeight =
state.modifiersData.fullHeight || state.elements.popper.offsetHeight
const rect = state.elements.popper.getBoundingClientRect()
const neededScreenSpace =
state.elements.reference.offsetHeight + rect.top + dropHeight
if (state.placement !== 'top-start' && neededScreenSpace > window.innerHeight) {
state.styles.popper.top = `-${150}px`
}
}
}
]
}
})
return { popperOpts }
},
mounted() {
this.$el.__datePicker = this.$refs.datePicker
}
Expand Down

0 comments on commit e430a6a

Please sign in to comment.