Skip to content

Commit

Permalink
feat: 🎸 Added onInputChange prop to autocomplete component
Browse files Browse the repository at this point in the history
✅ Closes: #65
  • Loading branch information
Chris-Boyle committed Jan 12, 2021
1 parent 5161f99 commit 2b08d17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/SQForm/SQFormAsyncAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function SQFormAsyncAutocomplete({
name,
onBlur,
onChange,
onInputChange,
handleAsyncInputChange,
loading,
open,
Expand Down Expand Up @@ -142,8 +143,9 @@ function SQFormAsyncAutocomplete({
(_event, value) => {
setInputValue(value);
handleAsyncInputChange(value);
onInputChange && onInputChange();
},
[handleAsyncInputChange]
[handleAsyncInputChange, onInputChange]
);

return (
Expand Down Expand Up @@ -231,6 +233,8 @@ SQFormAsyncAutocomplete.propTypes = {
onBlur: PropTypes.func,
/** Custom onChange event callback */
onChange: PropTypes.func,
/** Custom onInputChange event callback (key pressed)*/
onInputChange: PropTypes.func,
/** Size of the input given full-width is 12. */
size: PropTypes.oneOf(['auto', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
};
Expand Down
13 changes: 10 additions & 3 deletions src/components/SQForm/SQFormAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function SQFormAutocomplete({
name,
onBlur,
onChange,
onInputChange,
size = 'auto'
}) {
const classes = useStyles();
Expand Down Expand Up @@ -140,9 +141,13 @@ function SQFormAutocomplete({
[name, onChange, setFieldValue]
);

const handleInputChange = React.useCallback((_event, value) => {
setInputValue(value);
}, []);
const handleInputChange = React.useCallback(
(_event, value) => {
setInputValue(value);
onInputChange && onInputChange();
},
[onInputChange]
);

return (
<Grid item sm={size}>
Expand Down Expand Up @@ -214,6 +219,8 @@ SQFormAutocomplete.propTypes = {
onBlur: PropTypes.func,
/** Custom onChange event callback */
onChange: PropTypes.func,
/** Custom onInputChange event callback (key pressed) */
onInputChange: PropTypes.func,
/** Size of the input given full-width is 12. */
size: PropTypes.oneOf(['auto', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
};
Expand Down
1 change: 1 addition & 0 deletions stories/SQForm.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const basicForm = () => {
name="tenThousandOptions"
label="Ten Thousand Options"
size={6}
onInputChange={action('Update local state')}
>
{MOCK_AUTOCOMPLETE_OPTIONS}
</SQFormAutocomplete>
Expand Down

0 comments on commit 2b08d17

Please sign in to comment.