Add note to README regarding onSelect being called when an item is no longer selected

This commit is contained in:
Tom Southall
2022-03-15 14:19:48 +00:00
parent 238080b01f
commit ebacd8b6ef
3 changed files with 2 additions and 1 deletions

View File

@@ -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

View File

@@ -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`

View File

@@ -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])
}