Skip to content

Commit 2956562

Browse files
committed
feat: Add option to force top or bottom position (resolves #1026)
1 parent e68e8fc commit 2956562

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

index.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-types */
21
import type {
32
ComponentOptionsMixin,
43
ComponentPropsOptions,
@@ -185,7 +184,7 @@ export interface VueDatePickerProps {
185184
selectText?: string;
186185
cancelText?: string;
187186
weekNumName?: string;
188-
autoPosition?: boolean;
187+
autoPosition?: boolean | 'top' | 'bottom';
189188
monthPicker?: boolean;
190189
timePicker?: boolean;
191190
textInput?:

src/VueDatePicker/composables/position.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
import type { Component, ComputedRef, Ref, Slots } from 'vue';
12
import { h, ref, render, toRef, watch } from 'vue';
23
import {
34
type DatepickerInputRef,
45
type DatepickerMenuRef,
56
type InlineOptions,
6-
type VueEmit,
7-
OpenPosition,
87
type MaybeElementRef,
8+
OpenPosition,
9+
type VueEmit,
910
} from '@/interfaces';
1011

1112
import { unrefElement } from '@/utils/util';
1213
import { MenuPlacement } from '@/constants';
13-
14-
import type { Component, ComputedRef, Ref, Slots } from 'vue';
1514
import type { AllPropsType } from '@/props';
1615
import { useDefaults } from '@/composables/defaults';
1716

@@ -181,6 +180,8 @@ export const usePosition = ({
181180
const getMenuPlacement = (): MenuPlacement => {
182181
const inputEl = unrefElement(inputRef as MaybeElementRef);
183182
if (inputEl) {
183+
if (props.autoPosition === 'top') return MenuPlacement.top;
184+
if (props.autoPosition === 'bottom') return MenuPlacement.bottom;
184185
const { height: menuHeight } = menuRect.value;
185186
const { top: inputTop, height: inputHeight } = inputEl.getBoundingClientRect();
186187

src/VueDatePicker/props.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const AllProps = {
4242
type: [String, Function] as PropType<IFormat>,
4343
default: () => null,
4444
},
45-
autoPosition: { type: Boolean as PropType<boolean>, default: true },
45+
autoPosition: { type: [Boolean, String] as PropType<boolean | 'top' | 'bottom'>, default: true },
4646
altPosition: { type: Function as PropType<(el: HTMLElement | null) => any>, default: null },
4747
transitions: { type: [Boolean, Object] as PropType<boolean | Partial<Transition>>, default: true },
4848
formatLocale: { type: Object as PropType<Locale>, default: null },

0 commit comments

Comments
 (0)