From 646fe0aaea103b9e194d866351b3af5d162ace91 Mon Sep 17 00:00:00 2001 From: Paul Korzhyk Date: Sun, 18 Aug 2024 17:29:03 +0300 Subject: [PATCH] Add options argument to selectMulti for consistency with select 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. --- modules/react-arborist/src/interfaces/tree-api.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/react-arborist/src/interfaces/tree-api.ts b/modules/react-arborist/src/interfaces/tree-api.ts index 50e03a8..c817ddd 100644 --- a/modules/react-arborist/src/interfaces/tree-api.ts +++ b/modules/react-arborist/src/interfaces/tree-api.ts @@ -344,15 +344,18 @@ export class TreeApi { this.dispatch(selection.remove(id)); } - selectMulti(identity: Identity) { + selectMulti(identity: Identity, opts: { align?: Align; focus?: boolean } = {}) { const node = this.get(identifyNull(identity)); if (!node) return; - this.dispatch(focus(node.id)); + const changeFocus = opts.focus !== false; + if (changeFocus) this.dispatch(focus(node.id)); this.dispatch(selection.add(node.id)); this.dispatch(selection.anchor(node.id)); this.dispatch(selection.mostRecent(node.id)); - this.scrollTo(node); - if (this.focusedNode) safeRun(this.props.onFocus, this.focusedNode); + this.scrollTo(node, opts.align); + if (this.focusedNode && changeFocus) { + safeRun(this.props.onFocus, this.focusedNode); + } safeRun(this.props.onSelect, this.selectedNodes); }