@skyscanner/backpack-web 40.1.0 → 40.1.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.
@@ -76,6 +76,7 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
76
76
  };
77
77
  const arrowRef = useRef(null);
78
78
  const previousHighlightedIndexRef = useRef(null);
79
+ const originalInputOnPreviewRef = useRef(null);
79
80
  const hasInteractedRef = useRef(false);
80
81
  const hasLoadedInitiallyRef = useRef(false);
81
82
  const suggestionsCount = suggestions.length;
@@ -135,12 +136,14 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
135
136
  method: type,
136
137
  newValue: newInputValue ?? ''
137
138
  });
138
- if (newInputValue?.length > 0) {
139
- if (newIsOpen) {
140
- onSuggestionsFetchRequested(newInputValue);
139
+ if (type === useCombobox.stateChangeTypes.InputChange) {
140
+ if (newInputValue?.length > 0) {
141
+ if (newIsOpen) {
142
+ onSuggestionsFetchRequested(newInputValue);
143
+ }
144
+ } else {
145
+ onSuggestionsFetchRequested('');
141
146
  }
142
- } else {
143
- onSuggestionsFetchRequested('');
144
147
  }
145
148
  },
146
149
  onSelectedItemChange(changes) {
@@ -149,6 +152,7 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
149
152
  } = changes;
150
153
  if (selectedItem) {
151
154
  setInputValue(getSuggestionValue(selectedItem));
155
+ originalInputOnPreviewRef.current = null;
152
156
  onSuggestionSelected?.({
153
157
  suggestion: selectedItem,
154
158
  inputValue
@@ -163,7 +167,34 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
163
167
  return getA11yResultsMessage?.(suggestionsCount) ?? '';
164
168
  },
165
169
  initialInputValue: defaultValue ?? '',
166
- id
170
+ id,
171
+ onHighlightedIndexChange(changes) {
172
+ const {
173
+ highlightedIndex: newIndex,
174
+ type
175
+ } = changes;
176
+ const currentSuggestion = newIndex != null && newIndex >= 0 ? flattenedSuggestions?.[newIndex] ?? null : null;
177
+ onSuggestionHighlighted?.({
178
+ suggestion: currentSuggestion
179
+ });
180
+ const isArrowKey = type === useCombobox.stateChangeTypes.InputKeyDownArrowDown || type === useCombobox.stateChangeTypes.InputKeyDownArrowUp;
181
+ if (isArrowKey) {
182
+ if (currentSuggestion) {
183
+ if (originalInputOnPreviewRef.current === null) {
184
+ originalInputOnPreviewRef.current = inputValue ?? '';
185
+ }
186
+ const previewValue = getSuggestionValue(currentSuggestion);
187
+ if (previewValue !== inputValue) {
188
+ setInputValue(previewValue);
189
+ }
190
+ } else if (originalInputOnPreviewRef.current !== null) {
191
+ if ((inputValue ?? '') !== originalInputOnPreviewRef.current) {
192
+ setInputValue(originalInputOnPreviewRef.current);
193
+ }
194
+ originalInputOnPreviewRef.current = null;
195
+ }
196
+ }
197
+ }
167
198
  });
168
199
  const {
169
200
  context,
@@ -171,6 +202,11 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
171
202
  refs
172
203
  } = useFloating({
173
204
  placement: 'bottom-start',
205
+ // Use fixed strategy on desktop to avoid stacking context issues with table headers
206
+ // Fixed positioning is relative to viewport, not affected by parent transforms/overflows
207
+ ...(isDesktop && {
208
+ strategy: 'fixed'
209
+ }),
174
210
  middleware: isDesktop ? [offset(4), flip(), shift(), size({
175
211
  apply({
176
212
  elements,
@@ -209,10 +245,16 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
209
245
  if (highlightedIndex === previousHighlightedIndexRef.current) return;
210
246
  previousHighlightedIndexRef.current = highlightedIndex;
211
247
  const currentSuggestion = highlightedIndex != null && highlightedIndex >= 0 ? flattenedSuggestions?.[highlightedIndex] ?? null : null;
248
+ if (!currentSuggestion && originalInputOnPreviewRef.current !== null) {
249
+ if ((inputValue ?? '') !== originalInputOnPreviewRef.current) {
250
+ setInputValue(originalInputOnPreviewRef.current);
251
+ }
252
+ originalInputOnPreviewRef.current = null;
253
+ }
212
254
  onSuggestionHighlighted?.({
213
255
  suggestion: currentSuggestion
214
256
  });
215
- }, [highlightedIndex, flattenedSuggestions, onSuggestionHighlighted]);
257
+ }, [highlightedIndex, flattenedSuggestions, onSuggestionHighlighted, inputValue, setInputValue]);
216
258
  const handleInputInteraction = () => {
217
259
  hasInteractedRef.current = true;
218
260
  if (shouldRenderSuggestions) {
@@ -389,6 +431,14 @@ const BpkAutosuggest = /*#__PURE__*/forwardRef(({
389
431
  refs.setReference(containerWrapperRef.current);
390
432
  }
391
433
  }, [refs]);
434
+
435
+ // Call getMenuProps on every render to satisfy Downshift.
436
+ // When hidden, use suppressRefError to avoid ref warnings.
437
+ if (!showSuggestions) {
438
+ getMenuProps({}, {
439
+ suppressRefError: true
440
+ });
441
+ }
392
442
  return /*#__PURE__*/_jsxs("div", {
393
443
  ref: containerWrapperRef,
394
444
  className: getClassName(theme.container, suggestionsCount && theme.containerOpen),
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonDestructive is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.destructive} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Destructive button component
6
+ */
2
7
  declare const BpkButtonDestructive: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonDestructive;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonDestructive is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.destructive} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Destructive button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonDestructive = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonFeatured is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.featured} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Featured button component
6
+ */
2
7
  declare const BpkButtonFeatured: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonFeatured;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonFeatured is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.featured} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Featured button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonFeatured = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonLink is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.link} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Link button component
6
+ */
2
7
  declare const BpkButtonLink: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonLink;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonLink is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.link} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Link button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonLink = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonLinkOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.linkOnDark} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Link on dark button component
6
+ */
2
7
  declare const BpkButtonLinkOnDark: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonLinkOnDark;
@@ -16,6 +16,12 @@
16
16
  * limitations under the License.
17
17
  */
18
18
  import BpkButton from "./src/BpkButton";
19
+
20
+ /**
21
+ * @deprecated BpkButtonLinkOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.linkOnDark} instead.
22
+ * @param {Props} props - Component props
23
+ * @returns {JSX.Element} Link on dark button component
24
+ */
19
25
  import { jsx as _jsx } from "react/jsx-runtime";
20
26
  const BpkButtonLinkOnDark = props => /*#__PURE__*/_jsx(BpkButton, {
21
27
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonPrimary is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primary} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Primary button component
6
+ */
2
7
  declare const BpkButtonPrimary: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonPrimary;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonPrimary is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primary} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Primary button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonPrimary = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonPrimaryOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primaryOnDark} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Primary on dark button component
