A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix: popover positions incorrectly on mobile
aminnausin014cfd5c08a5
diff --git a/resources/js/components/cedar-ui/popover/BasePopover.vue b/resources/js/components/cedar-ui/popover/BasePopover.vueindex bb607f7e..f4b2565d 100644--- a/resources/js/components/cedar-ui/popover/BasePopover.vue+++ b/resources/js/components/cedar-ui/popover/BasePopover.vue@@ -1,5 +1,5 @@<script setup lang="ts">-import type { Component, ComponentPublicInstance } from 'vue';+import type { Component, ComponentPublicInstance, ShallowRef } from 'vue';import { computed, nextTick, onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';import { onClickOutside } from '@vueuse/core';@@ -14,15 +14,15 @@ const props = withDefaults(buttonClass?: string;popoverClass?: string;buttonComponent?: Component;- buttonAttributes?: { [key: string]: any };+ buttonAttributes?: Record<string, any>;hideDefaultIcon?: boolean;forcePopoverPosition?: 'top' | 'bottom';showPopoverArrow?: boolean;teleportDisabled?: boolean;teleportTarget?: string;scrollContainer?: 'body' | 'window';- marginY?: number;marginX?: number;+ offsetY?: number;}>(),{disabled: false,@@ -32,66 +32,70 @@ const props = withDefaults(teleportDisabled: false,teleportTarget: 'body',scrollContainer: 'body',- marginY: 12,marginX: 8,+ offsetY: 12,},);const popoverOpen = ref(false);-const popoverStyles = ref<Record<string, string>>({});const popoverDirection = ref<'top' | 'bottom'>('bottom');+const popoverStyles = ref<Record<string, string>>({});const arrowStyles = ref<Record<string, string>>({});const popover = useTemplateRef('popover');const popoverArrow = useTemplateRef('popoverArrowRef');const popoverButton = useTemplateRef<ComponentPublicInstance>('popoverButton');-const init = ref(false);-const maxWidth = ref(0);-const maxHeight = ref(0);-const mergedButtonAttributes = computed(() => ({title: 'Open Menu',...props.buttonAttributes,}));+function getEl(ref: ShallowRef) {+ return (ref.value?.$el ?? ref.value) as HTMLElement;+}+const adjustPopoverPosition = () => {- if (!popover.value?.$el || !popoverButton.value?.$el) return;+ const popoverEl = getEl(popover);+ const buttonEl = getEl(popoverButton);- const [scrollX, scrollY] = props.scrollContainer === 'body' ? [document.body.scrollLeft, document.body.scrollTop] : [window.scrollX, window.scrollY];+ if (!popoverEl || !buttonEl || !popoverOpen.value) return;- const buttonRect = popoverButton.value.$el.getBoundingClientRect();- const popoverRect = popover.value.$el.getBoundingClientRect();+ const [scrollX, scrollY] = props.scrollContainer === 'body' ? [document.body.scrollLeft, document.body.scrollTop] : [window.scrollX, window.scrollY];- maxWidth.value = Math.max(popoverRect.width, maxWidth.value);- maxHeight.value = Math.max(popoverRect.height, maxHeight.value);+ const buttonRect = buttonEl.getBoundingClientRect();+ const popoverRect = popoverEl.getBoundingClientRect();- if (!props.forcePopoverPosition) {- const spaceBelow = window.innerHeight - buttonRect.bottom - props.marginY;- const spaceAbove = buttonRect.top - props.marginY;- popoverDirection.value = spaceBelow < maxHeight.value && spaceAbove >= maxHeight.value ? 'top' : 'bottom';+ if (buttonRect.width === 0) {+ popoverOpen.value = false;+ return;}- const verticalOffset = popoverDirection.value === 'top' ? buttonRect.top + scrollY - props.marginY - maxHeight.value : buttonRect.bottom + props.marginY + scrollY;+ popoverDirection.value =+ props.forcePopoverPosition ??+ (() => {+ const spaceBelow = window.innerHeight - buttonRect.bottom - props.offsetY;+ const spaceAbove = buttonRect.top - props.offsetY;+ return spaceBelow < popoverRect.height && spaceAbove >= popoverRect.height ? 'top' : 'bottom';+ })();- const clampedTop = Math.max(verticalOffset, props.marginY + scrollY);+ const top = popoverDirection.value === 'top' ? buttonRect.top + scrollY - props.offsetY - popoverRect.height : buttonRect.bottom + props.offsetY + scrollY;- let left = buttonRect.left - maxWidth.value / 2 + buttonRect.width / 2 + scrollX;+ let left = buttonRect.left - popoverRect.width / 2 + buttonRect.width / 2 + scrollX;++ const overflow = left + popoverRect.width - window.innerWidth + props.marginX + 8;- const overflow = left + maxWidth.value - window.innerWidth + props.marginX + 8;if (overflow > 0) {left = Math.max(left - overflow, props.marginX);- arrowStyles.value = { left: `${maxWidth.value / 2 + overflow}px` };+ arrowStyles.value = { left: `${popoverRect.width / 2 + overflow}px` };} else {- arrowStyles.value = { left: `${maxWidth.value / 2 - (popoverArrow.value?.getBoundingClientRect().width ?? 10 / 2)}` };+ arrowStyles.value = { left: `${popoverRect.width / 2 - (popoverArrow.value?.getBoundingClientRect().width ?? 10) / 2}px` };}- popoverStyles.value = { left: `${left}px`, top: `${clampedTop}px` };+ popoverStyles.value = { left: `${left}px`, top: `${top}px` };};const handleClose = () => {- maxWidth.value = 0;- maxHeight.value = 0;popoverOpen.value = false;};@@ -99,23 +103,28 @@ watch(() => popoverOpen.value,(value) => {if (!value) return;- if (!init.value) init.value = true;nextTick(adjustPopoverPosition);},);+function handleViewportChange() {+ if (!popoverOpen.value) return;++ requestAnimationFrame(adjustPopoverPosition);+}+onMounted(() => {- window.addEventListener('resize', handleClose);+ window.addEventListener('resize', handleViewportChange, { passive: true });});onUnmounted(() => {- window.removeEventListener('resize', handleClose);+ window.removeEventListener('resize', handleViewportChange);});onClickOutside(popover, (event) => {if (popoverButton.value?.$el?.contains(event.target as Node)) return;- popoverOpen.value = false;+ handleClose();});defineExpose({ handleClose });@@ -132,21 +141,21 @@ defineExpose({ handleClose });</slot></template></component>- <Teleport :to="teleportTarget" :disabled="teleportDisabled" v-if="init">+ <Teleport :to="teleportTarget" :disabled="teleportDisabled"><Transition- enter-active-class="ease-out duration-150 will-change-[transform,opacity]"- enter-from-class="scale-[0.8] opacity-0"- enter-to-class="scale-100 opacity-100"- leave-active-class="ease-in duration-100 will-change-[transform,opacity]"- leave-from-class="scale-100 opacity-100"- leave-to-class="scale-[0.65] opacity-0"+ enter-active-class="ease-out duration-200 transition-opacity"+ enter-from-class="opacity-0"+ enter-to-class=" opacity-100"+ leave-active-class="ease-in duration-150 transition-opacity"+ leave-from-class="opacity-100"+ leave-to-class="opacity-0"><UseFocusTrapv-if="popoverOpen"ref="popover"- :options="{ allowOutsideClick: true, preventScroll: true }":style="popoverStyles"- :class="cn('absolute z-50 w-75 max-w-lg p-3', 'ring-1ring-r-button bg-overlay-2 sm:bg-overlay-2-t', 'rounded-md shadow sm:backdrop-blur-xs', popoverClass)"+ :options="{ allowOutsideClick: true, preventScroll: true }"+ :class="cn('absolute z-50 w-75 max-w-lg', 'p-3', 'ring-r-button bg-overlay-2-t ring-1', 'rounded-md shadow backdrop-blur-xs', popoverClass)"@keydown.esc="popoverOpen = false"><div@@ -155,7 +164,7 @@ defineExpose({ handleClose });:style="arrowStyles":class="['absolute left-1/2 inline-block w-5 -translate-x-2 overflow-hidden',- popoverDirection === 'bottom' ? 'top-0 -translate-y-2.5' : 'bottom-0 mb-px translate-y-2.5',+ popoverDirection === 'bottom' ? 'top-0 -translate-y-2.5' : 'bottom-0 translate-y-2.5',]"><divdiff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.phpindex 01d385cd..188a1ad2 100755--- a/resources/views/layouts/app.blade.php+++ b/resources/views/layouts/app.blade.php@@ -75,10 +75,6 @@pointer-events: none;}- html {- height: 100%;- }-html {overflow: hidden;height: 100%;