From 2485371edf2fbe829193428966bf4bd197f7c63c Mon Sep 17 00:00:00 2001 From: Josh Black Date: Tue, 14 Jul 2020 16:29:59 -0500 Subject: [PATCH] fix(dropdown,multiselect): add support for refs on buttons (#6441) Co-authored-by: Alessandra Davila --- .../__snapshots__/PublicAPI-test.js.snap | 6 ++ .../react/src/components/Dropdown/Dropdown.js | 53 +++++++++-------- .../src/components/MultiSelect/MultiSelect.js | 57 ++++++++++--------- 3 files changed, 66 insertions(+), 50 deletions(-) diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 6554a90d2498..948c96b53c9c 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -2146,6 +2146,7 @@ Map { }, }, "Dropdown" => Object { + "$$typeof": Symbol(react.forward_ref), "defaultProps": Object { "direction": "bottom", "disabled": false, @@ -2156,6 +2157,7 @@ Map { "titleText": "", "type": "default", }, + "displayName": "Dropdown", "propTypes": Object { "ariaLabel": Object { "type": "string", @@ -2285,6 +2287,7 @@ Map { "type": "oneOf", }, }, + "render": [Function], }, "ErrorBoundary" => Object { "contextType": Object { @@ -3251,6 +3254,7 @@ Map { }, }, "MultiSelect" => Object { + "$$typeof": Symbol(react.forward_ref), "Filterable": Object { "defaultProps": Object { "ariaLabel": "Choose an item", @@ -3481,6 +3485,7 @@ Map { "title": false, "type": "default", }, + "displayName": "MultiSelect", "propTypes": Object { "compareItems": Object { "isRequired": true, @@ -3696,6 +3701,7 @@ Map { "type": "bool", }, }, + "render": [Function], }, "ToastNotification" => Object { "defaultProps": Object { diff --git a/packages/react/src/components/Dropdown/Dropdown.js b/packages/react/src/components/Dropdown/Dropdown.js index 696690a036c3..e1c68b355d13 100644 --- a/packages/react/src/components/Dropdown/Dropdown.js +++ b/packages/react/src/components/Dropdown/Dropdown.js @@ -24,29 +24,32 @@ const defaultItemToString = (item) => { return item ? item.label : ''; }; -function Dropdown({ - className: containerClassName, - disabled, - direction, - items, - label, - ariaLabel, - itemToString, - itemToElement, - type, - size, - onChange, - id, - titleText, - helperText, - translateWithId, - light, - invalid, - invalidText, - initialSelectedItem, - selectedItem: controlledSelectedItem, - downshiftProps, -}) { +const Dropdown = React.forwardRef(function Dropdown( + { + className: containerClassName, + disabled, + direction, + items, + label, + ariaLabel, + itemToString, + itemToElement, + type, + size, + onChange, + id, + titleText, + helperText, + translateWithId, + light, + invalid, + invalidText, + initialSelectedItem, + selectedItem: controlledSelectedItem, + downshiftProps, + }, + ref +) { const selectProps = mapDownshiftProps({ ...downshiftProps, items, @@ -134,6 +137,7 @@ function Dropdown({ )}