6
+ */
2
7
  declare const BpkButtonPrimaryOnDark: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonPrimaryOnDark;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonPrimaryOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primaryOnDark} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Primary on dark button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonPrimaryOnDark = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonPrimaryOnLight is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primaryOnLight} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Primary on light button component
6
+ */
2
7
  declare const BpkButtonPrimaryOnLight: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonPrimaryOnLight;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonPrimaryOnLight is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.primaryOnLight} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Primary on light button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonPrimaryOnLight = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonSecondary is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.secondary} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Secondary button component
6
+ */
2
7
  declare const BpkButtonSecondary: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonSecondary;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonSecondary is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.secondary} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Secondary button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonSecondary = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -1,3 +1,8 @@
1
1
  import { type Props } from './src/BpkButton';
2
+ /**
3
+ * @deprecated BpkButtonSecondaryOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.secondaryOnDark} instead.
4
+ * @param {Props} props - Component props
5
+ * @returns {JSX.Element} Secondary on dark button component
6
+ */
2
7
  declare const BpkButtonSecondaryOnDark: (props: Props) => import("react/jsx-runtime").JSX.Element;
3
8
  export default BpkButtonSecondaryOnDark;
@@ -17,6 +17,12 @@
17
17
  */
18
18
 
19
19
  import BpkButton from "./src/BpkButton";
