Skip to content

Commit

Permalink
fix: do not trap focus when virtualize: true
Browse files Browse the repository at this point in the history
  • Loading branch information
jledentu committed Dec 22, 2023
1 parent a53121e commit 85ac00c
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/components/FinderList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ export default {
getOffset() {
Math.floor(this.$el.scrollTop / this.itemHeight) + 1;
},
getFocusedElement() {
const focusedItem = this.$refs[`item-${this.treeModel.focusedNodeId}`];
return focusedItem ? focusedItem.$el : null;
},
getVirtualRange() {
const overscan = 5;
const start = Math.max(
Expand All @@ -212,6 +216,9 @@ export default {
return;
}
const mustRestoreFocus =
this.getFocusedElement() === document.activeElement;
this.visibleStart = start;
this.visibleEnd = end;
Expand All @@ -223,17 +230,16 @@ export default {
this.listWidth = this.$el.clientWidth;
}
// We could have lost focus on focused item while updating the visible range
// so we need to refocus it
const focusedItem = this.$refs[`item-${this.treeModel.focusedNodeId}`];
if (
focusedItem &&
focusedItem.$el &&
focusedItem.$el !== document.activeElement
) {
focusedItem.$el.focus({
preventScroll: true
});
if (mustRestoreFocus) {
// We could have lost focus on focused item while updating the visible range
// so we need to refocus it
const focusedItem = this.getFocusedElement();
if (focusedItem && focusedItem !== document.activeElement) {
focusedItem.focus({
preventScroll: true
});
}

Check warning on line 242 in src/components/FinderList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/FinderList.vue#L234-L242

Added lines #L234 - L242 were not covered by tests
}
}
},
Expand Down

0 comments on commit 85ac00c

Please sign in to comment.