diff --git a/CHANGELOG.md b/CHANGELOG.md index 329dc26..161c3c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### 1.1.2 (15 Mar 2022) +- Add note to README regarding onSelect being called when an item is no longer selected - Use autofocus HTML attribute instead of a useEffect hook - Add MIT License - Add precommit hooks for test and lint diff --git a/README.md b/README.md index 341fd05..d0ece3f 100644 --- a/README.md +++ b/README.md @@ -424,6 +424,7 @@ in order to exit the focused state of the search box. - The following arguments are passed to the `onSelect` function: 1. `selectedItem` The item selected by the user. This is in the same format as received from `listbox.data`. 1. `displayField` (string / number / undefined) The field in `selectedItem` that contains the text displayed in the listbox. If `selectedItem` is not an array or an object, `displayField` is `undefined`. +- This function is also called with `undefined` arguments to indicate when an item is no longer selected #### `onTab` - Type: `function` diff --git a/src/lib/components/hooks/containerEffects.js b/src/lib/components/hooks/containerEffects.js index 8a135d5..9b141cd 100644 --- a/src/lib/components/hooks/containerEffects.js +++ b/src/lib/components/hooks/containerEffects.js @@ -71,7 +71,6 @@ export const useSelected = (selected, queryInput, typeaheadInput, onSelect) => { displayField = selected.displayField } - //TODO: Check if it's necessary to call this when value is undef if (typeof onSelect === 'function') onSelect(value, displayField) }, [selected, onSelect, queryInput, typeaheadInput]) }