20
+
21
+ /**
22
+ * @deprecated BpkButtonSecondaryOnDark is deprecated and will be removed in a future major version. Please use BpkButtonV2 with type={BUTTON_TYPES.secondaryOnDark} instead.
23
+ * @param {Props} props - Component props
24
+ * @returns {JSX.Element} Secondary on dark button component
25
+ */
20
26
  import { jsx as _jsx } from "react/jsx-runtime";
21
27
  const BpkButtonSecondaryOnDark = props => /*#__PURE__*/_jsx(BpkButton, {
22
28
  ...props,
@@ -9,7 +9,7 @@ import BpkButtonSecondary from './BpkButtonSecondary';
9
9
  import BpkButtonSecondaryOnDark from './BpkButtonSecondaryOnDark';
10
10
  import BpkButton from './src/BpkButton';
11
11
  import { BpkButtonV2 } from './src/BpkButtonV2/BpkButton';
12
- export { BUTTON_TYPES, SIZE_TYPES } from './src/BpkButtonV2/common-types';
12
+ export { BUTTON_TYPES, SIZE_TYPES, type ButtonType, type SizeType, type Props, } from './src/BpkButtonV2/common-types';
13
13
  export { buttonThemeAttributes, primaryThemeAttributes, primaryOnDarkThemeAttributes, primaryOnLightThemeAttributes, secondaryThemeAttributes, secondaryOnDarkThemeAttributes, featuredThemeAttributes, destructiveThemeAttributes, } from './themeAttributes';
14
14
  export default BpkButton;
15
15
  export { BpkButtonPrimary, BpkButtonPrimaryOnDark, BpkButtonPrimaryOnLight, BpkButtonSecondary, BpkButtonSecondaryOnDark, BpkButtonDestructive, BpkButtonLink, BpkButtonLinkOnDark, BpkButtonFeatured, BpkButtonV2, };
@@ -10,6 +10,11 @@ export type Props = CommonProps & {
10
10
  link?: boolean;
11
11
  linkOnDark?: boolean;
12
12
  };
13
+ /**
14
+ * @deprecated BpkButton is deprecated and will be removed in a future major version. Please use BpkButtonV2 instead.
15
+ * @param {Props} props - Component props
16
+ * @returns {JSX.Element} Button component
17
+ */
13
18
  declare const BpkButton: {
14
19
  ({ destructive, featured, link, linkOnDark, primaryOnDark, primaryOnLight, secondary, secondaryOnDark, ...rest }: Props): import("react/jsx-runtime").JSX.Element;
15
20
  propTypes: {
@@ -19,6 +19,11 @@ import PropTypes from 'prop-types';
19
19
  import BpkButtonBase, { BUTTON_TYPES } from "./BpkButtonBase";
20
20
  import { propTypes } from "./common-types";
21
21
  import { jsx as _jsx } from "react/jsx-runtime";
22
+ /**
23
+ * @deprecated BpkButton is deprecated and will be removed in a future major version. Please use BpkButtonV2 instead.
24
+ * @param {Props} props - Component props
25
+ * @returns {JSX.Element} Button component
26
+ */
22
27
  const BpkButton = ({
23
28
  destructive = false,
24
29
  featured = false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "40.1.0",
3
+ "version": "40.1.2",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",