Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/moody-poems-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"apostrophe": minor
---

Fixed an issue where using the Tab key to navigate within modals could incorrectly jump focus to a wrong element instead of the next input field.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
:data-apos-graph-key="props.graphKey || undefined"
tabindex="0"
@focus.capture="captureFocus"
@keyup.tab="onKeyup"
@keydown.tab="onKeydownTab"
@keyup.esc="onKeyup"
>
<transition :name="transitionType">
Expand Down Expand Up @@ -476,13 +476,25 @@ onUnmounted(() => {
}
});

function onKeyup(event) {
// Handle Tab on keydown — before the browser moves focus.
// Handling Tab on keyup is too late: the browser
// has already moved focus, so the cycling logic sees the wrong
// activeElement.
function onKeydownTab(event) {
if (!shouldTrapFocus.value) {
return;
}
if (!store.isOnTop(modalEl.value)) {
return;
}
if (event.target?.nodeName?.toLowerCase() === 'textarea') {
return;
}
cycleElementsToFocus(event, props.modalData.elementsToFocus);
}

if (event.key === 'Tab') {
cycleElementsToFocus(event, props.modalData.elementsToFocus);
function onKeyup(event) {
if (!store.isOnTop(modalEl.value)) {
return;
}

Expand Down
Loading