Skip to content

Commit

Permalink
fix(useCombobox): select item on blur only when menu is open (#1170)
Browse files Browse the repository at this point in the history
* Added additional conditional statement in useCombobox function inputHandleBlur to ensure that items could not be selected by clicking the left arrow key when the dropdown was closed

* quality message

* Removed changes to useCombobox method inputHandleBlur and added conditional statement to check dropdown menu is open to useCombobox reducer.
  • Loading branch information
ndeom committed Sep 5, 2020
1 parent e002b9a commit d1299c4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
29 changes: 12 additions & 17 deletions .size-snapshot.json
@@ -1,30 +1,25 @@
{
"downshift.cjs.js": {
"bundled": 145030,
"minified": 65717,
"gzipped": 14220
},
"downshift.umd.min.js": {
"bundled": 158213,
"minified": 50906,
"gzipped": 13947
"bundled": 158031,
"minified": 50884,
"gzipped": 13945
},
"downshift.umd.js": {
"bundled": 194827,
"minified": 67351,
"gzipped": 17536
"bundled": 194611,
"minified": 67329,
"gzipped": 17530
},
"downshift.esm.js": {
"bundled": 145404,
"minified": 65910,
"gzipped": 14242,
"bundled": 143881,
"minified": 64857,
"gzipped": 14134,
"treeshaked": {
"rollup": {
"code": 2274,
"import_statements": 317
"code": 2275,
"import_statements": 318
},
"webpack": {
"code": 4497
"code": 4496
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/useCombobox/index.js
@@ -1,11 +1,7 @@
/* eslint-disable max-statements */
import {useRef, useEffect, useCallback, useMemo} from 'react'
import {isPreact, isReactNative} from '../../is.macro'
import {
handleRefs,
normalizeArrowKey,
callAllEventHandlers,
} from '../../utils'
import {handleRefs, normalizeArrowKey, callAllEventHandlers} from '../../utils'
import {
getItemIndex,
getPropTypesValidator,
Expand Down Expand Up @@ -110,7 +106,7 @@ function useCombobox(userProps = {}) {
isOpen,
itemRefs,
scrollIntoView,
getItemNodeFromIndex
getItemNodeFromIndex,
})
useControlPropsValidator({
isInitialMount: isInitialMountRef.current,
Expand Down
20 changes: 12 additions & 8 deletions src/hooks/useCombobox/reducer.js
Expand Up @@ -115,14 +115,18 @@ export default function downshiftUseComboboxReducer(state, action) {
}
break
case stateChangeTypes.InputBlur:
changes = {
isOpen: false,
highlightedIndex: -1,
...(state.highlightedIndex >= 0 &&
action.selectItem && {
selectedItem: props.items[state.highlightedIndex],
inputValue: props.itemToString(props.items[state.highlightedIndex]),
}),
if (state.isOpen) {
changes = {
isOpen: false,
highlightedIndex: -1,
...(state.highlightedIndex >= 0 &&
action.selectItem && {
selectedItem: props.items[state.highlightedIndex],
inputValue: props.itemToString(
props.items[state.highlightedIndex],
),
}),
}
}
break
case stateChangeTypes.InputChange:
Expand Down

0 comments on commit d1299c4

Please sign in to comment.