Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature proposal - alt-posision prop can affect the arrow position #1076

Open
iv-thomson opened this issue Jan 29, 2025 · 0 comments
Open

Feature proposal - alt-posision prop can affect the arrow position #1076

iv-thomson opened this issue Jan 29, 2025 · 0 comments
Labels
awaiting triage The issue is not reviewed by the maintainers enhancement New feature or request

Comments

@iv-thomson
Copy link

iv-thomson commented Jan 29, 2025

Hello! I'd like to propose an improvement to the alt-position prop.

The issue

When using 'teleport' together with the alt-position prop and calculating the position of the datepicker, we have no way to change the position of an arrow (besides overwriting it's css)

This happens because the position of the arrow is determined by the following parameter:

const openOnTop = ref(false);

By default it's value is changed here in the calculateMenuPosition, however, when using alt-position, this property is set to default, which makes the arrow always point upwards.

const setMenuPosition = (recalculate = true): void => {
if (!inline.value.enabled) {
if (centered.value) return teleportCenter();
if (props.altPosition !== null) return customAltPosition();
if (recalculate) {
const el = props.teleport ? menuRefInner.value?.$el : menuRef.value;
if (el) {
menuRect.value = el.getBoundingClientRect();
}
emit('recalculate-position');
}
return calculateMenuPosition();
}
};

Solution

My suggestion is to change the customAltPosition method to allow users to provide their own value of openOnTop parameter:

@@ -103,7 +103,12 @@ export const usePosition = ({
 
     const customAltPosition = () => {
         const el = unrefElement(inputRef as MaybeElementRef);
-        menuStyle.value = props.altPosition(el);
+        const { openOnTop, ...customPosition } = props.altPosition(el);
+        menuStyle.value = customPosition;
+
+        if (openOnTop !== undefined) {
+            openOnTop.value = openOnTop;
+        }
     };

Then, on the level of a project we'll just need to do the following:

<template>
  <VueDatePicker :alt-position="calculatePosition" />
</template>

<script setup lang="ts">
  const calculatePosition = (el: HTMLElement): { top: number; left: number, openOnTop: boolean } => {
    const { top, left, placement } = somePlacementFunction();
    return {
      top,
      left,
      openOnTop: placement === 'top'
    };
  }
</ script>

This change will allow more flexibility for setting up custom positions for the calendar content.

Workaround

The workaround I found is to overwrite the css of dp__arrow_top class for the arrow to point in the correct dirrection. This is not ideal, because I will have to do a side effect inside the function I'm passing to the alt-position prop.

Screenshot for more context

Image
@iv-thomson iv-thomson added awaiting triage The issue is not reviewed by the maintainers enhancement New feature or request labels Jan 29, 2025
@iv-thomson iv-thomson changed the title Feature proposal - Feature proposal - alt-posision prop can affect the arrow position Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting triage The issue is not reviewed by the maintainers enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant