@digitransit-component/digitransit-component-autosuggest 9.0.1 → 9.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.development.cjs +14 -1
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -6345,6 +6345,10 @@ function getLabel(properties) {
|
|
|
6345
6345
|
}
|
|
6346
6346
|
}
|
|
6347
6347
|
|
|
6348
|
+
// The scrolling element is the menu's wrapper, outside downshift's menu node.
|
|
6349
|
+
const scrollItemIntoView = node => node.scrollIntoView({
|
|
6350
|
+
block: 'nearest'
|
|
6351
|
+
});
|
|
6348
6352
|
const isKeyboardSelectionEvent = event => {
|
|
6349
6353
|
const space = [13, ' ', 'Spacebar'];
|
|
6350
6354
|
const enter = [32, 'Enter'];
|
|
@@ -6883,6 +6887,7 @@ const MobileView = ({
|
|
|
6883
6887
|
items: state.suggestions,
|
|
6884
6888
|
inputValue: value,
|
|
6885
6889
|
isOpen: true,
|
|
6890
|
+
scrollIntoView: scrollItemIntoView,
|
|
6886
6891
|
onSelectedItemChange: changes => {
|
|
6887
6892
|
onSelectedItemChange(changes);
|
|
6888
6893
|
dispatch({
|
|
@@ -7465,6 +7470,8 @@ function DTAutosuggest({
|
|
|
7465
7470
|
// not something that should itself trigger a render or round-trip through
|
|
7466
7471
|
// another dispatch.
|
|
7467
7472
|
const pendingEnterRef = useRef(false);
|
|
7473
|
+
// Identifies the latest search so results of superseded searches are ignored.
|
|
7474
|
+
const searchIdRef = useRef(0);
|
|
7468
7475
|
useEffect(() => {
|
|
7469
7476
|
if (storeRef) {
|
|
7470
7477
|
storeRef(inputRef.current);
|
|
@@ -7482,9 +7489,14 @@ function DTAutosuggest({
|
|
|
7482
7489
|
});
|
|
7483
7490
|
// remove location favourites in desktop search (collection item replaces it in target array)
|
|
7484
7491
|
const newSources = state.sources ? state.sources.filter(s => !isLocationSearch || !s === 'Favourite' || state.showOwnPlaces || isMobile) : state.sources;
|
|
7492
|
+
searchIdRef.current += 1;
|
|
7493
|
+
const searchId = searchIdRef.current;
|
|
7485
7494
|
executeSearch(newTargets, newSources, transportMode, searchContext, filterResults, geocodingSize, {
|
|
7486
7495
|
input: state.value || ''
|
|
7487
7496
|
}, searchResult => {
|
|
7497
|
+
if (searchId !== searchIdRef.current) {
|
|
7498
|
+
return;
|
|
7499
|
+
}
|
|
7488
7500
|
if (searchResult == null) {
|
|
7489
7501
|
dispatch({
|
|
7490
7502
|
type: 'FETCH_SUGGESTIONS',
|
|
@@ -7569,6 +7581,7 @@ function DTAutosuggest({
|
|
|
7569
7581
|
} = useCombobox({
|
|
7570
7582
|
inputId: id,
|
|
7571
7583
|
inputValue: state.value,
|
|
7584
|
+
scrollIntoView: scrollItemIntoView,
|
|
7572
7585
|
defaultHighlightedIndex: 0,
|
|
7573
7586
|
// Typing is dispatched synchronously by Input. Downshift reports it from an
|
|
7574
7587
|
// effect a render late, which would overwrite newer keystrokes.
|