Skip to content

Commit bc9fc60

Browse files
committed
refactor!: Allow alt-position to update style in any way (fixes #1018)
1 parent a156591 commit bc9fc60

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface VueDatePickerProps {
206206
noHoursOverlay?: boolean;
207207
noMinutesOverlay?: boolean;
208208
noSecondsOverlay?: boolean;
209-
altPosition?: (el: HTMLElement | undefined) => { top: number | string; left: number | string; transform?: string };
209+
altPosition?: (el: HTMLElement | undefined) => Record<string, string | number>;
210210
disabledWeekDays?: number[] | string[];
211211
allowedDates?: string[] | Date[];
212212
nowButtonLabel?: string;

src/VueDatePicker/composables/position.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const usePosition = ({
9090

9191
const getInputPositions = (inputEl: HTMLElement) => {
9292
const { width, height } = inputEl.getBoundingClientRect();
93-
const { top, left } = props.altPosition ? props.altPosition(inputEl) : getOffset(inputEl);
93+
const { top, left } = getOffset(inputEl);
9494
return { top: +top, left: +left, width, height };
9595
};
9696

@@ -104,8 +104,7 @@ export const usePosition = ({
104104

105105
const customAltPosition = () => {
106106
const el = unrefElement(inputRef as MaybeElementRef);
107-
const { top, left, transform } = props.altPosition(el);
108-
menuStyle.value = { top: `${top}px`, left: `${left}px`, transform: transform ?? '' };
107+
menuStyle.value = props.altPosition(el);
109108
};
110109

111110
/**

src/VueDatePicker/interfaces.ts

-6
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ export type TimeType = keyof Time;
120120

121121
export type DisabledDatesProp = Date[] | string[] | IDisableDates;
122122

123-
export type CustomAltPosition = (el: HTMLElement | null) => {
124-
top: number | string;
125-
left: number | string;
126-
transform?: string;
127-
};
128-
129123
export type PresetDate = {
130124
label: string;
131125
value: Date[] | string[] | Date | string;

src/VueDatePicker/props.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {
1313
OpenPosition,
1414
WeekStartNum,
1515
WeekStartStr,
16-
CustomAltPosition,
1716
SixWeekMode,
1817
ActionRowData,
1918
ICalendarDate,
@@ -44,7 +43,7 @@ export const AllProps = {
4443
default: () => null,
4544
},
4645
autoPosition: { type: Boolean as PropType<boolean>, default: true },
47-
altPosition: { type: Function as PropType<CustomAltPosition>, default: null },
46+
altPosition: { type: Function as PropType<(el: HTMLElement | null) => any>, default: null },
4847
transitions: { type: [Boolean, Object] as PropType<boolean | Partial<Transition>>, default: true },
4948
formatLocale: { type: Object as PropType<Locale>, default: null },
5049
utc: { type: [Boolean, String] as PropType<boolean | 'preserve'>, default: false },

0 commit comments

Comments
 (0)