Skip to content

Commit 3f5ed81

Browse files
authored
Merge pull request #229 from grapoza/fix-premature-tree-traversal
Move selection mode enforcement to nextTick
2 parents 767f671 + 8fac163 commit 3f5ed81

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/components/TreeView.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,17 @@
147147
}
148148
}
149149
150-
this.$_grtv_enforceSingleSelectionMode();
151-
152150
if (this.$el.id) {
153151
this.$set(this, 'uniqueId', this.$el.id);
154152
}
155153
156-
// Set this in a $nextTick so the focusable watcher
154+
// Set isMounted in a $nextTick so the focusable watcher
157155
// in TreeViewNodeAria fires before isMounted is set.
158156
// Otherwise, it steals focus when the tree is mounted.
157+
// Also wait to enforce single selection mode in case root
158+
// nodes load asynchronously so their create hooks fire.
159159
this.$nextTick(() => {
160+
this.$_grtv_enforceSingleSelectionMode();
160161
this.isMounted = true;
161162
});
162163
},

tests/unit/TreeView.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('TreeView.vue', () => {
229229
beforeEach(() => {
230230
jest.useFakeTimers();
231231
loadNodesPromise = new Promise(resolve => setTimeout(resolve.bind(null, generateNodes(['', ''])), 1000));
232-
wrapper = createWrapper({ loadNodesAsync: () => loadNodesPromise });
232+
wrapper = createWrapper({ loadNodesAsync: () => loadNodesPromise, selectionMode: SelectionMode.Single });
233233
});
234234

235235
afterEach(() => {

0 commit comments

Comments
 (0)