From 6a9e2fa5dd193775c4bf5283feeeb18ba7d25230 Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Tue, 6 Feb 2024 23:27:24 +0100 Subject: [PATCH] fix(NcAppSidebar): provide a method to focus active tab with auto return focus Signed-off-by: Grigorii K. Shartsev --- src/components/NcAppSidebar/NcAppSidebar.vue | 11 +++++++++++ src/components/NcAppSidebarTab/NcAppSidebarTab.vue | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/NcAppSidebar/NcAppSidebar.vue b/src/components/NcAppSidebar/NcAppSidebar.vue index 4930502b6f..ee66fd1a5f 100644 --- a/src/components/NcAppSidebar/NcAppSidebar.vue +++ b/src/components/NcAppSidebar/NcAppSidebar.vue @@ -864,6 +864,17 @@ export default { this.$refs.header.focus() }, + /** + * Focus the active tab + * @public + */ + focusActiveTabContent() { + // If a tab is focused then probably a new trigger element moved the focus to the sidebar + this.preserveElementToReturnFocus() + + this.$refs.tabs.focusActiveTabContent() + }, + /** * Emit name change event to parent component * diff --git a/src/components/NcAppSidebarTab/NcAppSidebarTab.vue b/src/components/NcAppSidebarTab/NcAppSidebarTab.vue index 038928bd7a..a4bf4c360a 100644 --- a/src/components/NcAppSidebarTab/NcAppSidebarTab.vue +++ b/src/components/NcAppSidebarTab/NcAppSidebarTab.vue @@ -30,8 +30,8 @@ :aria-label="isTablistShown() ? undefined : name" :aria-labelledby="isTablistShown() ? `tab-button-${id}` : undefined" class="app-sidebar__tab" - tabindex="0" - role="tabpanel" + :tabindex="isTablistShown() ? 0 : -1" + :role="isTablistShown() ? 'tabpanel' : undefined" @scroll="onScroll">

{{ name }}