Skip to content

Commit

Permalink
feat(react): added input change callback to multiselect filterable (#…
Browse files Browse the repository at this point in the history
…11415)

* feat(react): added input change callback to multiselect filterable

* chore(react): removed story changes for previous version

* chore(project): update snaps

* chore(react): updated handleOnInputValueChange to remove type param

Co-authored-by: Taylor Jones <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 17, 2022
1 parent 84b57db commit 606664e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 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 @@ -3154,6 +3154,9 @@ Map {
"onChange": Object {
"type": "func",
},
"onInputValueChange": Object {
"type": "func",
},
"onMenuChange": Object {
"type": "func",
},
Expand Down Expand Up @@ -4339,6 +4342,9 @@ Map {
"onChange": Object {
"type": "func",
},
"onInputValueChange": Object {
"type": "func",
},
"onMenuChange": Object {
"type": "func",
},
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/components/MultiSelect/FilterableMultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export default class FilterableMultiSelect extends React.Component {
*/
onChange: PropTypes.func,

/**
* `onInputValueChange` is a utility for this controlled component to communicate to
* the currently typed input.
*/
onInputValueChange: PropTypes.func,

/**
* `onMenuChange` is a utility for this controlled component to communicate to a
* consuming component that the menu was opened(`true`)/closed(`false`).
Expand Down Expand Up @@ -259,6 +265,10 @@ export default class FilterableMultiSelect extends React.Component {
};

handleOnInputValueChange = (inputValue, { type }) => {
if (this.props.onInputValueChange) {
this.props.onInputValueChange(inputValue);
}

if (type !== Downshift.stateChangeTypes.changeInput) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect(
itemToString,
light,
locale,
onInputValueChange,
open,
onChange,
onMenuChange,
Expand Down Expand Up @@ -165,6 +166,10 @@ const FilterableMultiSelect = React.forwardRef(function FilterableMultiSelect(
}

function handleOnInputValueChange(inputValue, { type }) {
if (onInputValueChange) {
onInputValueChange(inputValue);
}

if (type !== Downshift.stateChangeTypes.changeInput) {
return;
}
Expand Down Expand Up @@ -515,6 +520,12 @@ FilterableMultiSelect.propTypes = {
*/
onChange: PropTypes.func,

/**
* `onInputValueChange` is a utility for this controlled component to communicate to
* the currently typed input.
*/
onInputValueChange: PropTypes.func,

/**
* `onMenuChange` is a utility for this controlled component to communicate to a
* consuming component that the menu was opened(`true`)/closed(`false`).
Expand Down

0 comments on commit 606664e

Please sign in to comment.