-
Notifications
You must be signed in to change notification settings - Fork 14
ComboBox stateful with hooks #750 #793
ComboBox stateful with hooks #750 #793
Conversation
eef87d3
to
7940b2b
Compare
Blocked till we update all components with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boom 💥 Other than updating to use useTheme
(which is blocked) this looks perfect to me!
One thing: maybe it’s worth generalizing the useSelectedOption
custom hook and adding it to src/utils/customHooks.js
. Only question is what to call it 🤔 usePropOverridesState
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hell yeah! 🔥 I have only one tiny thing to add:
0e2cfbc
to
fb16478
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Just a couple minor things I noticed:
The following functions could use useCallback
with an empty array as second arg:
handleClick
handleMouseOutOption
handleBlur
src/ComboBox/index.jsx
Outdated
value, | ||
} = props; | ||
|
||
const [ optionSelected, setOptionSelected ] = useSelection( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call it selection
and setSelection
instead? optionSelected
implies a single option but it could be multiple
src/ComboBox/index.jsx
Outdated
const { isMultiselect, onChange } = this.props; | ||
const unprefixedId = removePrefix( optId, id ); | ||
|
||
let newSelection = !isReadOnly ? getOption( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling getOption
here is redundant (I think) since we already have the id
of the new option (unprefixedId
)
src/ComboBox/index.jsx
Outdated
value : undefined, | ||
}; | ||
|
||
ComboBox.displayName = 'ComboBox'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComboBox.displayName = 'ComboBox'; | |
ComboBox.displayName = componentName; |
src/ComboBox/index.jsx
Outdated
[ props.id ], | ||
); | ||
|
||
const filteredOptions = searchValue && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use useMemo
with [ flatOptions, searchValue ]
|
||
handleClickClose( { id } ) | ||
const handleClickClose = useCallback( ( { id : tagId } ) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array of props to watch is missing from this useCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💥
Just one thing:
src/ComboBox/index.jsx
Outdated
const activeOption = useMemo( | ||
() => ( ( searchValue && filteredOptions.length ) ? | ||
filteredOptions[ 0 ].id : stateActiveOption ), | ||
[ flatOptions, searchValue, stateActiveOption ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ flatOptions, searchValue, stateActiveOption ], | |
[ filteredOptions, searchValue, stateActiveOption ], |
b743ec8
to
9a602d3
Compare
PR for #750