|
14 | 14 | }, |
15 | 15 | ]" |
16 | 16 | :aria-hidden="!panelExpanded && !fixed ? 'true' : 'false'" |
| 17 | + :inert="!panelExpanded && !fixed" |
17 | 18 | @focusout="onFocusout" |
18 | 19 | @mousedown="onMouseDown" |
19 | 20 | @mouseenter="onHoverToggle(true)" |
|
33 | 34 | import { |
34 | 35 | computed, |
35 | 36 | inject, |
| 37 | + nextTick, |
36 | 38 | onBeforeUnmount, |
37 | 39 | onMounted, |
38 | 40 | reactive, |
@@ -110,13 +112,47 @@ watch( |
110 | 112 | panelExpanded.value = props.expanded; |
111 | 113 | } |
112 | 114 | ); |
| 115 | +// Manage focusable elements when panel visibility changes |
| 116 | +function manageFocusableElements(isExpanded, isFixed) { |
| 117 | + if (!el.value || isFixed) return; |
| 118 | +
|
| 119 | + const focusableElements = el.value.querySelectorAll( |
| 120 | + 'a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])' |
| 121 | + ); |
| 122 | +
|
| 123 | + focusableElements.forEach(element => { |
| 124 | + if (isExpanded) { |
| 125 | + // Restore original tabindex when expanded |
| 126 | + const originalTabindex = element.getAttribute('data-original-tabindex'); |
| 127 | + if (originalTabindex !== null) { |
| 128 | + if (originalTabindex === 'null') { |
| 129 | + element.removeAttribute('tabindex'); |
| 130 | + } else { |
| 131 | + element.setAttribute('tabindex', originalTabindex); |
| 132 | + } |
| 133 | + element.removeAttribute('data-original-tabindex'); |
| 134 | + } |
| 135 | + } else { |
| 136 | + // Store original tabindex and set to -1 when collapsed |
| 137 | + const currentTabindex = element.getAttribute('tabindex'); |
| 138 | + element.setAttribute('data-original-tabindex', currentTabindex || 'null'); |
| 139 | + element.setAttribute('tabindex', '-1'); |
| 140 | + } |
| 141 | + }); |
| 142 | +} |
| 143 | +
|
113 | 144 | const emit = defineEmits(['update:expanded', 'panel-resize']); |
114 | 145 | const isPanelExpanded = computed( |
115 | 146 | () => panelExpanded.value || expandedViaHoverState.value |
116 | 147 | ); |
117 | 148 | watch(isPanelExpanded, current => { |
118 | 149 | emit('update:expanded', current); |
119 | 150 | emit('panel-resize', { id: props.id, expanded: current }); |
| 151 | +
|
| 152 | + // Manage focusable elements for non-fixed nav |
| 153 | + nextTick(() => { |
| 154 | + manageFocusableElements(current, props.fixed); |
| 155 | + }); |
120 | 156 | }); |
121 | 157 |
|
122 | 158 | const isChildOfHeader = computed(() => { |
|
0 commit comments