Skip to content

Commit 8e11b37

Browse files
authored
Add options argument to selectMulti for consistency with select (#266)
select(...) supports optional flag to disable focus change but selectMulti(...) doesn't. This change makes the two methods consistent. It shouldn't break existing code. I copy-pasted the align option without understanding it.
1 parent 3e9f4a9 commit 8e11b37

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

modules/react-arborist/src/interfaces/tree-api.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,18 @@ export class TreeApi<T> {
345345
safeRun(this.props.onSelect, this.selectedNodes);
346346
}
347347

348-
selectMulti(identity: Identity) {
348+
selectMulti(identity: Identity, opts: { align?: Align; focus?: boolean } = {}) {
349349
const node = this.get(identifyNull(identity));
350350
if (!node) return;
351-
this.dispatch(focus(node.id));
351+
const changeFocus = opts.focus !== false;
352+
if (changeFocus) this.dispatch(focus(node.id));
352353
this.dispatch(selection.add(node.id));
353354
this.dispatch(selection.anchor(node.id));
354355
this.dispatch(selection.mostRecent(node.id));
355-
this.scrollTo(node);
356-
if (this.focusedNode) safeRun(this.props.onFocus, this.focusedNode);
356+
this.scrollTo(node, opts.align);
357+
if (this.focusedNode && changeFocus) {
358+
safeRun(this.props.onFocus, this.focusedNode);
359+
}
357360
safeRun(this.props.onSelect, this.selectedNodes);
358361
}
359362

0 commit comments

Comments
 (0)