Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): add prop adapter for downshift changes #6427

Merged
merged 9 commits into from
Jul 10, 2020
5 changes: 3 additions & 2 deletions packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Checkmark16, WarningFilled16 } from '@carbon/icons-react';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { match, keys } from '../../internal/keyboard';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
import { mapDownshiftProps } from '../../tools/createPropAdapter';

const { prefix } = settings;

Expand Down Expand Up @@ -333,13 +334,13 @@ export default class ComboBox extends React.Component {
const ItemToElement = itemToElement;
return (
<Downshift
{...downshiftProps}
{...mapDownshiftProps(downshiftProps)}
onChange={this.handleOnChange}
onInputValueChange={this.handleOnInputValueChange}
onStateChange={this.handleOnStateChange}
inputValue={this.state.inputValue || ''}
itemToString={itemToString}
defaultSelectedItem={initialSelectedItem}
initialSelectedItem={initialSelectedItem}
inputId={id}
selectedItem={selectedItem}>
{({
Expand Down
7 changes: 4 additions & 3 deletions packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { useSelect } from 'downshift';
import { settings } from 'carbon-components';
import cx from 'classnames';
import PropTypes from 'prop-types';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { Checkmark16, WarningFilled16 } from '@carbon/icons-react';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { mapDownshiftProps } from '../../tools/createPropAdapter';

const { prefix } = settings;

Expand Down Expand Up @@ -46,13 +47,13 @@ function Dropdown({
selectedItem: controlledSelectedItem,
downshiftProps,
}) {
const selectProps = {
const selectProps = mapDownshiftProps({
...downshiftProps,
items,
itemToString,
initialSelectedItem,
onSelectedItemChange,
};
});

// only set selectedItem if the prop is defined. Setting if it is undefined
// will overwrite default selected items from useSelect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { defaultItemToString } from './tools/itemToString';
import { defaultSortItems, defaultCompareItems } from './tools/sorting';
import { defaultFilterItems } from '../ComboBox/tools/filter';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
import { mapDownshiftProps } from '../../tools/createPropAdapter';

const { prefix } = settings;

Expand Down Expand Up @@ -321,7 +322,7 @@ export default class FilterableMultiSelect extends React.Component {
initialSelectedItems={initialSelectedItems}
render={({ selectedItems, onItemChange, clearSelection }) => (
<Downshift
{...downshiftProps}
{...mapDownshiftProps(downshiftProps)}
highlightedIndex={highlightedIndex}
id={id}
isOpen={isOpen}
Expand Down
21 changes: 12 additions & 9 deletions packages/react/src/components/MultiSelect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { defaultItemToString } from './tools/itemToString';
import { defaultSortItems, defaultCompareItems } from './tools/sorting';
import { useSelection } from '../../internal/Selection';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
import { mapDownshiftProps } from '../../tools/createPropAdapter';

const { prefix } = settings;
const noop = () => {};
Expand Down Expand Up @@ -79,15 +80,17 @@ function MultiSelect({
getMenuProps,
getItemProps,
selectedItem: selectedItems,
} = useSelect({
...downshiftProps,
highlightedIndex,
isOpen,
itemToString,
onStateChange,
selectedItem: controlledSelectedItems,
items,
});
} = useSelect(
mapDownshiftProps({
...downshiftProps,
highlightedIndex,
isOpen,
itemToString,
onStateChange,
selectedItem: controlledSelectedItems,
items,
})
);

/**
* programmatically control this `open` prop
Expand Down