Skip to content

Commit

Permalink
use getInitialValue
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram committed Aug 1, 2023
1 parent 5ce3acd commit 48cc29b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
6 changes: 2 additions & 4 deletions src/hooks/useCombobox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useControlPropsValidator,
useElementIds,
getItemAndIndex,
getFocusOnOpenValue,
getInitialValue,
} from '../utils'
import {
getInitialState,
Expand All @@ -32,8 +32,6 @@ function useCombobox(userProps = {}) {
...userProps,
}
const {
initialIsOpen,
defaultIsOpen,
items,
scrollIntoView,
environment,
Expand Down Expand Up @@ -107,7 +105,7 @@ function useCombobox(userProps = {}) {
})
// Focus the input on first render if required.
useEffect(() => {
const focusOnOpen = getFocusOnOpenValue(initialIsOpen, defaultIsOpen, isOpen)
const focusOnOpen = getInitialValue(props, 'isOpen')

if (focusOnOpen && inputRef.current) {
inputRef.current.focus()
Expand Down
13 changes: 0 additions & 13 deletions src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,6 @@ const commonDropdownPropTypes = {
scrollIntoView: PropTypes.func,
}

function getFocusOnOpenValue(initialIsOpen, defaultIsOpen, isOpenProp) {
if (isOpenProp !== undefined) {
return isOpenProp
}

if (initialIsOpen !== undefined) {
return initialIsOpen
}

return !!defaultIsOpen
}

export {
useControlPropsValidator,
useScrollIntoView,
Expand All @@ -652,5 +640,4 @@ export {
getChangesOnSelection,
commonDropdownPropTypes,
commonPropTypes,
getFocusOnOpenValue
}

0 comments on commit 48cc29b

Please sign in to comment.