From 6b3bb479bdc02a8f205f035528d0cc4bcf7ab356 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Wed, 25 Nov 2026 19:38:09 +0100 Subject: [PATCH] fix(contexts): give the focus back to the application after editing it "Edit application" closes the actions menu of the application without returning the focus, because a dialog opens from it, and the dialog then has nothing to give the focus back to when it closes: the menu item is gone. Keyboard users ended up on the document after Save or Cancel and had to start again at the top. The dialog now says when it closes, and the navigation entry of that application focuses its actions button. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ruben van der Linde --- cypress/component/NavigationContextItem.cy.js | 32 +++++++++++++++++++ src/modules/modals/EditContext.vue | 1 + .../partials/NavigationContextItem.vue | 21 ++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 cypress/component/NavigationContextItem.cy.js 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)