From b68f837989ad0b396b77010245483a24be8fef9e Mon Sep 17 00:00:00 2001 From: Josefina Mancilla <32556167+jnm2377@users.noreply.github.com> Date: Thu, 8 Jul 2021 12:32:58 -0500 Subject: [PATCH] feat(ComboBox): add ability to forward ref (#9136) * feat(ComboBox): add ability to forward ref * chore: update combobox public api snapshot * Update packages/react/src/components/ComboBox/ComboBox-story.js Co-authored-by: Josh Black Co-authored-by: Josh Black Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../react/__tests__/__snapshots__/PublicAPI-test.js.snap | 2 ++ packages/react/src/components/ComboBox/ComboBox.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 1ace0962e8d2..2b282c239bbf 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -438,6 +438,7 @@ Map { }, }, "ComboBox" => Object { + "$$typeof": Symbol(react.forward_ref), "defaultProps": Object { "ariaLabel": "Choose an item", "direction": "bottom", @@ -692,6 +693,7 @@ Map { "type": "node", }, }, + "render": [Function], }, "ComposedModal" => Object { "defaultProps": Object { diff --git a/packages/react/src/components/ComboBox/ComboBox.js b/packages/react/src/components/ComboBox/ComboBox.js index 30a4b6c283f2..f274d16cb222 100644 --- a/packages/react/src/components/ComboBox/ComboBox.js +++ b/packages/react/src/components/ComboBox/ComboBox.js @@ -70,7 +70,7 @@ const findHighlightedIndex = ({ items, itemToString }, inputValue) => { const getInstanceId = setupGetInstanceId(); -const ComboBox = (props) => { +const ComboBox = React.forwardRef((props, ref) => { const { ariaLabel, className: containerClassName, @@ -308,7 +308,7 @@ const ComboBox = (props) => { aria-controls={inputProps['aria-controls']} {...inputProps} {...rest} - ref={mergeRefs(textInput, rootProps.ref)} + ref={mergeRefs(textInput, ref)} /> {invalid && ( { }} ); -}; +}); ComboBox.propTypes = { /**