@skyscanner/backpack-web 41.12.0 → 41.14.0

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.
@@ -38,6 +38,7 @@ const BpkCardList = props => {
38
38
  chipGroup,
39
39
  description,
40
40
  expandText,
41
+ initiallyInViewCardIndex = 0,
41
42
  initiallyShownCardsDesktop = DEFAULT_ITEMS_DESKTOP,
42
43
  initiallyShownCardsMobile = DEFAULT_ITEMS_MOBILE,
43
44
  layoutDesktop,
@@ -78,6 +79,7 @@ const BpkCardList = props => {
78
79
  initiallyShownCards: initiallyShownCardsMobile,
79
80
  layout: layoutMobile,
80
81
  accessibilityLabels: accessibilityLabels,
82
+ initiallyInViewCardIndex: initiallyInViewCardIndex,
81
83
  isMobile: true,
82
84
  children: cardList
83
85
  }), layoutMobile === LAYOUTS.stack && /*#__PURE__*/_jsx(BpkCardListGridStack, {
@@ -97,6 +99,7 @@ const BpkCardList = props => {
97
99
  initiallyShownCards: initiallyShownCardsDesktop,
98
100
  layout: layoutDesktop,
99
101
  accessibilityLabels: accessibilityLabels,
102
+ initiallyInViewCardIndex: initiallyInViewCardIndex,
100
103
  children: cardList
101
104
  }), layoutDesktop === LAYOUTS.grid && accessoryDesktop !== ACCESSORY_DESKTOP_TYPES.pagination && /*#__PURE__*/_jsx(BpkCardListGridStack, {
102
105
  accessory: accessoryDesktop,
@@ -20,7 +20,7 @@ import { useRef, useState, useEffect, isValidElement, Children, useMemo } from '
20
20
  import throttle from 'lodash/throttle';
21
21
  import { cssModules, getDataComponentAttribute } from "../../../bpk-react-utils";
22
22
  import { RENDER_BUFFER_SIZE } from "./constants";
23
- import { lockScroll, setA11yTabIndex, useScrollToCard, useIntersectionObserver } from "./utils";
23
+ import { setA11yTabIndex, useIntersectionObserver, usePageScrollSync } from "./utils";
24
24
  import STYLES from "./BpkCardListCarousel.module.css";
25
25
  import { jsx as _jsx } from "react/jsx-runtime";
26
26
  const getClassName = cssModules(STYLES);
@@ -30,6 +30,7 @@ const BpkCardListCarousel = props => {
30
30
  carouselLabel = (initiallyShownCards, childrenLength) => `Entering Carousel with ${initiallyShownCards} slides shown at a time, ${childrenLength} slides in total. Please use Pagination below with the Previous and Next buttons to navigate, or the slide dot buttons at the end to jump to slides.`,
31
31
  children,
32
32
  currentIndex,
33
+ initialPageIndex,
33
34
  initiallyShownCards,
34
35
  isMobile = false,
35
36
  layout,
@@ -47,13 +48,20 @@ const BpkCardListCarousel = props => {
47
48
  const firstCardWidthRef = useRef(null);
48
49
  const firstCardHeightRef = useRef(null);
49
50
  const [visibilityList, setVisibilityList] = useState(Array(childrenLength).fill(0));
50
- const stateScrollingLockRef = useRef(false);
51
- const openSetStateLockTimeoutRef = useRef(null);
52
51
  const observerVisibility = useIntersectionObserver({
53
52
  root,
54
53
  threshold: 0.5
55
54
  }, setVisibilityList);
56
- useScrollToCard(currentIndex * initiallyShownCards, root, cardRefs, stateScrollingLockRef);
55
+ usePageScrollSync({
56
+ currentIndex,
57
+ setCurrentIndex,
58
+ initiallyShownCards,
59
+ cardRefs,
60
+ visibilityList,
61
+ container: root,
62
+ enabled: !isMobile,
63
+ initialPageIndex
64
+ });
57
65
 
58
66
  // Similar to Virtual Scrolling to improve performance
59
67
  const firstVisibleIndex = Math.max(0, visibilityList.indexOf(1));
@@ -87,22 +95,6 @@ const BpkCardListCarousel = props => {
87
95
  }
88
96
  }
89
97
  }), [childrenLength, observerVisibility, visibilityList, firstCardWidthRef, firstCardHeightRef]);
90
- useEffect(() => {
91
- const container = root;
92
- if (isMobile || !container) return undefined;
93
- const lockScrollDuringInteraction = () => {
94
- lockScroll(stateScrollingLockRef, openSetStateLockTimeoutRef);
95
- };
96
- container.addEventListener('wheel', lockScrollDuringInteraction);
97
- container.addEventListener('touchmove', lockScrollDuringInteraction);
98
- return () => {
99
- container.removeEventListener('touchmove', lockScrollDuringInteraction);
100
- container.removeEventListener('wheel', lockScrollDuringInteraction);
101
- if (openSetStateLockTimeoutRef.current) {
102
- clearTimeout(openSetStateLockTimeoutRef.current);
103
- }
104
- };
105
- }, [root]);
106
98
  useEffect(() => {
107
99
  // update hasBeenVisibleRef to include the range of cards that should be visible
108
100
  const start = currentIndex * initiallyShownCards;
@@ -111,15 +103,6 @@ const BpkCardListCarousel = props => {
111
103
  hasBeenVisibleRef.current.add(i);
112
104
  }
113
105
  }, [currentIndex, initiallyShownCards, childrenLength, dynamicRenderBufferSize]);
114
- useEffect(() => {
115
- const firstVisible = visibilityList.indexOf(1);
116
- if (firstVisible >= 0) {
117
- const newIndex = Math.floor(firstVisible / initiallyShownCards);
118
- if (newIndex !== currentIndex) {
119
- setCurrentIndex(newIndex);
120
- }
121
- }
122
- }, [initiallyShownCards]);
123
106
  useEffect(() => {
124
107
  const handleResize = throttle(() => {
125
108
  firstCardWidthRef.current = null;
@@ -149,8 +132,9 @@ const BpkCardListCarousel = props => {
149
132
  if (firstCardHeightRef.current) {
150
133
  cardDimensionStyle.height = `${firstCardHeightRef.current}px`;
151
134
  }
135
+ const isPageStart = index % initiallyShownCards === 0;
152
136
  const commonProps = {
153
- className: getClassName(`bpk-card-list-row-rail__${layout}__card`),
137
+ className: getClassName(`bpk-card-list-row-rail__${layout}__card`, isPageStart && 'bpk-card-list-row-rail__card--page-start'),
154
138
  style: shownNumberStyle,
155
139
  key: `carousel-card-${index.toString()}`,
156
140
  role: 'group'
@@ -161,6 +145,7 @@ const BpkCardListCarousel = props => {
161
145
  if (!shouldRenderCard) {
162
146
  return /*#__PURE__*/_jsx("div", {
163
147
  ...commonProps,
148
+ ref: cardRefFns[index],
164
149
  style: {
165
150
  ...commonProps.style,
166
151
  ...cardDimensionStyle,
@@ -15,4 +15,4 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- .bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 0.5rem;--carousel-card-gap: 1.25rem;display:flex;overflow-x:hidden;box-sizing:border-box;gap:var(--carousel-card-gap);margin-block:-1.5rem;margin-inline:-0.5rem;padding-block:1.5rem;padding-inline:.5rem;scroll-snap-stop:always;scroll-snap-type:x mandatory;scrollbar-width:none}@media(max-width: 32rem){.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 1rem;--carousel-card-gap: 1rem;overflow-x:scroll}}.bpk-card-list-row-rail__row::-webkit-scrollbar,.bpk-card-list-row-rail__rail::-webkit-scrollbar{display:none}.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{position:relative;flex:0 0 calc((100% - (var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1) + var(--spacing-offset)*2/var(--initially-shown-cards, 3)))/var(--initially-shown-cards, 3));overflow:visible;box-sizing:border-box;scroll-margin-inline:var(--spacing-offset);scroll-snap-align:start}@media(max-width: 32rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{flex:0 0 calc((100% - var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1))/max(1,var(--initially-shown-cards, 3) - .8))}}.bpk-card-list-row-rail__rail{-webkit-overflow-scrolling:touch}@media(max-width: 32rem){.bpk-card-list-row-rail__rail{margin-inline:calc(-1*var(--spacing-offset));padding-inline:var(--spacing-offset)}}.bpk-card-list-row-rail__card-slot{display:grid;height:100%}
18
+ .bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 0.5rem;--carousel-card-gap: 1.25rem;display:flex;overflow-x:scroll;box-sizing:border-box;gap:var(--carousel-card-gap);margin-block:-1.5rem;margin-inline:-0.5rem;-webkit-overflow-scrolling:touch;padding-block:1.5rem;padding-inline:.5rem;scroll-snap-type:x mandatory;scrollbar-width:none}@media(max-width: 32rem){.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{--spacing-offset: 1rem;--carousel-card-gap: 1rem;overflow-x:scroll}}.bpk-card-list-row-rail__row::-webkit-scrollbar,.bpk-card-list-row-rail__rail::-webkit-scrollbar{display:none}.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{position:relative;flex:0 0 calc((100% - (var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1) + var(--spacing-offset)*2/var(--initially-shown-cards, 3)))/var(--initially-shown-cards, 3));overflow:visible;box-sizing:border-box;scroll-margin-inline:var(--spacing-offset);scroll-snap-align:start}@media(min-width: 32.0625rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{scroll-snap-align:none}}@media(max-width: 32rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{flex:0 0 calc((100% - var(--carousel-card-gap)*(var(--initially-shown-cards, 3) - 1))/max(1,var(--initially-shown-cards, 3) - .8))}}@media(min-width: 32.0625rem){.bpk-card-list-row-rail__card--page-start{scroll-snap-align:start;scroll-snap-stop:always}}.bpk-card-list-row-rail__rail{-webkit-overflow-scrolling:touch}@media(max-width: 32rem){.bpk-card-list-row-rail__rail{margin-inline:calc(-1*var(--spacing-offset));padding-inline:var(--spacing-offset)}}.bpk-card-list-row-rail__card-slot{display:grid;height:100%}
@@ -28,6 +28,7 @@ const BpkCardListRowRailContainer = props => {
28
28
  accessibilityLabels,
29
29
  accessory,
30
30
  children,
31
+ initiallyInViewCardIndex,
31
32
  initiallyShownCards,
32
33
  isMobile = false,
33
34
  layout
@@ -35,7 +36,18 @@ const BpkCardListRowRailContainer = props => {
35
36
  const childrenCount = Children.count(children);
36
37
  const totalIndicators = Math.ceil(childrenCount / initiallyShownCards);
37
38
  const showAccessory = childrenCount > initiallyShownCards;
38
- const [currentIndex, setCurrentIndex] = useState(0);
39
+
40
+ // Calculate initial page from card index
41
+ const [initialPageIndex] = useState(() => {
42
+ if (initiallyInViewCardIndex < 0) {
43
+ return 0;
44
+ }
45
+ if (initiallyInViewCardIndex >= childrenCount) {
46
+ return Math.max(0, totalIndicators - 1);
47
+ }
48
+ return Math.floor(initiallyInViewCardIndex / initiallyShownCards);
49
+ });
50
+ const [currentIndex, setCurrentIndex] = useState(initialPageIndex);
39
51
  const accessoryContent = layout === LAYOUTS.row && accessory === ACCESSORY_DESKTOP_TYPES.pagination ? /*#__PURE__*/_jsx(BpkPageIndicator, {
40
52
  currentIndex: currentIndex,
41
53
  totalIndicators: totalIndicators,
@@ -57,6 +69,7 @@ const BpkCardListRowRailContainer = props => {
57
69
  isMobile: isMobile,
58
70
  carouselLabel: accessibilityLabels?.carouselLabel,
59
71
  slideLabel: accessibilityLabels?.slideLabel,
72
+ initialPageIndex: initialPageIndex,
60
73
  children: children
61
74
  }), accessoryContent && showAccessory && /*#__PURE__*/_jsx("div", {
62
75
  role: "region",
@@ -1,2 +1,2 @@
1
- export declare const RELEASE_LOCK_DELAY = 20;
1
+ export declare const RELEASE_LOCK_DELAY = 200;
2
2
  export declare const RENDER_BUFFER_SIZE = 3;
@@ -16,5 +16,5 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- export const RELEASE_LOCK_DELAY = 20;
19
+ export const RELEASE_LOCK_DELAY = 200;
20
20
  export const RENDER_BUFFER_SIZE = 3;
@@ -1,9 +1,4 @@
1
- /**
2
- * Typically used to prevent useScrollToCard() from being called, to prevent scrollings caused by state changes, so as to avoid cyclic dependencies.
3
- * @param stateScrollingLockRef - Ref to the state that indicates if scrollIntoView should be locked
4
- * @param openSetStateLockTimeoutRef - Ref to the timeout that releases the lock after a delay. Should be renewed every time another scroll action is triggered, with a new lock is added.
5
- */
6
- export declare const lockScroll: (stateScrollingLockRef: React.MutableRefObject<boolean>, openSetStateLockTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>) => void;
1
+ import type { Dispatch, SetStateAction, RefObject } from 'react';
7
2
  /**
8
3
  * Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
9
4
  * For example, if there is a button inside a card which is not shown, it cannot be focused as well.
@@ -11,5 +6,27 @@ export declare const lockScroll: (stateScrollingLockRef: React.MutableRefObject<
11
6
  * @param index - Current container index
12
7
  */
13
8
  export declare const setA11yTabIndex: (el: HTMLDivElement | null, index: number, visibilityList: number[]) => void;
14
- export declare const useScrollToCard: (currentIndex: number, container: HTMLElement | null, cardRefs: React.MutableRefObject<Array<HTMLDivElement | null>>, stateScrollingLockRef: React.MutableRefObject<boolean>) => void;
15
- export declare const useIntersectionObserver: ({ root, threshold }: IntersectionObserverInit, setVisibilityList: React.Dispatch<React.SetStateAction<number[]>>) => (element: HTMLElement | null, index: number) => void;
9
+ export declare const useIntersectionObserver: ({ root, threshold }: IntersectionObserverInit, setVisibilityList: Dispatch<SetStateAction<number[]>>) => (element: HTMLElement | null, index: number) => void;
10
+ type UsePageScrollSyncOptions = {
11
+ currentIndex: number;
12
+ setCurrentIndex: Dispatch<SetStateAction<number>>;
13
+ initiallyShownCards: number;
14
+ cardRefs: RefObject<Array<HTMLDivElement | null>>;
15
+ visibilityList: number[];
16
+ container: HTMLElement | null;
17
+ enabled: boolean;
18
+ initialPageIndex: number;
19
+ };
20
+ /**
21
+ * Provides bidirectional synchronisation between page index state and scroll position.
22
+ *
23
+ * - **State → Scroll**: When `currentIndex` changes (e.g. via pagination buttons),
24
+ * the container scrolls to bring the corresponding page into view.
25
+ * - **Scroll → State**: When the user scrolls (via wheel or touch), `currentIndex`
26
+ * is updated to reflect the first visible page.
27
+ *
28
+ * The hook uses a lock mechanism to prevent conflicts between programmatic and
29
+ * user-initiated scrolling.
30
+ */
31
+ export declare const usePageScrollSync: ({ cardRefs, container, currentIndex, enabled, initialPageIndex, initiallyShownCards, setCurrentIndex, visibilityList, }: UsePageScrollSyncOptions) => void;
32
+ export {};
@@ -19,25 +19,6 @@
19
19
  import { useEffect, useRef } from 'react';
20
20
  import { RELEASE_LOCK_DELAY } from "./constants";
21
21
 
22
- /**
23
- * Typically used to prevent useScrollToCard() from being called, to prevent scrollings caused by state changes, so as to avoid cyclic dependencies.
24
- * @param stateScrollingLockRef - Ref to the state that indicates if scrollIntoView should be locked
25
- * @param openSetStateLockTimeoutRef - Ref to the timeout that releases the lock after a delay. Should be renewed every time another scroll action is triggered, with a new lock is added.
26
- */
27
-
28
- export const lockScroll = (stateScrollingLockRef, openSetStateLockTimeoutRef) => {
29
- // eslint-disable-next-line no-param-reassign
30
- stateScrollingLockRef.current = true;
31
- if (openSetStateLockTimeoutRef.current) {
32
- clearTimeout(openSetStateLockTimeoutRef.current);
33
- }
34
- // eslint-disable-next-line no-param-reassign
35
- openSetStateLockTimeoutRef.current = setTimeout(() => {
36
- // eslint-disable-next-line no-param-reassign
37
- stateScrollingLockRef.current = false;
38
- }, RELEASE_LOCK_DELAY);
39
- };
40
-
41
22
  /**
42
23
  * Only sets the tabIndex of focusable elements as 0 if the card is visible, otherwise sets it to -1, including all its children.
43
24
  * For example, if there is a button inside a card which is not shown, it cannot be focused as well.
@@ -53,22 +34,6 @@ export const setA11yTabIndex = (el, index, visibilityList) => {
53
34
  targetElement.tabIndex = visibilityList[index] === 1 ? 0 : -1;
54
35
  });
55
36
  };
56
- export const useScrollToCard = (currentIndex, container, cardRefs, stateScrollingLockRef) => {
57
- useEffect(() => {
58
- const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
59
- if (!isVisible) return; // Escape from scrollIntoView if the container is not visible, otherwise the webpage will scroll down to the last rendered & non-visible container
60
-
61
- if (stateScrollingLockRef.current && stateScrollingLockRef.current === true) return;
62
- const targetCard = cardRefs.current[currentIndex];
63
- if (targetCard) {
64
- targetCard.scrollIntoView({
65
- behavior: 'smooth',
66
- block: 'nearest',
67
- inline: 'start'
68
- });
69
- }
70
- }, [currentIndex]);
71
- };
72
37
  export const useIntersectionObserver = ({
73
38
  root,
74
39
  threshold
@@ -115,4 +80,122 @@ export const useIntersectionObserver = ({
115
80
  }
116
81
  };
117
82
  return observeElement;
83
+ };
84
+ /**
85
+ * Provides bidirectional synchronisation between page index state and scroll position.
86
+ *
87
+ * - **State → Scroll**: When `currentIndex` changes (e.g. via pagination buttons),
88
+ * the container scrolls to bring the corresponding page into view.
89
+ * - **Scroll → State**: When the user scrolls (via wheel or touch), `currentIndex`
90
+ * is updated to reflect the first visible page.
91
+ *
92
+ * The hook uses a lock mechanism to prevent conflicts between programmatic and
93
+ * user-initiated scrolling.
94
+ */
95
+
96
+ export const usePageScrollSync = ({
97
+ cardRefs,
98
+ container,
99
+ currentIndex,
100
+ enabled,
101
+ initialPageIndex,
102
+ initiallyShownCards,
103
+ setCurrentIndex,
104
+ visibilityList
105
+ }) => {
106
+ const isUserScrollingRef = useRef(false);
107
+ const scrollEndTimeoutRef = useRef(null);
108
+ const lastCurrentIndexRef = useRef(currentIndex);
109
+ const hasInitialScrolled = useRef(false);
110
+
111
+ // Effect 0: Initial scroll (instant, runs once on mount)
112
+ useEffect(() => {
113
+ if (hasInitialScrolled.current) {
114
+ return;
115
+ }
116
+ hasInitialScrolled.current = true;
117
+ if (!enabled || initialPageIndex === 0) {
118
+ return;
119
+ }
120
+ const targetCard = cardRefs.current?.[initialPageIndex * initiallyShownCards];
121
+ if (targetCard) {
122
+ targetCard.scrollIntoView({
123
+ behavior: 'instant',
124
+ block: 'nearest',
125
+ inline: 'start'
126
+ });
127
+ }
128
+ }, [cardRefs, enabled, initialPageIndex, initiallyShownCards]); // Run once on mount only
129
+
130
+ // Effect 1: Programmatic scroll when currentIndex changes
131
+ useEffect(() => {
132
+ if (!enabled ||
133
+ // Avoid triggering programmatic scroll when currentIndex changes due to user scroll
134
+ isUserScrollingRef.current || lastCurrentIndexRef.current === currentIndex) {
135
+ return;
136
+ }
137
+ lastCurrentIndexRef.current = currentIndex;
138
+ const isVisible = container && container.getBoundingClientRect().bottom > 0 && container.getBoundingClientRect().bottom <= window.innerHeight;
139
+ if (!isVisible) {
140
+ return;
141
+ }
142
+ const targetCard = cardRefs.current?.[currentIndex * initiallyShownCards];
143
+ if (targetCard) {
144
+ targetCard.scrollIntoView({
145
+ behavior: 'smooth',
146
+ block: 'nearest',
147
+ inline: 'start'
148
+ });
149
+ }
150
+ }, [currentIndex, enabled, container, initiallyShownCards, cardRefs]);
151
+
152
+ // Effect 2: Scroll detection and silence-based lock release
153
+ useEffect(() => {
154
+ if (!enabled || !container) return undefined;
155
+ const handleScrollActivity = e => {
156
+ // Set flag only for user input events, not scroll events
157
+ if (e.type === 'wheel' || e.type === 'touchstart') {
158
+ isUserScrollingRef.current = true;
159
+ }
160
+
161
+ // Reset silence timer on every scroll-related event
162
+ if (scrollEndTimeoutRef.current) {
163
+ clearTimeout(scrollEndTimeoutRef.current);
164
+ }
165
+
166
+ // Release lock after scroll silence
167
+ scrollEndTimeoutRef.current = setTimeout(() => {
168
+ isUserScrollingRef.current = false;
169
+ }, RELEASE_LOCK_DELAY);
170
+ };
171
+ container.addEventListener('scroll', handleScrollActivity, {
172
+ passive: true
173
+ });
174
+ container.addEventListener('wheel', handleScrollActivity, {
175
+ passive: true
176
+ });
177
+ container.addEventListener('touchstart', handleScrollActivity, {
178
+ passive: true
179
+ });
180
+ return () => {
181
+ container.removeEventListener('scroll', handleScrollActivity);
182
+ container.removeEventListener('wheel', handleScrollActivity);
183
+ container.removeEventListener('touchstart', handleScrollActivity);
184
+ if (scrollEndTimeoutRef.current) {
185
+ clearTimeout(scrollEndTimeoutRef.current);
186
+ }
187
+ };
188
+ }, [enabled, container]);
189
+
190
+ // Effect 3: Update currentIndex from visibility during user scroll
191
+ useEffect(() => {
192
+ if (!enabled || !isUserScrollingRef.current) return;
193
+ const firstVisibleIndex = visibilityList.indexOf(1);
194
+ if (firstVisibleIndex === -1) return;
195
+ const newPageIndex = Math.floor(firstVisibleIndex / initiallyShownCards);
196
+ if (newPageIndex !== currentIndex) {
197
+ setCurrentIndex(newPageIndex);
198
+ lastCurrentIndexRef.current = newPageIndex;
199
+ }
200
+ }, [visibilityList, enabled, initiallyShownCards, currentIndex, setCurrentIndex]);
118
201
  };
@@ -36,6 +36,7 @@ type CardListBaseProps = {
36
36
  accessoryMobile?: (typeof ACCESSORY_MOBILE_TYPES)[keyof typeof ACCESSORY_MOBILE_TYPES];
37
37
  initiallyShownCardsDesktop?: number;
38
38
  initiallyShownCardsMobile?: number;
39
+ initiallyInViewCardIndex?: number;
39
40
  chipGroup?: ReactElement;
40
41
  buttonContent?: React.ReactNode;
41
42
  onButtonClick?: () => void;
@@ -69,6 +70,7 @@ type CardListRowRailProps = {
69
70
  accessory?: typeof ACCESSORY_DESKTOP_TYPES.pagination;
70
71
  isMobile?: boolean;
71
72
  accessibilityLabels?: AccessibilityLabels;
73
+ initiallyInViewCardIndex: number;
72
74
  };
73
75
  type CardListCarouselProps = {
74
76
  children: Array<ReactElement<HTMLDivElement | HTMLAnchorElement>>;
@@ -79,6 +81,7 @@ type CardListCarouselProps = {
79
81
  isMobile?: boolean;
80
82
  carouselLabel?: (initiallyShownCards: number, childrenLength: number) => string;
81
83
  slideLabel?: (index: number, childrenLength: number) => string;
84
+ initialPageIndex: number;
82
85
  };
83
86
  type CardListProps = CardListBaseProps;
84
87
  export default CardListProps;
@@ -15,4 +15,4 @@
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */
18
- .bpk-content-card--link{color:inherit;font:inherit;text-decoration:inherit}.bpk-content-card--horizontal{display:grid;column-gap:2.5rem;grid-template-columns:minmax(10%, 38.75rem) 40%;align-items:center}@media(max-width: 32rem){.bpk-content-card--horizontal{grid-template-columns:1fr}}.bpk-content-card--horizontal .bpk-content-card--image-container{width:100%;height:26.25rem}@media(max-width: 32rem){.bpk-content-card--horizontal .bpk-content-card--image-container{max-height:11.25rem;margin-bottom:1rem}}@media(max-width: 64rem){.bpk-content-card--horizontal .bpk-content-card--image-container{height:100%}}.bpk-content-card--vertical .bpk-content-card--image{height:28.75rem;margin-bottom:1rem}@media(max-width: 48rem){.bpk-content-card--vertical .bpk-content-card--image{width:100%;height:auto;max-height:16.25rem}}@media(max-width: 32rem){.bpk-content-card--vertical .bpk-content-card--image{max-height:11.25rem}}.bpk-content-card--headline{margin-bottom:.25rem;font-size:1.25rem;line-height:1.5rem;font-weight:700}.bpk-content-card--description{color:#626971;font-size:1rem;line-height:1.5rem;font-weight:400}.bpk-content-card--image{width:100%;height:100%;border-radius:.75rem;object-fit:cover}
18
+ .bpk-content-card--link{position:relative;display:block;border-radius:.75rem;color:inherit;font:inherit;text-decoration:inherit}.bpk-content-card--link:focus{outline:.125rem solid #0062e3;outline-offset:.125rem}.bpk-content-card--horizontal{display:grid;column-gap:2.5rem;grid-template-columns:minmax(10%, 38.75rem) 40%;align-items:center}@media(max-width: 32rem){.bpk-content-card--horizontal{grid-template-columns:1fr}}.bpk-content-card--horizontal .bpk-content-card--image-container{width:100%;height:26.25rem}@media(max-width: 32rem){.bpk-content-card--horizontal .bpk-content-card--image-container{max-height:11.25rem;margin-bottom:1rem}}@media(max-width: 64rem){.bpk-content-card--horizontal .bpk-content-card--image-container{height:100%}}.bpk-content-card--vertical .bpk-content-card--image{height:28.75rem;margin-bottom:1rem}@media(max-width: 48rem){.bpk-content-card--vertical .bpk-content-card--image{width:100%;height:auto;max-height:16.25rem}}@media(max-width: 32rem){.bpk-content-card--vertical .bpk-content-card--image{max-height:11.25rem}}.bpk-content-card--headline{margin-bottom:.25rem;font-size:1.25rem;line-height:1.5rem;font-weight:700}.bpk-content-card--description{color:#626971;font-size:1rem;line-height:1.5rem;font-weight:400}.bpk-content-card--image{width:100%;height:100%;border-radius:.75rem;object-fit:cover}
@@ -15,6 +15,12 @@ export type WithOpenEventsProps = {
15
15
  */
16
16
  onOpen?: () => void;
17
17
  hasTouchSupport?: boolean;
18
+ /**
19
+ * @deprecated Use inputMode="none" instead. readOnly will be removed in a future version.
20
+ * Previously used to prevent the mobile keyboard from opening, but this caused a WCAG 1.3.1
21
+ * violation due to conflicting readonly + aria-readonly attributes.
22
+ */
23
+ readOnly?: boolean | string;
18
24
  };
19
25
  type EventHandlers = {
20
26
  onClick?: (event: UIEvent) => void;
@@ -23,10 +29,11 @@ type EventHandlers = {
23
29
  onTouchEnd?: (event: UIEvent) => void;
24
30
  onKeyDown?: (event: UIEvent) => void;
25
31
  onKeyUp?: (event: UIEvent) => void;
32
+ inputMode?: 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
26
33
  readOnly?: string;
27
34
  'aria-readonly'?: boolean;
28
35
  };
29
- type InputProps = ComponentProps<'input'> & Omit<EventHandlers, 'readOnly' | 'aria-readonly'>;
36
+ type InputProps = ComponentProps<'input'> & Omit<EventHandlers, 'inputMode' | 'readOnly' | 'aria-readonly'>;
30
37
  declare const withOpenEvents: <P extends object>(WithOpenEventsInputComponent: ComponentType<P>) => {
31
38
  new (props: P & WithOpenEventsProps & InputProps): {
32
39
  focusCanOpen: boolean;
@@ -35,25 +42,25 @@ declare const withOpenEvents: <P extends object>(WithOpenEventsInputComponent: C
35
42
  handleBlur: () => void;
36
43
  render(): ReactElement;
37
44
  context: unknown;
38
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
45
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
39
46
  forceUpdate(callback?: (() => void) | undefined): void;
40
- readonly props: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>;
47
+ readonly props: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>;
41
48
  state: Readonly<{}>;
42
49
  refs: {
43
50
  [key: string]: import("react").ReactInstance;
44
51
  };
45
52
  componentDidMount?(): void;
46
- shouldComponentUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): boolean;
53
+ shouldComponentUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): boolean;
47
54
  componentWillUnmount?(): void;
48
55
  componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
49
- getSnapshotBeforeUpdate?(prevProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, prevState: Readonly<{}>): any;
50
- componentDidUpdate?(prevProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, prevState: Readonly<{}>, snapshot?: any): void;
56
+ getSnapshotBeforeUpdate?(prevProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, prevState: Readonly<{}>): any;
57
+ componentDidUpdate?(prevProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, prevState: Readonly<{}>, snapshot?: any): void;
51
58
  componentWillMount?(): void;
52
59
  UNSAFE_componentWillMount?(): void;
53
- componentWillReceiveProps?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextContext: any): void;
54
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextContext: any): void;
55
- componentWillUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): void;
56
- UNSAFE_componentWillUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): void;
60
+ componentWillReceiveProps?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextContext: any): void;
61
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextContext: any): void;
62
+ componentWillUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): void;
63
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<P & import("react").ClassAttributes<HTMLInputElement> & import("react").InputHTMLAttributes<HTMLInputElement> & Omit<EventHandlers, "inputMode" | "aria-readonly" | "readOnly"> & WithOpenEventsProps>, nextState: Readonly<{}>, nextContext: any): void;
57
64
  };
58
65
  displayName: string;
59
66
  defaultProps: {
@@ -96,8 +96,12 @@ const withOpenEvents = WithOpenEventsInputComponent => {
96
96
  onKeyUp,
97
97
  onOpen,
98
98
  onTouchEnd,
99
+ readOnly,
99
100
  ...rest
100
101
  } = this.props;
102
+ if (readOnly !== undefined) {
103
+ console.warn('withOpenEvents: The readOnly prop is deprecated and will be removed in a future version. ' + 'The component now uses inputMode="none" to prevent mobile keyboards from opening, ' + 'which avoids WCAG 1.3.1 violations from conflicting readonly + aria-readonly attributes.');
104
+ }
101
105
  const eventHandlers = {
102
106
  onClick: withEventHandler(onOpen, onClick),
103
107
  // @ts-expect-error for some reason the type KeyboardEvent was not being recognized as
@@ -105,9 +109,15 @@ const withOpenEvents = WithOpenEventsInputComponent => {
105
109
  onKeyDown: withEventHandler(handleKeyEvent(onOpen), onKeyDown)
106
110
  };
107
111
  if (hasTouchSupport) {
108
- // Prevents the mobile keyboard from opening (iOS / Android), while not announcing it as 'read only' to a screen reader
109
- eventHandlers.readOnly = 'readOnly';
110
- eventHandlers['aria-readonly'] = false;
112
+ if (readOnly !== undefined) {
113
+ // Deprecated: prevents the mobile keyboard from opening (iOS / Android), while not announcing it as 'read only' to a screen reader
114
+ eventHandlers.readOnly = 'readOnly';
115
+ eventHandlers['aria-readonly'] = false;
116
+ } else {
117
+ // Prevents the mobile keyboard from opening (iOS / Android) using inputMode="none"
118
+ // This avoids WCAG 1.3.1 violation from conflicting readonly + aria-readonly attributes
119
+ eventHandlers.inputMode = 'none';
120
+ }
111
121
  eventHandlers.onTouchEnd = withEventHandler(this.handleTouchEnd, onTouchEnd);
112
122
  }
113
123
 
@@ -110,7 +110,7 @@ const BpkNudger = ({
110
110
  inputRef.current && setNativeValue(inputRef.current, newValue);
111
111
  },
112
112
  disabled: minButtonDisabled,
113
- title: decreaseButtonLabel,
113
+ "aria-label": decreaseButtonLabel,
114
114
  "aria-controls": id,
115
115
  children: /*#__PURE__*/_jsx(AlignedMinusIcon, {})
116
116
  }), /*#__PURE__*/_jsx("input", {
@@ -151,7 +151,7 @@ const BpkNudger = ({
151
151
  inputRef.current && setNativeValue(inputRef.current, newValue);
152
152
  },
153
153
  disabled: maxButtonDisabled,
154
- title: increaseButtonLabel,
154
+ "aria-label": increaseButtonLabel,
155
155
  "aria-controls": id,
156
156
  children: /*#__PURE__*/_jsx(AlignedPlusIcon, {})
157
157
  })]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "41.12.0",
3
+ "version": "41.14.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",