@skyscanner/backpack-web 42.13.1 → 42.13.2

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.
@@ -101,6 +101,18 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
101
101
  changes,
102
102
  type
103
103
  } = actionAndChanges;
104
+
105
+ // Intercept InputBlur before the alwaysRenderSuggestions early-return
106
+ if (type === useCombobox.stateChangeTypes.InputBlur) {
107
+ const keepOpen = Boolean(alwaysRenderSuggestions && hasSuggestions);
108
+ return {
109
+ ...changes,
110
+ isOpen: keepOpen,
111
+ highlightedIndex: -1,
112
+ selectedItem: state.selectedItem,
113
+ inputValue: state.inputValue
114
+ };
115
+ }
104
116
  const shouldForceKeepOpen = alwaysRenderSuggestions && hasSuggestions && changes.isOpen === false;
105
117
  if (shouldForceKeepOpen) {
106
118
  return {
@@ -205,6 +217,11 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
205
217
  onSuggestionHighlighted?.({
206
218
  suggestion: currentSuggestion
207
219
  });
220
+
221
+ // Only arm auto-select-on-blur for non-mouse-driven highlight changes.
222
+ if (type !== useCombobox.stateChangeTypes.ItemMouseMove && type !== useCombobox.stateChangeTypes.MenuMouseLeave) {
223
+ savedHighlightedIndexRef.current = newIndex ?? null;
224
+ }
208
225
  const isArrowKey = type === useCombobox.stateChangeTypes.InputKeyDownArrowDown || type === useCombobox.stateChangeTypes.InputKeyDownArrowUp;
209
226
  if (isArrowKey) {
210
227
  if (currentSuggestion) {
@@ -272,8 +289,6 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
272
289
  useEffect(() => {
273
290
  if (highlightedIndex === previousHighlightedIndexRef.current) return;
274
291
  previousHighlightedIndexRef.current = highlightedIndex;
275
- // Save highlighted index to allow auto-selection on blur
276
- savedHighlightedIndexRef.current = highlightedIndex;
277
292
  const currentSuggestion = highlightedIndex != null && highlightedIndex >= 0 ? flattenedSuggestions?.[highlightedIndex] ?? null : null;
278
293
  if (!currentSuggestion && originalInputOnPreviewRef.current !== null) {
279
294
  if ((inputValue ?? '') !== originalInputOnPreviewRef.current) {
@@ -463,8 +478,11 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
463
478
  highlightedSuggestion = firstSuggestion;
464
479
  }
465
480
  if (highlightedSuggestion) {
466
- // Use setTimeout to ensure selectItem runs after the blur event completes
481
+ // Use setTimeout to ensure selectItem runs after the blur event completes.
467
482
  setTimeout(() => {
483
+ if (committedSelectionRef.current) {
484
+ return;
485
+ }
468
486
  selectItem(highlightedSuggestion);
469
487
  }, 0);
470
488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "42.13.1",
3
+ "version": "42.13.2",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",