Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

ComboBox stateful with hooks #750 #793

Merged

Conversation

damian-rodriguez-sociomantic
Copy link
Contributor

PR for #750

@damian-rodriguez-sociomantic
Copy link
Contributor Author

Blocked till we update all components with useTheme custom Hook

Copy link
Contributor

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?

Copy link
Contributor

@daniel-martic-sociomantic daniel-martic-sociomantic left a 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:

src/ComboBox/index.jsx Outdated Show resolved Hide resolved
Copy link
Contributor

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

value,
} = props;

const [ optionSelected, setOptionSelected ] = useSelection(

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

const { isMultiselect, onChange } = this.props;
const unprefixedId = removePrefix( optId, id );

let newSelection = !isReadOnly ? getOption(

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)

value : undefined,
};

ComboBox.displayName = 'ComboBox';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ComboBox.displayName = 'ComboBox';
ComboBox.displayName = componentName;

[ props.id ],
);

const filteredOptions = searchValue && (

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 } ) =>

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

Just one thing:

const activeOption = useMemo(
() => ( ( searchValue && filteredOptions.length ) ?
filteredOptions[ 0 ].id : stateActiveOption ),
[ flatOptions, searchValue, stateActiveOption ],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[ flatOptions, searchValue, stateActiveOption ],
[ filteredOptions, searchValue, stateActiveOption ],

@conor-cafferkey-sociomantic conor-cafferkey-sociomantic merged commit 8ffb3a4 into Milestone-Hooks! Mar 4, 2019
@conor-cafferkey-sociomantic conor-cafferkey-sociomantic deleted the Issue-750-ComboBoxWithHooks! branch March 4, 2019 15:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants