Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cypress/component/NavigationContextItem.cy.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
1 change: 1 addition & 0 deletions src/modules/modals/EditContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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')
},
Expand Down
21 changes: 21 additions & 0 deletions src/modules/navigation/partials/NavigationContextItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -99,6 +100,10 @@ export default {
},
},

setup() {
return { ...useEventBusSubscriptions() }
},

data() {
return {
icon: null,
Expand All @@ -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)
Expand Down
Loading