From 4e92fff387e0fe36e5dcff2c8be8bde111d4ad23 Mon Sep 17 00:00:00 2001 From: Magnus Ellinge Date: Wed, 3 Apr 2019 13:27:26 +0200 Subject: [PATCH] fix: Do not select readOnly/disabled --- src/index.js | 5 +++-- src/tree-manager/index.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index d3a4018b..59ac1d02 100644 --- a/src/index.js +++ b/src/index.js @@ -192,7 +192,8 @@ class DropdownTreeSelect extends Component { } onKeyboardKeyDown = e => { - if (!this.props.enableKeyboardNavigation) { return } + const { enableKeyboardNavigation, readOnly } = this.props + if (!enableKeyboardNavigation) { return } const { showDropdown, tags, searchModeOn, currentFocus } = this.state @@ -204,7 +205,7 @@ class DropdownTreeSelect extends Component { } else if (showDropdown && keyboardNavigation.isValidKey(e.key, true)) { const tm = this.treeManager const tree = searchModeOn ? tm.matchTree : tm.tree - const newFocus = tm.handleNavigationKey(currentFocus, tree, e.key, !searchModeOn, this.onCheckboxChange, this.onNodeToggle) + const newFocus = tm.handleNavigationKey(currentFocus, tree, e.key, readOnly, !searchModeOn, this.onCheckboxChange, this.onNodeToggle) if (newFocus !== currentFocus) { this.setState({ currentFocus: newFocus }) } diff --git a/src/tree-manager/index.js b/src/tree-manager/index.js index 3f76fe0f..1e544402 100644 --- a/src/tree-manager/index.js +++ b/src/tree-manager/index.js @@ -228,7 +228,7 @@ class TreeManager { }) } - handleNavigationKey(currentFocus, tree, key, markSubTreeOnNonExpanded, onToggleChecked, onToggleExpanded) { + handleNavigationKey(currentFocus, tree, key, readOnly, markSubTreeOnNonExpanded, onToggleChecked, onToggleExpanded) { const prevFocus = currentFocus && this.getNodeById(currentFocus) const action = keyboardNavigation.getAction(prevFocus, key) @@ -236,7 +236,7 @@ class TreeManager { const newFocus = this.handleFocusNavigationkey(tree, action, prevFocus, markSubTreeOnNonExpanded) return newFocus } - if (action === NavActions.ToggleChecked && prevFocus) { + if (action === NavActions.ToggleChecked && prevFocus && !readOnly && !(prevFocus.readOnly || prevFocus.disabled)) { onToggleChecked(prevFocus._id, prevFocus.checked !== true) } if (action === NavActions.ToggleExpanded && prevFocus) {