Skip to content

Commit

Permalink
fix(dropdown,multiselect): add support for refs on buttons (#6441)
Browse files Browse the repository at this point in the history
Co-authored-by: Alessandra Davila <[email protected]>
  • Loading branch information
joshblack and Alessandra Davila authored Jul 14, 2020
1 parent cc8d771 commit 2485371
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 50 deletions.
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,7 @@ Map {
},
},
"Dropdown" => Object {
"$$typeof": Symbol(react.forward_ref),
"defaultProps": Object {
"direction": "bottom",
"disabled": false,
Expand All @@ -2156,6 +2157,7 @@ Map {
"titleText": "",
"type": "default",
},
"displayName": "Dropdown",
"propTypes": Object {
"ariaLabel": Object {
"type": "string",
Expand Down Expand Up @@ -2285,6 +2287,7 @@ Map {
"type": "oneOf",
},
},
"render": [Function],
},
"ErrorBoundary" => Object {
"contextType": Object {
Expand Down Expand Up @@ -3251,6 +3254,7 @@ Map {
},
},
"MultiSelect" => Object {
"$$typeof": Symbol(react.forward_ref),
"Filterable": Object {
"defaultProps": Object {
"ariaLabel": "Choose an item",
Expand Down Expand Up @@ -3481,6 +3485,7 @@ Map {
"title": false,
"type": "default",
},
"displayName": "MultiSelect",
"propTypes": Object {
"compareItems": Object {
"isRequired": true,
Expand Down Expand Up @@ -3696,6 +3701,7 @@ Map {
"type": "bool",
},
},
"render": [Function],
},
"ToastNotification" => Object {
"defaultProps": Object {
Expand Down
53 changes: 29 additions & 24 deletions packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -134,6 +137,7 @@ function Dropdown({
<WarningFilled16 className={`${prefix}--list-box__invalid-icon`} />
)}
<button
ref={ref}
className={`${prefix}--list-box__field`}
disabled={disabled}
aria-disabled={disabled}
Expand Down Expand Up @@ -174,8 +178,9 @@ function Dropdown({
{!inline && !invalid && helper}
</div>
);
}
});

Dropdown.displayName = 'Dropdown';
Dropdown.propTypes = {
/**
* Disable the control
Expand Down
57 changes: 31 additions & 26 deletions packages/react/src/components/MultiSelect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,34 @@ const {
ToggleButtonClick,
} = useSelect.stateChangeTypes;

function MultiSelect({
className: containerClassName,
id,
items,
itemToString,
titleText,
helperText,
label,
type,
size,
disabled,
initialSelectedItems,
sortItems,
compareItems,
light,
invalid,
invalidText,
useTitleInItem,
translateWithId,
downshiftProps,
open,
selectionFeedback,
onChange,
direction,
}) {
const MultiSelect = React.forwardRef(function MultiSelect(
{
className: containerClassName,
id,
items,
itemToString,
titleText,
helperText,
label,
type,
size,
disabled,
initialSelectedItems,
sortItems,
compareItems,
light,
invalid,
invalidText,
useTitleInItem,
translateWithId,
downshiftProps,
open,
selectionFeedback,
onChange,
direction,
},
ref
) {
const { current: multiSelectInstanceId } = useRef(getInstanceId());
const [highlightedIndex, setHighlightedIndex] = useState(null);
const [isOpen, setIsOpen] = useState(open);
Expand Down Expand Up @@ -192,6 +195,7 @@ function MultiSelect({
<WarningFilled16 className={`${prefix}--list-box__invalid-icon`} />
)}
<button
ref={ref}
className={`${prefix}--list-box__field`}
disabled={disabled}
aria-disabled={disabled}
Expand Down Expand Up @@ -247,8 +251,9 @@ function MultiSelect({
)}
</div>
);
}
});

MultiSelect.displayName = 'MultiSelect';
MultiSelect.propTypes = {
...sortingPropTypes,

Expand Down

0 comments on commit 2485371

Please sign in to comment.