Skip to content

Commit

Permalink
Window resize adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Sep 28, 2024
1 parent a062d25 commit aa1d179
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/appMenu/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ import { useSettingStore } from '@/stores/settingStore'
import { useCommandStore } from '@/stores/commandStore'
import { MenuItem } from 'primevue/menuitem'
import { useI18n } from 'vue-i18n'
import { useDraggable, useLocalStorage } from '@vueuse/core'
import { debounce } from 'lodash'
import { useDraggable, useEventListener, useLocalStorage } from '@vueuse/core'
import { debounce, clamp } from 'lodash'
const settingsStore = useSettingStore()
const commandStore = useCommandStore()
Expand Down Expand Up @@ -198,6 +198,23 @@ watch(visible, (newVisible) => {
nextTick(setInitialPosition)
}
})
const adjustMenuPosition = () => {
if (panelRef.value) {
const screenWidth = window.innerWidth
const screenHeight = window.innerHeight
const menuWidth = panelRef.value.offsetWidth
const menuHeight = panelRef.value.offsetHeight
// Adjust x position if menu is off-screen horizontally
x.value = clamp(x.value, 0, screenWidth - menuWidth)
// Adjust y position if menu is off-screen vertically
y.value = clamp(y.value, 0, screenHeight - menuHeight)
}
}
useEventListener(window, 'resize', adjustMenuPosition)
</script>

<style scoped>
Expand Down

0 comments on commit aa1d179

Please sign in to comment.