Skip to content

Commit

Permalink
FE-814 Use children instead of menu prop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonambas committed Apr 9, 2020
1 parent be21822 commit 76a4dcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/matchbox/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ function ComboBox(props) {

// Clones children in order to pass the menu into the textfield
// Textfield inserts the menu in the DOM directly after the input, before helptext and error
const menu = React.useMemo(() => getChild('ComboBoxMenu'), [children]);
const textfield = React.useMemo(() => getChild('ComboBoxTextField', { menu }), [children]);
const textfieldWithMenu = React.useMemo(() => {
return getChild('ComboBoxTextField', { children: getChild('ComboBoxMenu') });
}, [children]);

return (
<Box position="relative" ref={rootRef} style={style} {...rest}>
{textfield}
{textfieldWithMenu}
</Box>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function ComboBoxTextField(props) {
const {
autoFocus,
disabled,
children,
error,
errorInLabel,
helpText,
id,
itemToString,
label,
labelHidden,
menu,
name,
onChange,
onFocus,
Expand Down Expand Up @@ -113,7 +113,7 @@ function ComboBoxTextField(props) {
/>
</StyledInputWrapper>
{/* Menu is rendered here so it is positioned correctly before error and helptext */}
{menu && menu}
{children}
{error && !errorInLabel && <Error id={errorId} error={error} />}
{helpText && <HelpText id={helpTextId}>{helpText}</HelpText>}
</StyledWrapper>
Expand All @@ -123,14 +123,14 @@ function ComboBoxTextField(props) {
ComboBoxTextField.propTypes = {
autoFocus: PropTypes.bool,
disabled: PropTypes.bool,
children: PropTypes.node,
error: PropTypes.string,
errorInLabel: PropTypes.bool,
helpText: PropTypes.node,
id: PropTypes.string.isRequired,
itemToString: PropTypes.func,
label: PropTypes.string,
labelHidden: PropTypes.bool,
menu: PropTypes.node,
name: PropTypes.string,
onChange: PropTypes.func,
onFocus: PropTypes.func,
Expand Down

0 comments on commit 76a4dcc

Please sign in to comment.