Skip to content

Commit

Permalink
Merge pull request #1076 from PrefectHQ/date-range-select-dropdown-width
Browse files Browse the repository at this point in the history
Sync the option dropdowns with the width of the input
  • Loading branch information
pleek91 authored Jan 5, 2024
2 parents 13a89cf + 89ac802 commit d89acf9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/components/DateRangeSelect/PDateRangeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<template #default>
<div class="p-date-range-select__picker" @click.stop>
<template v-if="mode === null">
<PDateRangeSelectOptions v-model:mode="mode" @apply="apply" />
<PDateRangeSelectOptions v-model:mode="mode" :style="styles.options" @apply="apply" />
</template>

<template v-if="mode === 'span'">
<PDateRangeSelectRelative v-bind="{ maxSpanInSeconds, min, max }" @close="close" @apply="apply" />
<PDateRangeSelectRelative :style="styles.options" v-bind="{ maxSpanInSeconds, min, max }" @close="close" @apply="apply" />
</template>

<template v-if="mode === 'around'">
Expand All @@ -41,7 +41,7 @@
</template>

<script lang="ts" setup>
import { useKeyDown } from '@prefecthq/vue-compositions'
import { useElementRect, useKeyDown } from '@prefecthq/vue-compositions'
import { addDays, addSeconds, isAfter, isBefore, secondsInDay } from 'date-fns'
import { computed, ref, watch } from 'vue'
import PButton from '@/components/Button/PButton.vue'
Expand All @@ -53,6 +53,7 @@
import PIcon from '@/components/Icon/PIcon.vue'
import PPopOver from '@/components/PopOver/PPopOver.vue'
import { DateRangeSelectValue } from '@/types/dateRange'
import { toPixels } from '@/utilities'
import { mapDateRangeSelectValueToDateRange } from '@/utilities/dateRangeSelect'
import { bottomRight, topRight, bottomLeft, topLeft, rightInside, leftInside } from '@/utilities/position'
Expand All @@ -79,7 +80,10 @@
})
const placement = [bottomLeft, topLeft, bottomRight, topRight, leftInside, rightInside]
const popover = ref<InstanceType<typeof PPopOver>>()
const target = computed(() => popover.value?.target)
const { width } = useElementRect(target)
const mode = ref<DateRangeSelectMode>(null)
const modelValue = computed({
Expand All @@ -103,6 +107,12 @@
},
}))
const styles = computed(() => ({
options: {
width: toPixels(width.value),
},
}))
function apply(value: DateRangeSelectValue): void {
modelValue.value = value
close()
Expand Down

0 comments on commit d89acf9

Please sign in to comment.