diff --git a/cypress/component/NavigationContextItem.cy.js b/cypress/component/NavigationContextItem.cy.js new file mode 100644 index 0000000000..ce2c1ac44e --- /dev/null +++ b/cypress/component/NavigationContextItem.cy.js @@ -0,0 +1,32 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { emit } from '@nextcloud/event-bus' +import { translate as t, translatePlural as n } from '@nextcloud/l10n' +import { createPinia } from 'pinia' +import { createMemoryHistory, createRouter } from 'vue-router' +import NavigationContextItem from '../../src/modules/navigation/partials/NavigationContextItem.vue' + +const context = { id: 3, name: 'Team board', iconName: null, owner: 'admin', ownerType: 0, sharing: {} } + +/** + * Mounts the navigation entry of the application inside a router, as the navigation does. + */ +function mountItem() { + const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/:path(.*)*', component: { render: () => null } }] }) + cy.mount(NavigationContextItem, { props: { context }, global: { plugins: [createPinia(), router], mixins: [{ methods: { t, n } }] } }) +} + +describe('NavigationContextItem', () => { + it('gives the focus back to its actions once the edit dialog of the application closes', () => { + mountItem() + cy.get('[data-cy="navigationContextItem"] .action-item__menutoggle').should('exist') + + cy.then(() => emit('tables:context:edit:closed', 4)) + cy.focused().should('not.exist') + + cy.then(() => emit('tables:context:edit:closed', 3)) + cy.focused().should('have.class', 'action-item__menutoggle') + }) +}) diff --git a/src/modules/modals/EditContext.vue b/src/modules/modals/EditContext.vue index 35b2c78371..327ace9353 100644 --- a/src/modules/modals/EditContext.vue +++ b/src/modules/modals/EditContext.vue @@ -157,6 +157,7 @@ export default { this.icon.svg = await this.getContextIcon(iconName) }, actionCancel() { + emit('tables:context:edit:closed', this.contextId) this.reset() this.$emit('close') }, diff --git a/src/modules/navigation/partials/NavigationContextItem.vue b/src/modules/navigation/partials/NavigationContextItem.vue index 73c0416a30..1939330ddc 100644 --- a/src/modules/navigation/partials/NavigationContextItem.vue +++ b/src/modules/navigation/partials/NavigationContextItem.vue @@ -73,6 +73,7 @@ import { useTablesStore } from '../../../store/store.js' import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' import Import from 'vue-material-design-icons/Import.vue' +import { useEventBusSubscriptions } from '../../../shared/composables/useEventBusSubscriptions.js' export default { name: 'NavigationContextItem', @@ -99,6 +100,10 @@ export default { }, }, + setup() { + return { ...useEventBusSubscriptions() } + }, + data() { return { icon: null, @@ -118,8 +123,24 @@ export default { }, }, + mounted() { + this.subscribeToEventBus('tables:context:edit:closed', this.focusActions) + }, + methods: { ...mapActions(useTablesStore, ['updateDisplayMode']), + /** + * Focuses the actions button of this application once its edit dialog closes, since the + * menu item that opened the dialog is gone by then. + * + * @param {number} contextId the application whose dialog closed + */ + focusActions(contextId) { + if (contextId !== this.context?.id) { + return + } + this.$nextTick(() => setTimeout(() => this.$el?.querySelector?.('.action-item__menutoggle')?.focus())) + }, emit, async editContext() { emit('tables:context:edit', this.context.id)