44-->
55
66<template >
7- <nav class =" app-menu"
7+ <nav ref =" appMenu"
8+ class =" app-menu"
89 :aria-label =" t('core', 'Applications menu')" >
910 <ul class =" app-menu__list" >
1011 <AppMenuEntry v-for =" app in mainAppList"
@@ -29,7 +30,8 @@ import type { INavigationEntry } from '../types/navigation'
2930import { subscribe , unsubscribe } from ' @nextcloud/event-bus'
3031import { loadState } from ' @nextcloud/initial-state'
3132import { n , t } from ' @nextcloud/l10n'
32- import { defineComponent } from ' vue'
33+ import { useElementSize } from ' @vueuse/core'
34+ import { defineComponent , ref } from ' vue'
3335
3436import AppMenuEntry from ' ./AppMenuEntry.vue'
3537import NcActions from ' @nextcloud/vue/dist/Components/NcActions.js'
@@ -46,40 +48,47 @@ export default defineComponent({
4648 },
4749
4850 setup() {
51+ const appMenu = ref ()
52+ const { width : appMenuWidth } = useElementSize (appMenu )
4953 return {
5054 t ,
5155 n ,
56+ appMenu ,
57+ appMenuWidth ,
5258 }
5359 },
5460
5561 data() {
5662 const appList = loadState <INavigationEntry []>(' core' , ' apps' , [])
57-
5863 return {
5964 appList ,
60- appLimit: 0 ,
61- observer: null as ResizeObserver | null ,
6265 }
6366 },
6467
6568 computed: {
69+ appLimit() {
70+ const maxApps = Math .floor (this .appMenuWidth / 50 )
71+ if (maxApps < this .appList .length ) {
72+ // Ensure there is space for the overflow menu
73+ return Math .max (maxApps - 1 , 0 )
74+ }
75+ return maxApps
76+ },
77+
6678 mainAppList() {
6779 return this .appList .slice (0 , this .appLimit )
6880 },
81+
6982 popoverAppList() {
7083 return this .appList .slice (this .appLimit )
7184 },
7285 },
7386
7487 mounted() {
75- this .observer = new ResizeObserver (this .resize )
76- this .observer .observe (this .$el )
77- this .resize ()
7888 subscribe (' nextcloud:app-menu.refresh' , this .setApps )
7989 },
8090
8191 beforeDestroy() {
82- this .observer ! .disconnect ()
8392 unsubscribe (' nextcloud:app-menu.refresh' , this .setApps )
8493 },
8594
@@ -96,54 +105,44 @@ export default defineComponent({
96105 setApps({ apps }: { apps: INavigationEntry []}) {
97106 this .appList = apps
98107 },
99-
100- resize() {
101- const availableWidth = (this .$el as HTMLElement ).offsetWidth
102- let appCount = Math .floor (availableWidth / 50 ) - 1
103- const popoverAppCount = this .appList .length - appCount
104- if (popoverAppCount === 1 ) {
105- appCount --
106- }
107- if (appCount < 1 ) {
108- appCount = 0
109- }
110- this .appLimit = appCount
111- },
112108 },
113109})
114110 </script >
115111
116112<style scoped lang="scss">
117113.app-menu {
118- width : 100% ;
119114 display : flex ;
120- flex-shrink : 1 ;
121- flex-wrap : wrap ;
115+ flex : 1 1 ;
116+ width : 0 ;
122117
123118 & __list {
124119 display : flex ;
125120 flex-wrap : nowrap ;
126121 }
127122
128- // Adjust the overflow NcActions styles as they are directly rendered on the background
129- & __overflow :deep (.button-vue--vue-tertiary ) {
130- opacity : .7 ;
131- margin : 3px ;
132- filter : var (--background-image-invert-if-bright );
123+ & __overflow {
124+ margin-block : auto ;
133125
134- /* Remove all background and align text color if not expanded */
135- & :not ([aria-expanded = " true" ]) {
136- color : var (--color-background-plain-text );
126+ // Adjust the overflow NcActions styles as they are directly rendered on the background
127+ :deep (.button-vue--vue-tertiary ) {
128+ opacity : .7 ;
129+ margin : 3px ;
130+ filter : var (--background-image-invert-if-bright );
137131
138- & :hover {
139- opacity : 1 ;
140- background-color : transparent !important ;
132+ /* Remove all background and align text color if not expanded */
133+ & :not ([aria-expanded = " true" ]) {
134+ color : var (--color-background-plain-text );
135+
136+ & :hover {
137+ opacity : 1 ;
138+ background-color : transparent !important ;
139+ }
141140 }
142- }
143141
144- & :focus-visible {
145- opacity : 1 ;
146- outline : none !important ;
142+ & :focus-visible {
143+ opacity : 1 ;
144+ outline : none !important ;
145+ }
147146 }
148147 }
149148
0 commit comments