Skip to content

Commit c607e5a

Browse files
committed
refactor: Position menu arrow based on the input width (fixes #802)
1 parent eae475c commit c607e5a

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/VueDatePicker/VueDatePicker.vue

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
:open-on-top="openOnTop"
3838
:no-overlay-focus="noOverlayFocus"
3939
:collapse="collapse"
40+
:input-width="inputWidth"
4041
@close-picker="closeMenu"
4142
@select-date="selectDate"
4243
@auto-apply="autoApplyValue"
@@ -258,6 +259,10 @@
258259
);
259260
});
260261
262+
const inputWidth = computed(() => {
263+
return inputRef.value?.$el?.getBoundingClientRect()?.width ?? 0;
264+
});
265+
261266
/**
262267
* Event listener for 'scroll'
263268
* Depending on the props, it can close the menu or set correct position

src/VueDatePicker/components/DatepickerMenu.vue

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
role="dialog"
77
:aria-label="ariaLabels?.menu"
88
:class="dpMenuClass"
9+
:style="{ '--dp-arrow-left': arrowPos }"
910
@mouseleave="clearHoverDate"
1011
@click="handleDpMenuClick"
1112
@keydown.esc="handleEsc"
@@ -172,6 +173,7 @@
172173
internalModelValue: { type: [Date, Array] as PropType<InternalModuleValue>, default: null },
173174
noOverlayFocus: { type: Boolean as PropType<boolean>, default: false },
174175
collapse: { type: Boolean as PropType<boolean>, default: false },
176+
inputWidth: { type: Number as PropType<number>, default: 0 },
175177
});
176178
177179
const dpMenuRef = ref(null);
@@ -244,6 +246,13 @@
244246
return DatePicker;
245247
});
246248
249+
const arrowPos = computed(() => {
250+
if (props.inputWidth < calendarWidth.value) {
251+
return `${props.inputWidth / 2}px`;
252+
}
253+
return '50%';
254+
});
255+
247256
const focusMenu = (): void => {
248257
const menu = unrefElement(dpMenuRef);
249258
if (menu) {

src/VueDatePicker/props.ts

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export const PickerBaseProps = {
173173
noOverlayFocus: { type: Boolean as PropType<boolean>, default: false },
174174
collapse: { type: Boolean as PropType<boolean>, default: false },
175175
menuWrapRef: { type: Object as PropType<HTMLElement | null>, default: null },
176+
inputWidth: { type: Number as PropType<number>, default: 0 },
176177
};
177178

178179
export type AllPropsType = ExtractPropTypes<typeof AllProps>;

src/VueDatePicker/style/components/_DatepickerMenu.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999

100100
.dp__arrow_top {
101-
left: 50%;
101+
left: var(--dp-arrow-left);
102102
top: 0;
103103
height: 12px;
104104
width: 12px;
@@ -110,7 +110,7 @@
110110
}
111111

112112
.dp__arrow_bottom {
113-
left: 50%;
113+
left: var(--dp-arrow-left);
114114
bottom: 0;
115115
height: 12px;
116116
width: 12px;

0 commit comments

Comments
 (0)