diff --git a/src/index.js b/src/index.js index 444fd31d..58670383 100644 --- a/src/index.js +++ b/src/index.js @@ -201,7 +201,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 @@ -213,7 +214,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 40bc8cfc..b3212f90 100644 --- a/src/tree-manager/index.js +++ b/src/tree-manager/index.js @@ -246,7 +246,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) @@ -254,7 +254,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) {