Skip to content

Commit 8319b4e

Browse files
committed
fix(NcAppSidebar): check handling of conditionally rendered elements
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 13abad8 commit 8319b4e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/components/NcAppSidebar/NcAppSidebar.vue

+24-2
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ export default {
551551
-->
552552
<Teleport v-if="ncContentSelector && !open && !noToggle" :to="ncContentSelector">
553553
<NcButton :aria-label="t('Open sidebar')"
554+
ref="toggle"
554555
class="app-sidebar__toggle"
555556
:class="toggleClasses"
556557
variant="tertiary"
@@ -565,6 +566,15 @@ export default {
565566
</NcButton>
566567
</Teleport>
567568

569+
<!-- Fallback for screen reader navigation in case header was not rendered -->
570+
<h2 v-if="hasHeaderAriaFallback"
571+
:id="`app-sidebar-vue-${uid}__header`"
572+
ref="headerAriaFallback"
573+
:tabindex="0"
574+
class="hidden-visually">
575+
{{ name }}
576+
</h2>
577+
568578
<header :class="{
569579
'app-sidebar-header--with-figure': isSlotPopulated($slots.header?.()) || background,
570580
'app-sidebar-header--compact': compact,
@@ -957,6 +967,9 @@ export default {
957967
hasFigureClickListener() {
958968
return !!this.$attrs.onFigureClick
959969
},
970+
hasHeaderAriaFallback() {
971+
return this.empty || isSlotPopulated(this.$slots.content)
972+
},
960973
},
961974

962975
watch: {
@@ -1019,7 +1032,7 @@ export default {
10191032
document.querySelector('#header'),
10201033
], {
10211034
allowOutsideClick: true,
1022-
fallbackFocus: this.$refs.closeButton.$el,
1035+
fallbackFocus: this.$refs.closeButton?.$el ?? this.$refs.sidebar,
10231036
trapStack: getTrapStack(),
10241037
escapeDeactivates: false,
10251038
})
@@ -1146,7 +1159,16 @@ export default {
11461159
* @public
11471160
*/
11481161
focus() {
1149-
(this.$refs.header ?? this.$refs.toggle)?.focus()
1162+
if (!this.open && !this.noToggle) {
1163+
this.$refs.toggle.$el.focus()
1164+
return
1165+
}
1166+
1167+
if (this.hasHeaderAriaFallback) {
1168+
this.$refs.headerAriaFallback.focus()
1169+
} else {
1170+
this.$refs.header.focus()
1171+
}
11501172
},
11511173

11521174
/**

0 commit comments

Comments
 (0)