@enact/ui 5.5.0 → 5.5.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  The following is a curated list of changes in the Enact ui module, newest changes on the top.
4
4
 
5
+ ## [5.5.1] - 2026-06-01
6
+
7
+ ### Changed
8
+
9
+ - `ui/VirtualList.VirtualListBasic` scroll animation method for `scrollMode: native`
10
+
11
+ ### Fixed
12
+
13
+ - `ui/Scroller` jumping back when scrolled by long press
14
+ - `ui/VirtualList` overscroll effect at the bottom of the list
15
+ - `ui/VirtualList.VirtualList` overscroll effect at the bottom of the list
16
+ - `ui/VirtualList.VirtualGridList` overscroll effect at the bottom of the list
17
+
18
+ ## [5.4.4] - 2026-05-22
19
+
20
+ ### Fixed
21
+
22
+ - `ui/Scroller` jumping back when scrolled by long press
23
+
5
24
  ## [5.5.0] - 2026-05-08
6
25
 
7
26
  ### Added
@@ -26,8 +26,8 @@ export class ScrollerBasic extends React.Component<
26
26
  /**
27
27
  * Programmatically animates the native scroll position of `node` toward the target `left` / `top`
28
28
  offsets using `requestAnimationFrame` . It computes the scroll direction on each axis, then repeatedly
29
- calls `scrollBy` in small 18px steps (instant behavior) until the target is reached or a scroll bound
30
- is hit. Used as a Chrome fallback when repeating a smooth scroll.
29
+ calls `scrollBy` with a dynamic step (10% of remaining distance, minimum 8px) until the target is reached
30
+ or 1s has elapsed. Used as a Chrome fallback when repeating a smooth scroll.
31
31
  */
32
32
  animateScroll(any, any, any): void;
33
33
  }
@@ -151,6 +151,10 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
151
151
  if (_platform.platform.chrome && smoothBehavior && repeat) {
152
152
  this.animateScroll(this.getRtlPositionX(left), top, node);
153
153
  } else {
154
+ if (this.scrollAnimationId) {
155
+ window.cancelAnimationFrame(this.scrollAnimationId);
156
+ this.scrollAnimationId = null;
157
+ }
154
158
  node.scrollTo({
155
159
  left: this.getRtlPositionX(left),
156
160
  top: top,
@@ -162,8 +166,8 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
162
166
  /**
163
167
  * Programmatically animates the native scroll position of `node` toward the target `left`/`top`
164
168
  * offsets using `requestAnimationFrame`. It computes the scroll direction on each axis, then repeatedly
165
- * calls `scrollBy` in small 18px steps (instant behavior) until the target is reached or a scroll bound
166
- * is hit. Used as a Chrome fallback when repeating a smooth scroll.
169
+ * calls `scrollBy` with a dynamic step (10% of remaining distance, minimum 8px) until the target is reached
170
+ * or 1s has elapsed. Used as a Chrome fallback when repeating a smooth scroll.
167
171
  */
168
172
  }, {
169
173
  key: "animateScroll",
@@ -171,23 +175,32 @@ var ScrollerBasic = exports.ScrollerBasic = /*#__PURE__*/function (_Component) {
171
175
  var _this3 = this;
172
176
  var directionX = Math.sign(left - node.scrollLeft);
173
177
  var directionY = Math.sign(top - node.scrollTop);
174
- var _animateScroll = function animateScroll() {
178
+ var startTime = performance.now();
179
+ var _animateScroll = function animateScroll(currentTime) {
180
+ var elapsed = (currentTime - startTime) / 1000;
175
181
  var scrollLeft = directionX > 0 ? node.scrollLeft < left : node.scrollLeft > left;
176
182
  var scrollTop = directionY > 0 ? node.scrollTop < top : node.scrollTop > top;
177
183
 
178
- // Check if we reached the scroll bounds and cancel the animation
179
- if (top > _this3.scrollBounds.maxTop && node.scrollTop === _this3.scrollBounds.maxTop || left > _this3.scrollBounds.maxLeft && node.scrollLeft === _this3.scrollBounds.maxLeft || top < 0 && node.scrollTop === 0 || left < 0 && node.scrollLeft === 0) {
180
- window.cancelAnimationFrame(_this3.scrollAnimationId);
184
+ // Stop animating if the target is reached or 1s has elapsed since animation started
185
+ if (!scrollTop && !scrollLeft || elapsed > 1) {
186
+ // Fallback: if timed out before reaching target, jump there with smooth scroll
187
+ if (elapsed > 1 && (node.scrollLeft !== left || node.scrollTop !== top)) {
188
+ node.scrollTo({
189
+ top: top,
190
+ left: left,
191
+ behavior: 'smooth'
192
+ });
193
+ }
181
194
  return;
182
195
  }
183
- if (scrollTop || scrollLeft) {
184
- node.scrollBy({
185
- top: directionY * 8,
186
- left: directionX * 8,
187
- behavior: 'instant'
188
- });
189
- _this3.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
190
- }
196
+ var horizontalScrollFactor = Math.max(Math.abs(left - node.scrollLeft) * 0.1, 8);
197
+ var verticalScrollFactor = Math.max(Math.abs(top - node.scrollTop) * 0.1, 8);
198
+ node.scrollBy({
199
+ top: directionY * verticalScrollFactor,
200
+ left: directionX * horizontalScrollFactor,
201
+ behavior: 'instant'
202
+ });
203
+ _this3.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
191
204
  };
192
205
  this.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
193
206
  }
@@ -2,6 +2,14 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _Scroller = require("../Scroller");
5
+ var mockPlatform = {};
6
+ jest.mock('@enact/core/platform', function () {
7
+ return {
8
+ get platform() {
9
+ return mockPlatform;
10
+ }
11
+ };
12
+ });
5
13
  describe('ScrollBasic', function () {
6
14
  var scrollContentRef;
7
15
  beforeEach(function () {
@@ -18,7 +26,7 @@ describe('ScrollBasic', function () {
18
26
  afterEach(function () {
19
27
  jest.clearAllMocks();
20
28
  });
21
- test('should call scrollBy on scrollToPosition', function () {
29
+ test('should call scrollTo on scrollToPosition', function () {
22
30
  var instance = new _Scroller.ScrollerBasic({
23
31
  scrollContentRef: scrollContentRef,
24
32
  direction: 'both'
@@ -36,24 +44,189 @@ describe('ScrollBasic', function () {
36
44
  behavior: 'instant'
37
45
  });
38
46
  });
39
- test('should call scrollBy with animated values during animateScroll', function () {
40
- var rafCallback;
47
+ test('should cancel pending animation before calling scrollTo on scrollToPosition', function () {
41
48
  var instance = new _Scroller.ScrollerBasic({
42
49
  scrollContentRef: scrollContentRef,
43
50
  direction: 'both'
44
51
  });
45
- instance.scrollBounds.maxTop = 500;
46
- instance.scrollBounds.maxLeft = 500;
47
- window.requestAnimationFrame = jest.fn(function (cb) {
48
- rafCallback = cb;
52
+ var mockAnimationId = 42;
53
+ instance.scrollAnimationId = mockAnimationId;
54
+ window.cancelAnimationFrame = jest.fn();
55
+ instance.scrollToPosition(100, 200, 'instant');
56
+ expect(window.cancelAnimationFrame).toHaveBeenCalledWith(mockAnimationId);
57
+ expect(instance.scrollAnimationId).toBeNull();
58
+ expect(scrollContentRef.current.scrollTo).toHaveBeenCalledWith({
59
+ left: 100,
60
+ top: 200,
61
+ behavior: 'instant'
49
62
  });
63
+ });
64
+ test('should not call cancelAnimationFrame when scrollAnimationId is null on scrollToPosition', function () {
65
+ var instance = new _Scroller.ScrollerBasic({
66
+ scrollContentRef: scrollContentRef,
67
+ direction: 'both'
68
+ });
69
+ instance.scrollAnimationId = null;
50
70
  window.cancelAnimationFrame = jest.fn();
51
- instance.animateScroll(100, 200, scrollContentRef.current);
52
- rafCallback();
53
- expect(scrollContentRef.current.scrollBy).toHaveBeenCalled();
54
- scrollContentRef.current.scrollTop = 500;
55
- instance.animateScroll(550, 550, scrollContentRef.current);
56
- rafCallback();
57
- expect(window.cancelAnimationFrame).toHaveBeenCalled();
71
+ instance.scrollToPosition(100, 200, 'instant');
72
+ expect(window.cancelAnimationFrame).not.toHaveBeenCalled();
73
+ });
74
+ test('should call animateScroll instead of scrollTo when platform is Chrome, behavior is smooth, and repeat is true', function () {
75
+ mockPlatform.chrome = 132;
76
+ var instance = new _Scroller.ScrollerBasic({
77
+ scrollContentRef: scrollContentRef,
78
+ direction: 'both'
79
+ });
80
+ instance.animateScroll = jest.fn();
81
+ instance.scrollToPosition(100, 200, 'smooth', true);
82
+ expect(instance.animateScroll).toHaveBeenCalledWith(100, 200, scrollContentRef.current);
83
+ expect(scrollContentRef.current.scrollTo).not.toHaveBeenCalled();
84
+ delete mockPlatform.chrome;
85
+ });
86
+ describe('animateScroll', function () {
87
+ var rafCallbacks;
88
+ var rafIdCounter;
89
+ var nowValue;
90
+ beforeEach(function () {
91
+ rafCallbacks = [];
92
+ rafIdCounter = 1;
93
+ nowValue = 0;
94
+ window.requestAnimationFrame = jest.fn(function (cb) {
95
+ var id = rafIdCounter++;
96
+ rafCallbacks.push({
97
+ id: id,
98
+ cb: cb
99
+ });
100
+ return id;
101
+ });
102
+ window.cancelAnimationFrame = jest.fn(function (id) {
103
+ rafCallbacks = rafCallbacks.filter(function (entry) {
104
+ return entry.id !== id;
105
+ });
106
+ });
107
+ jest.spyOn(performance, 'now').mockImplementation(function () {
108
+ return nowValue;
109
+ });
110
+ });
111
+ afterEach(function () {
112
+ jest.restoreAllMocks();
113
+ });
114
+ function flushRaf(time) {
115
+ nowValue = time;
116
+ var callbacks = rafCallbacks.splice(0);
117
+ callbacks.forEach(function (_ref) {
118
+ var cb = _ref.cb;
119
+ return cb(time);
120
+ });
121
+ }
122
+ test('should call scrollBy with a dynamic step (10% of remaining distance) during animateScroll', function () {
123
+ scrollContentRef.current.scrollLeft = 0;
124
+ scrollContentRef.current.scrollTop = 0;
125
+ var instance = new _Scroller.ScrollerBasic({
126
+ scrollContentRef: scrollContentRef,
127
+ direction: 'both'
128
+ });
129
+ var node = scrollContentRef.current;
130
+ instance.animateScroll(200, 100, node);
131
+
132
+ // First frame at t=0
133
+ flushRaf(0);
134
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
135
+ left: expect.closeTo(20, 1),
136
+ // 10% of 200
137
+ top: expect.closeTo(10, 1),
138
+ // 10% of 100
139
+ behavior: 'instant'
140
+ }));
141
+ });
142
+ test('should use minimum step of 8px when remaining distance is less than 80px', function () {
143
+ scrollContentRef.current.scrollLeft = 0;
144
+ scrollContentRef.current.scrollTop = 0;
145
+ var instance = new _Scroller.ScrollerBasic({
146
+ scrollContentRef: scrollContentRef,
147
+ direction: 'both'
148
+ });
149
+ var node = scrollContentRef.current;
150
+
151
+ // 50px remaining → 10% = 5px < 8px minimum
152
+ instance.animateScroll(50, 50, node);
153
+ flushRaf(0);
154
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
155
+ left: 8,
156
+ top: 8,
157
+ behavior: 'instant'
158
+ }));
159
+ });
160
+ test('should stop animating and not call scrollBy when target is already reached', function () {
161
+ scrollContentRef.current.scrollLeft = 100;
162
+ scrollContentRef.current.scrollTop = 200;
163
+ var instance = new _Scroller.ScrollerBasic({
164
+ scrollContentRef: scrollContentRef,
165
+ direction: 'both'
166
+ });
167
+ var node = scrollContentRef.current;
168
+
169
+ // Target equals current position → already reached
170
+ instance.animateScroll(100, 200, node);
171
+ flushRaf(0);
172
+ expect(node.scrollBy).not.toHaveBeenCalled();
173
+ expect(node.scrollTo).not.toHaveBeenCalled();
174
+ });
175
+ test('should stop animation and call scrollTo with smooth behavior when 1s timeout elapses before reaching target', function () {
176
+ scrollContentRef.current.scrollLeft = 0;
177
+ scrollContentRef.current.scrollTop = 0;
178
+ var instance = new _Scroller.ScrollerBasic({
179
+ scrollContentRef: scrollContentRef,
180
+ direction: 'both'
181
+ });
182
+ var node = scrollContentRef.current;
183
+ instance.animateScroll(500, 500, node);
184
+
185
+ // Advance past 1s timeout without updating scroll position
186
+ flushRaf(1100);
187
+ expect(node.scrollTo).toHaveBeenCalledWith({
188
+ top: 500,
189
+ left: 500,
190
+ behavior: 'smooth'
191
+ });
192
+ });
193
+ test('should not call scrollTo fallback when target is reached exactly at timeout boundary', function () {
194
+ scrollContentRef.current.scrollLeft = 500;
195
+ scrollContentRef.current.scrollTop = 500;
196
+ var instance = new _Scroller.ScrollerBasic({
197
+ scrollContentRef: scrollContentRef,
198
+ direction: 'both'
199
+ });
200
+ var node = scrollContentRef.current;
201
+
202
+ // Target already reached
203
+ instance.animateScroll(500, 500, node);
204
+ flushRaf(1100);
205
+ expect(node.scrollTo).not.toHaveBeenCalled();
206
+ });
207
+ test('should continue requesting animation frames until target is reached', function () {
208
+ scrollContentRef.current.scrollLeft = 0;
209
+ scrollContentRef.current.scrollTop = 0;
210
+ var instance = new _Scroller.ScrollerBasic({
211
+ scrollContentRef: scrollContentRef,
212
+ direction: 'both'
213
+ });
214
+ var node = scrollContentRef.current;
215
+ instance.animateScroll(100, 0, node);
216
+
217
+ // First frame: scrollBy called, new rAF registered
218
+ flushRaf(0);
219
+ expect(node.scrollBy).toHaveBeenCalledTimes(1);
220
+
221
+ // Simulate scroll progress
222
+ node.scrollLeft = 50;
223
+ flushRaf(100);
224
+ expect(node.scrollBy).toHaveBeenCalledTimes(2);
225
+
226
+ // Simulate reaching target
227
+ node.scrollLeft = 100;
228
+ flushRaf(200);
229
+ expect(node.scrollBy).toHaveBeenCalledTimes(2);
230
+ });
58
231
  });
59
232
  });
@@ -18,6 +18,7 @@ var _excluded = ["className", "containerProps", "placeholderRenderer", "role", "
18
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
19
19
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
20
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
21
+ function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
21
22
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
22
23
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
24
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -404,10 +405,15 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
404
405
  this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
405
406
  this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
406
407
  if (this.isPrimaryDirectionVertical) {
407
- this.scrollBounds.maxTop += this.itemMarginTop + this.itemMarginBottom;
408
+ var marginSum = this.itemMarginTop + this.itemMarginBottom;
409
+ this.scrollBounds.scrollHeight += marginSum;
410
+ this.scrollBounds.maxTop += marginSum;
408
411
  } else {
409
- this.scrollBounds.maxLeft += this.itemMarginLeft + this.itemMarginRight;
412
+ var _marginSum = this.itemMarginLeft + this.itemMarginRight;
413
+ this.scrollBounds.scrollWidth += _marginSum;
414
+ this.scrollBounds.maxLeft += _marginSum;
410
415
  }
416
+ this.setContainerSize();
411
417
  }
412
418
  var deferScrollTo = false;
413
419
  var _this$state = this.state,
@@ -782,8 +788,31 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
782
788
  value:
783
789
  // scrollMode 'native' only
784
790
  function scrollToPosition(left, top, behavior) {
785
- if (this.props.scrollContentRef.current && this.props.scrollContentRef.current.scrollTo) {
786
- this.props.scrollContentRef.current.scrollTo({
791
+ var _this$props3 = this.props,
792
+ dataSize = _this$props3.dataSize,
793
+ scrollContentRef = _this$props3.scrollContentRef;
794
+ var node = scrollContentRef.current;
795
+ if (!node) return;
796
+ var _this$scrollBounds3 = this.scrollBounds,
797
+ clientWidth = _this$scrollBounds3.clientWidth,
798
+ clientHeight = _this$scrollBounds3.clientHeight,
799
+ scrollWidth = _this$scrollBounds3.scrollWidth,
800
+ scrollHeight = _this$scrollBounds3.scrollHeight;
801
+ var _this$moreInfo = this.moreInfo,
802
+ firstVisibleIndex = _this$moreInfo.firstVisibleIndex,
803
+ lastVisibleIndex = _this$moreInfo.lastVisibleIndex;
804
+ var scrollSize = this.isPrimaryDirectionVertical ? top >= scrollHeight - clientHeight : left >= scrollWidth - clientWidth;
805
+ var isTargetStart = this.isPrimaryDirectionVertical ? top === 0 : left === 0;
806
+ var isScrollWrap = lastVisibleIndex === dataSize - 1 && isTargetStart || firstVisibleIndex === 0 && scrollSize;
807
+ var isScrollByPageKey = node.lastInputType === 'pageKey';
808
+ var isSmoothBehavior = behavior === 'smooth';
809
+ if (_platform.platform.chrome && isSmoothBehavior && !isScrollByPageKey && !isScrollWrap) {
810
+ this.animateScroll(this.getRtlPositionX(left), top, node);
811
+ } else if (node.scrollTo) {
812
+ if (this.scrollAnimationId) {
813
+ this.cancelScrollAnimation();
814
+ }
815
+ node.scrollTo({
787
816
  left: this.getRtlPositionX(left),
788
817
  top: top,
789
818
  behavior: behavior
@@ -791,6 +820,64 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
791
820
  }
792
821
  }
793
822
 
823
+ // scroll mode 'native' only
824
+ }, {
825
+ key: "animateScroll",
826
+ value: function _animateScroll(left, top, node) {
827
+ var _this8 = this;
828
+ // Determine the direction of scroll (1 for forward/down, -1 for backward/up, 0 for no movement)
829
+ var directionX = Math.sign(left - node.scrollLeft);
830
+ var directionY = Math.sign(top - node.scrollTop);
831
+
832
+ // Calculate an adaptive scroll factor (pixels per frame).
833
+ // It uses the average item size (gridSize) to ensure the speed feels consistent.
834
+ var scrollFactor = Math.max(this.primary.gridSize / 12, 2);
835
+ var startTime = performance.now();
836
+
837
+ // Progressively scrolls the node toward a target position using requestAnimationFrame.
838
+ // It applies an incremental scroll on each frame and cancels the animation once
839
+ // the target is reached or the duration (500ms) is exceeded, falling back to
840
+ // a smooth scroll if the timeout occurs first.
841
+ var _animateScroll = function animateScroll(currentTime) {
842
+ var elapsed = (currentTime - startTime) / 500;
843
+ node.scrollBy({
844
+ top: directionY * scrollFactor,
845
+ left: directionX * scrollFactor,
846
+ behavior: 'instant'
847
+ });
848
+ _this8.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
849
+ _this8.scrolling = true;
850
+ var scrollHorizontally = directionX > 0 ? node.scrollLeft < left : node.scrollLeft > left;
851
+ var scrollVertically = directionY > 0 ? node.scrollTop < top : node.scrollTop > top;
852
+ var targetReached = node.scrollLeft === left && node.scrollTop === top;
853
+
854
+ // Check if we've reached the needed scroll position
855
+ // or the elapsed time since startTime is longer than 0.5s and cancel the animation
856
+ if (!scrollHorizontally && !scrollVertically || elapsed > 1) {
857
+ _this8.cancelScrollAnimation();
858
+
859
+ // Fallback: if time is out before reaching the target, jump there with smooth scroll
860
+ if (elapsed > 1 && !targetReached) {
861
+ node.scrollTo({
862
+ top: top,
863
+ left: left,
864
+ behavior: 'smooth'
865
+ });
866
+ }
867
+ }
868
+ };
869
+ this.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
870
+ }
871
+
872
+ // scrollMode 'native' only
873
+ }, {
874
+ key: "cancelScrollAnimation",
875
+ value: function cancelScrollAnimation() {
876
+ window.cancelAnimationFrame(this.scrollAnimationId);
877
+ this.scrollAnimationId = null;
878
+ this.scrolling = false;
879
+ }
880
+
794
881
  // scrollMode 'native' only
795
882
  }, {
796
883
  key: "setScrollToPositionTarget",
@@ -829,10 +916,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
829
916
  }, {
830
917
  key: "didScroll",
831
918
  value: function didScroll(x, y) {
832
- var _this$props3 = this.props,
833
- dataSize = _this$props3.dataSize,
834
- spacing = _this$props3.spacing,
835
- itemSizes = _this$props3.itemSizes,
919
+ var _this$props4 = this.props,
920
+ dataSize = _this$props4.dataSize,
921
+ spacing = _this$props4.spacing,
922
+ itemSizes = _this$props4.itemSizes,
836
923
  firstIndex = this.state.firstIndex,
837
924
  isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
838
925
  threshold = this.threshold,
@@ -929,9 +1016,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
929
1016
  }, {
930
1017
  key: "applyItemPositionToDOMElement",
931
1018
  value: function applyItemPositionToDOMElement(index) {
932
- var _this$props4 = this.props,
933
- direction = _this$props4.direction,
934
- rtl = _this$props4.rtl,
1019
+ var _this$props5 = this.props,
1020
+ direction = _this$props5.direction,
1021
+ rtl = _this$props5.rtl,
935
1022
  numOfItems = this.state.numOfItems,
936
1023
  itemPositions = this.itemPositions,
937
1024
  childNode = this.itemContainerRefs[index % numOfItems];
@@ -961,10 +1048,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
961
1048
  }, {
962
1049
  key: "updateScrollBoundsWithItemPositions",
963
1050
  value: function updateScrollBoundsWithItemPositions() {
964
- var _this$props5 = this.props,
965
- dataSize = _this$props5.dataSize,
966
- itemSizes = _this$props5.itemSizes,
967
- spacing = _this$props5.spacing,
1051
+ var _this$props6 = this.props,
1052
+ dataSize = _this$props6.dataSize,
1053
+ itemSizes = _this$props6.itemSizes,
1054
+ spacing = _this$props6.spacing,
968
1055
  _this$state4 = this.state,
969
1056
  firstIndex = _this$state4.firstIndex,
970
1057
  numOfItems = _this$state4.numOfItems,
@@ -1041,9 +1128,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
1041
1128
  }, {
1042
1129
  key: "positionItems",
1043
1130
  value: function positionItems() {
1044
- var _this$props6 = this.props,
1045
- dataSize = _this$props6.dataSize,
1046
- itemSizes = _this$props6.itemSizes,
1131
+ var _this$props7 = this.props,
1132
+ dataSize = _this$props7.dataSize,
1133
+ itemSizes = _this$props7.itemSizes,
1047
1134
  _this$state6 = this.state,
1048
1135
  firstIndex = _this$state6.firstIndex,
1049
1136
  numOfItems = _this$state6.numOfItems,
@@ -1101,14 +1188,14 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
1101
1188
  // render
1102
1189
 
1103
1190
  function render() {
1104
- var _this$props7 = this.props,
1105
- className = _this$props7.className,
1106
- containerProps = _this$props7.containerProps,
1107
- placeholderRenderer = _this$props7.placeholderRenderer,
1108
- role = _this$props7.role,
1109
- style = _this$props7.style,
1110
- scrollMode = _this$props7.scrollMode,
1111
- rest = _objectWithoutProperties(_this$props7, _excluded),
1191
+ var _this$props8 = this.props,
1192
+ className = _this$props8.className,
1193
+ containerProps = _this$props8.containerProps,
1194
+ placeholderRenderer = _this$props8.placeholderRenderer,
1195
+ role = _this$props8.role,
1196
+ style = _this$props8.style,
1197
+ scrollMode = _this$props8.scrollMode,
1198
+ rest = _objectWithoutProperties(_this$props8, _excluded),
1112
1199
  cc = this.cc,
1113
1200
  isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
1114
1201
  primary = this.primary,
@@ -2,11 +2,14 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
- var _VirtualList = _interopRequireDefault(require("../VirtualList"));
5
+ var _react2 = require("react");
6
+ var _VirtualList = _interopRequireWildcard(require("../VirtualList"));
6
7
  var _jsxRuntime = require("react/jsx-runtime");
7
8
  var _excluded = ["index"],
8
- _excluded2 = ["index"];
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ _excluded2 = ["index"],
10
+ _excluded3 = ["direction"],
11
+ _excluded4 = ["index"];
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
15
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -14,6 +17,14 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
14
17
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
18
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
16
19
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
20
+ var mockPlatform = {};
21
+ jest.mock('@enact/core/platform', function () {
22
+ return {
23
+ get platform() {
24
+ return mockPlatform;
25
+ }
26
+ };
27
+ });
17
28
  describe('VirtualList with native scrollMode', function () {
18
29
  var clientSize, dataSize, items, itemSize, renderItem;
19
30
  beforeEach(function () {
@@ -165,4 +176,209 @@ describe('VirtualList with native scrollMode', function () {
165
176
  jest.useRealTimers();
166
177
  });
167
178
  });
179
+ describe('Animating scroll', function () {
180
+ var instance, node, scrollContentRef;
181
+ beforeEach(function () {
182
+ node = {
183
+ scrollTo: jest.fn(),
184
+ scrollBy: jest.fn(),
185
+ scrollLeft: 0,
186
+ scrollTop: 0
187
+ };
188
+ scrollContentRef = {
189
+ current: node
190
+ };
191
+ instance = new _VirtualList.VirtualListBasic({
192
+ scrollContentRef: scrollContentRef,
193
+ clientSize: clientSize,
194
+ itemSize: itemSize,
195
+ itemRenderer: renderItem,
196
+ scrollMode: 'native'
197
+ });
198
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
199
+ instance.rafCallback = cb;
200
+ return 123;
201
+ });
202
+ jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(jest.fn());
203
+ jest.spyOn(performance, 'now').mockReturnValue(0);
204
+ });
205
+ afterEach(function () {
206
+ delete mockPlatform.chrome;
207
+ });
208
+ test('should call native scrollTo when behavior is instant', function () {
209
+ instance.scrollToPosition(0, 300, 'instant');
210
+ expect(node.scrollTo).toHaveBeenCalledWith({
211
+ left: 0,
212
+ top: 300,
213
+ behavior: 'instant'
214
+ });
215
+ });
216
+ test('should call native scrollTo when NOT on Chrome and behavior is smooth', function () {
217
+ mockPlatform.chrome = false;
218
+ instance.scrollToPosition(0, 300, 'smooth');
219
+ expect(node.scrollTo).toHaveBeenCalledWith({
220
+ left: 0,
221
+ top: 300,
222
+ behavior: 'smooth'
223
+ });
224
+ });
225
+ test('should call animateScroll when on Chrome and behavior is smooth', function () {
226
+ mockPlatform.chrome = 88;
227
+ instance.animateScroll = jest.fn();
228
+ instance.scrollToPosition(0, 300, 'smooth');
229
+ expect(instance.animateScroll).toHaveBeenCalledWith(0, 300, node);
230
+ });
231
+ test('should cancel animation when content is scrolled by pageKey', function () {
232
+ mockPlatform.chrome = 88;
233
+ instance.scrollToPosition(0, 600, 'smooth');
234
+ node.lastInputType = 'pageKey';
235
+ instance.scrollToPosition(0, 200, 'smooth');
236
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
237
+ });
238
+ test('should initiate animation loop using requestAnimationFrame', function () {
239
+ instance.animateScroll(0, 300, node);
240
+ expect(window.requestAnimationFrame).toHaveBeenCalled();
241
+ });
242
+ test('should scroll incrementally on each frame', function () {
243
+ instance.animateScroll(0, 300, node);
244
+ instance.rafCallback();
245
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
246
+ behavior: 'instant'
247
+ }));
248
+ expect(instance.scrolling).toBe(true);
249
+ });
250
+ test('should cancel animation and stop when target is reached', function () {
251
+ node.scrollTop = 300;
252
+ instance.animateScroll(0, 310, node);
253
+ instance.rafCallback(600);
254
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
255
+ expect(instance.scrolling).toBe(false);
256
+ });
257
+ test('should fallback to smooth scroll if animation exceeds duration (timeout)', function () {
258
+ instance.animateScroll(0, 300, node);
259
+ instance.rafCallback(600);
260
+ node.scrollTop = 250;
261
+ expect(node.scrollTo).toHaveBeenCalledWith({
262
+ left: 0,
263
+ top: 300,
264
+ behavior: 'smooth'
265
+ });
266
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
267
+ });
268
+ });
269
+ });
270
+ describe('VirtualListBasic scrollBounds consistency after item margin detection', function () {
271
+ var originalGetComputedStyle;
272
+ var nop = function nop() {};
273
+ function renderVirtualListBasic() {
274
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
275
+ _ref3$direction = _ref3.direction,
276
+ direction = _ref3$direction === void 0 ? 'vertical' : _ref3$direction,
277
+ rest = _objectWithoutProperties(_ref3, _excluded3);
278
+ var scrollContentRef = /*#__PURE__*/(0, _react2.createRef)();
279
+ var itemRefs = /*#__PURE__*/(0, _react2.createRef)();
280
+ itemRefs.current = [];
281
+ var ref = /*#__PURE__*/(0, _react2.createRef)();
282
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList.VirtualListBasic, _objectSpread({
283
+ clientSize: {
284
+ clientWidth: 1280,
285
+ clientHeight: 720
286
+ },
287
+ dataSize: 100,
288
+ direction: direction,
289
+ getAffordance: function getAffordance() {
290
+ return 0;
291
+ },
292
+ itemRefs: itemRefs,
293
+ itemRenderer: function itemRenderer(_ref4) {
294
+ var index = _ref4.index,
295
+ rest2 = _objectWithoutProperties(_ref4, _excluded4);
296
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest2), {}, {
297
+ "data-index": index
298
+ }));
299
+ },
300
+ itemSize: 30,
301
+ overhang: 3,
302
+ placeholderRenderer: nop,
303
+ role: "list",
304
+ scrollContentRef: scrollContentRef,
305
+ scrollMode: "native",
306
+ spacing: 0,
307
+ cbScrollTo: nop,
308
+ ref: ref
309
+ }, rest)));
310
+ return {
311
+ ref: ref
312
+ };
313
+ }
314
+ beforeEach(function () {
315
+ originalGetComputedStyle = window.getComputedStyle;
316
+ });
317
+ afterEach(function () {
318
+ window.getComputedStyle = originalGetComputedStyle;
319
+ });
320
+ test('should increment scrollHeight and maxTop by the same margin sum when vertical item margins are detected, and not re-apply on subsequent updates', function () {
321
+ var _renderVirtualListBas = renderVirtualListBasic(),
322
+ ref = _renderVirtualListBas.ref;
323
+ var instance = ref.current;
324
+ var marginTop = 10;
325
+ var marginBottom = 5;
326
+ window.getComputedStyle = function (el) {
327
+ if (el === instance.props.itemRefs.current[0]) {
328
+ return {
329
+ getPropertyValue: function getPropertyValue(prop) {
330
+ if (prop === 'margin-top') return "".concat(marginTop, "px");
331
+ if (prop === 'margin-bottom') return "".concat(marginBottom, "px");
332
+ if (prop === 'margin-left') return '0px';
333
+ if (prop === 'margin-right') return '0px';
334
+ return '0px';
335
+ }
336
+ };
337
+ }
338
+ return originalGetComputedStyle(el);
339
+ };
340
+ instance.itemMarginTop = null;
341
+ (0, _react.act)(function () {
342
+ instance.forceUpdate();
343
+ });
344
+ var scrollHeightAfterFirst = instance.scrollBounds.scrollHeight;
345
+ var maxTopAfterFirst = instance.scrollBounds.maxTop;
346
+ expect(scrollHeightAfterFirst - maxTopAfterFirst).toBe(instance.props.clientSize.clientHeight);
347
+ expect(instance.scrollBounds.maxTop).toBe(instance.scrollBounds.scrollHeight - instance.props.clientSize.clientHeight);
348
+
349
+ // guard prevents re-applying on subsequent updates
350
+ (0, _react.act)(function () {
351
+ instance.forceUpdate();
352
+ });
353
+ expect(instance.scrollBounds.scrollHeight).toBe(scrollHeightAfterFirst);
354
+ expect(instance.scrollBounds.maxTop).toBe(maxTopAfterFirst);
355
+ });
356
+ test('should increment scrollWidth and maxLeft by the same margin sum when horizontal item margins are detected', function () {
357
+ var _renderVirtualListBas2 = renderVirtualListBasic({
358
+ direction: 'horizontal'
359
+ }),
360
+ ref = _renderVirtualListBas2.ref;
361
+ var instance = ref.current;
362
+ var marginLeft = 8;
363
+ var marginRight = 8;
364
+ window.getComputedStyle = function (el) {
365
+ if (el === instance.props.itemRefs.current[0]) {
366
+ return {
367
+ getPropertyValue: function getPropertyValue(prop) {
368
+ if (prop === 'margin-top') return '0px';
369
+ if (prop === 'margin-bottom') return '0px';
370
+ if (prop === 'margin-left') return "".concat(marginLeft, "px");
371
+ if (prop === 'margin-right') return "".concat(marginRight, "px");
372
+ return '0px';
373
+ }
374
+ };
375
+ }
376
+ return originalGetComputedStyle(el);
377
+ };
378
+ instance.itemMarginTop = null;
379
+ (0, _react.act)(function () {
380
+ instance.forceUpdate();
381
+ });
382
+ expect(instance.scrollBounds.scrollWidth - instance.scrollBounds.maxLeft).toBe(instance.props.clientSize.clientWidth);
383
+ });
168
384
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/ui",
3
- "version": "5.5.0",
3
+ "version": "5.5.1",
4
4
  "description": "A collection of simplified unstyled cross-platform UI components for Enact",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,10 +32,10 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@enact/core": "^5.5.0",
36
- "@enact/i18n": "^5.5.0",
35
+ "@enact/core": "^5.5.1",
36
+ "@enact/i18n": "^5.5.1",
37
37
  "classnames": "^2.5.1",
38
- "ilib": "^14.21.3",
38
+ "ilib": "^14.22.0",
39
39
  "invariant": "^2.2.4",
40
40
  "prop-types": "^15.8.1",
41
41
  "ramda": "^0.32.0",
@@ -3,6 +3,12 @@
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
5
  var _useScroll = require("../useScroll");
6
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
6
12
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
13
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
14
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -128,6 +134,7 @@ describe('useScroll', function () {
128
134
  jest.useRealTimers();
129
135
  });
130
136
  test('should scale itemSize when ri.scale(1) changes from 1 to 2', function () {
137
+ var _scrollContentPropsCa;
131
138
  mockRiScale = jest.fn(function (val) {
132
139
  return val;
133
140
  });
@@ -136,13 +143,14 @@ describe('useScroll', function () {
136
143
  minHeight: 50
137
144
  };
138
145
  var mocks = createMockRefs();
146
+ var assignProperties = jest.fn();
139
147
  var props = _objectSpread(_objectSpread({
140
148
  itemRenderer: jest.fn(),
141
149
  itemSize: itemSize,
142
150
  direction: 'vertical',
143
151
  scrollMode: 'translate'
144
152
  }, mocks), {}, {
145
- assignProperties: jest.fn(),
153
+ assignProperties: assignProperties,
146
154
  horizontalScrollbar: 'auto',
147
155
  verticalScrollbar: 'auto'
148
156
  });
@@ -158,16 +166,30 @@ describe('useScroll', function () {
158
166
  (0, _react.fireEvent)(window, new Event('resize'));
159
167
  jest.runAllTimers();
160
168
  });
161
- expect(itemSize.minWidth).toBe(200);
162
- expect(itemSize.minHeight).toBe(100);
169
+
170
+ // Original props object must not be mutated
171
+ expect(itemSize.minWidth).toBe(100);
172
+ expect(itemSize.minHeight).toBe(50);
173
+
174
+ // The scaled values should be passed to scrollContentProps via assignProperties
175
+ var scrollContentPropsCall = assignProperties.mock.calls.findLast(function (_ref) {
176
+ var _ref2 = _slicedToArray(_ref, 1),
177
+ name = _ref2[0];
178
+ return name === 'scrollContentProps';
179
+ });
180
+ var passedItemSize = scrollContentPropsCall === null || scrollContentPropsCall === void 0 || (_scrollContentPropsCa = scrollContentPropsCall[1]) === null || _scrollContentPropsCa === void 0 ? void 0 : _scrollContentPropsCa.itemSize;
181
+ expect(passedItemSize === null || passedItemSize === void 0 ? void 0 : passedItemSize.minWidth).toBe(200);
182
+ expect(passedItemSize === null || passedItemSize === void 0 ? void 0 : passedItemSize.minHeight).toBe(100);
163
183
  });
164
184
  test('should scale itemSizes when ri.scale(1) changes from 1 to 2', function () {
185
+ var _scrollContentPropsCa2;
165
186
  mockRiScale = jest.fn(function (val) {
166
187
  return val;
167
188
  });
168
189
  var itemSize = 100;
169
190
  var itemSizes = [100, 100, 100, 100, 100];
170
191
  var mocks = createMockRefs();
192
+ var assignProperties = jest.fn();
171
193
  var props = _objectSpread(_objectSpread({
172
194
  itemRenderer: jest.fn(),
173
195
  itemSize: itemSize,
@@ -175,7 +197,7 @@ describe('useScroll', function () {
175
197
  direction: 'vertical',
176
198
  scrollMode: 'translate'
177
199
  }, mocks), {}, {
178
- assignProperties: jest.fn(),
200
+ assignProperties: assignProperties,
179
201
  horizontalScrollbar: 'auto',
180
202
  verticalScrollbar: 'auto'
181
203
  });
@@ -191,7 +213,18 @@ describe('useScroll', function () {
191
213
  (0, _react.fireEvent)(window, new Event('resize'));
192
214
  jest.runAllTimers();
193
215
  });
194
- expect(itemSizes[1]).toBe(200);
216
+
217
+ // Original props array must not be mutated
218
+ expect(itemSizes[1]).toBe(100);
219
+
220
+ // The scaled values should be passed to scrollContentProps via assignProperties
221
+ var scrollContentPropsCall = assignProperties.mock.calls.findLast(function (_ref3) {
222
+ var _ref4 = _slicedToArray(_ref3, 1),
223
+ name = _ref4[0];
224
+ return name === 'scrollContentProps';
225
+ });
226
+ var passedItemSizes = scrollContentPropsCall === null || scrollContentPropsCall === void 0 || (_scrollContentPropsCa2 = scrollContentPropsCall[1]) === null || _scrollContentPropsCa2 === void 0 ? void 0 : _scrollContentPropsCa2.itemSizes;
227
+ expect(passedItemSizes === null || passedItemSizes === void 0 ? void 0 : passedItemSizes[1]).toBe(200);
195
228
  });
196
229
  test('should NOT scale itemSize when ri.scale(1) remains unchanged', function () {
197
230
  mockRiScale = jest.fn(function (val) {
@@ -342,7 +375,7 @@ describe('useScroll', function () {
342
375
  expect(roundedTargetX).toEqual(121);
343
376
  expect(roundedTargetY).toEqual(121);
344
377
  });
345
- test('should round target position downwards when target is bi than current position', function () {
378
+ test('should round target position downwards when target is less than current position', function () {
346
379
  mockPlatform = {
347
380
  chrome: 132
348
381
  };
@@ -431,6 +464,7 @@ describe('useScroll', function () {
431
464
  scrollMode: 'native',
432
465
  rtl: true
433
466
  }, mocks), {}, {
467
+ addEventListeners: jest.fn(),
434
468
  assignProperties: jest.fn(),
435
469
  horizontalScrollbar: 'auto',
436
470
  verticalScrollbar: 'auto'
@@ -453,4 +487,139 @@ describe('useScroll', function () {
453
487
  expect(mocks.scrollContentHandle.current.didScroll).toHaveBeenCalledWith(50, 0);
454
488
  });
455
489
  });
490
+ describe('onKeyDown repeat handling (native scroll mode)', function () {
491
+ beforeEach(function () {
492
+ jest.useFakeTimers();
493
+ mockPlatform = {
494
+ chrome: 132
495
+ };
496
+ mockRiScale = jest.fn(function (val) {
497
+ return val;
498
+ });
499
+ });
500
+ afterEach(function () {
501
+ jest.runOnlyPendingTimers();
502
+ jest.useRealTimers();
503
+ });
504
+ function createNativeScrollProps(mocks) {
505
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
506
+ return _objectSpread(_objectSpread({
507
+ direction: 'vertical',
508
+ scrollMode: 'native'
509
+ }, mocks), {}, {
510
+ assignProperties: jest.fn(),
511
+ horizontalScrollbar: 'auto',
512
+ verticalScrollbar: 'auto'
513
+ }, extra);
514
+ }
515
+ test('should forward onKeyDown event when key is not repeated', function () {
516
+ var mocks = createMockRefs();
517
+ var onKeyDown = jest.fn();
518
+ var props = createNativeScrollProps(mocks, {
519
+ onKeyDown: onKeyDown
520
+ });
521
+ (0, _react.renderHook)(function () {
522
+ return (0, _useScroll.useScrollBase)(props);
523
+ });
524
+
525
+ // eslint-disable-next-line testing-library/no-unnecessary-act
526
+ (0, _react.act)(function () {
527
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
528
+ keyCode: 40,
529
+ repeat: false
530
+ });
531
+ });
532
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
533
+ });
534
+ test('should not forward onKeyDown event when arrowKey is repeated and lastInputType is arrowKey', function () {
535
+ var mocks = createMockRefs();
536
+ var onKeyDown = jest.fn();
537
+ var scrollContainerHandle = null;
538
+ var props = createNativeScrollProps(mocks, {
539
+ onKeyDown: onKeyDown,
540
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
541
+ scrollContainerHandle = handle;
542
+ }
543
+ });
544
+ (0, _react.renderHook)(function () {
545
+ return (0, _useScroll.useScrollBase)(props);
546
+ });
547
+
548
+ // Set lastInputType to arrowKey via the exposed themeScrollContainerHandle
549
+ (0, _react.act)(function () {
550
+ if (scrollContainerHandle) {
551
+ scrollContainerHandle.lastInputType = 'arrowKey';
552
+ }
553
+ });
554
+
555
+ // eslint-disable-next-line testing-library/no-unnecessary-act
556
+ (0, _react.act)(function () {
557
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
558
+ keyCode: 40,
559
+ repeat: true
560
+ });
561
+ });
562
+ expect(onKeyDown).not.toHaveBeenCalled();
563
+ });
564
+ test('should not forward onKeyDown event when pageKey is repeated and lastInputType is pageKey', function () {
565
+ var mocks = createMockRefs();
566
+ var onKeyDown = jest.fn();
567
+ var scrollContainerHandle = null;
568
+ var props = createNativeScrollProps(mocks, {
569
+ onKeyDown: onKeyDown,
570
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
571
+ scrollContainerHandle = handle;
572
+ }
573
+ });
574
+ (0, _react.renderHook)(function () {
575
+ return (0, _useScroll.useScrollBase)(props);
576
+ });
577
+
578
+ // Set lastInputType to pageKey via the exposed themeScrollContainerHandle
579
+ (0, _react.act)(function () {
580
+ if (scrollContainerHandle) {
581
+ scrollContainerHandle.lastInputType = 'pageKey';
582
+ }
583
+ });
584
+
585
+ // eslint-disable-next-line testing-library/no-unnecessary-act
586
+ (0, _react.act)(function () {
587
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
588
+ keyCode: 33,
589
+ repeat: true
590
+ });
591
+ });
592
+ expect(onKeyDown).not.toHaveBeenCalled();
593
+ });
594
+ test('should forward onKeyDown event when repeat is true but lastInputType is neither arrowKey nor pageKey', function () {
595
+ var mocks = createMockRefs();
596
+ var onKeyDown = jest.fn();
597
+ var scrollContainerHandle = null;
598
+ var props = createNativeScrollProps(mocks, {
599
+ onKeyDown: onKeyDown,
600
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
601
+ scrollContainerHandle = handle;
602
+ }
603
+ });
604
+ (0, _react.renderHook)(function () {
605
+ return (0, _useScroll.useScrollBase)(props);
606
+ });
607
+
608
+ // Set lastInputType to wheel (not arrowKey or pageKey)
609
+ (0, _react.act)(function () {
610
+ if (scrollContainerHandle) {
611
+ scrollContainerHandle.lastInputType = 'wheel';
612
+ }
613
+ });
614
+
615
+ // eslint-disable-next-line testing-library/no-unnecessary-act
616
+ (0, _react.act)(function () {
617
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
618
+ keyCode: 40,
619
+ repeat: true
620
+ });
621
+ });
622
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
623
+ });
624
+ });
456
625
  });
@@ -24,7 +24,7 @@ var _utilEvent = _interopRequireDefault(require("./utilEvent"));
24
24
  var _useScrollModule = _interopRequireDefault(require("./useScroll.module.css"));
25
25
  var _jsxRuntime = require("react/jsx-runtime");
26
26
  var _excluded = ["ref"],
27
- _excluded2 = ["childProps", "children", "className", "clientSize", "assignProperties", "dataSize", "direction", "horizontalScrollbar", "horizontalScrollbarHandle", "itemRenderer", "itemSizes", "noScrollByDrag", "noScrollByWheel", "overhang", "overscrollEffectOn", "pageScroll", "role", "rtl", "scrollContainerRef", "scrollContentHandle", "scrollContentRef", "scrollMode", "setScrollContainerHandle", "snapToCenter", "spacing", "spotlightContainerDisabled", "verticalScrollbar", "verticalScrollbarHandle", "wrap"];
27
+ _excluded2 = ["childProps", "children", "className", "clientSize", "assignProperties", "dataSize", "direction", "horizontalScrollbar", "horizontalScrollbarHandle", "itemRenderer", "noScrollByDrag", "noScrollByWheel", "overhang", "overscrollEffectOn", "pageScroll", "role", "rtl", "scrollContainerRef", "scrollContentHandle", "scrollContentRef", "scrollMode", "setScrollContainerHandle", "snapToCenter", "spacing", "spotlightContainerDisabled", "verticalScrollbar", "verticalScrollbarHandle", "wrap"];
28
28
  /* global ResizeObserver */
29
29
  /**
30
30
  * Unstyled scrollable hook and behaviors to be customized by a theme or application.
@@ -138,6 +138,7 @@ function roundTarget(currentPosition, targetX, targetY) {
138
138
  * @private
139
139
  */
140
140
  var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
141
+ var _scaledItemSizesRef$c;
141
142
  var childProps = props.childProps,
142
143
  children = props.children,
143
144
  className = props.className,
@@ -148,7 +149,6 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
148
149
  horizontalScrollbar = props.horizontalScrollbar,
149
150
  horizontalScrollbarHandle = props.horizontalScrollbarHandle,
150
151
  itemRenderer = props.itemRenderer,
151
- itemSizes = props.itemSizes,
152
152
  noScrollByDrag = props.noScrollByDrag,
153
153
  noScrollByWheel = props.noScrollByWheel,
154
154
  overhang = props.overhang,
@@ -179,6 +179,7 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
179
179
  delete rest.clearOverscrollEffect;
180
180
  delete rest.handleResizeWindow;
181
181
  delete rest.itemSize;
182
+ delete rest.itemSizes;
182
183
  delete rest.onFlick;
183
184
  delete rest.onKeyDown;
184
185
  delete rest.onMouseDown;
@@ -219,6 +220,12 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
219
220
  _useState0 = _slicedToArray(_useState9, 2),
220
221
  itemSize = _useState0[0],
221
222
  setItemSize = _useState0[1];
223
+ var scaledItemSizesRef = (0, _react.useRef)(null);
224
+ var scaledItemSizesSourceRef = (0, _react.useRef)(props.itemSizes);
225
+ if (scaledItemSizesSourceRef.current !== props.itemSizes) {
226
+ scaledItemSizesRef.current = null;
227
+ scaledItemSizesSourceRef.current = props.itemSizes;
228
+ }
222
229
  var mutableRef = (0, _react.useRef)({
223
230
  overscrollEnabled: !!props.applyOverscrollEffect,
224
231
  // Enable the early bail out of repeated scrolling to the same position
@@ -464,7 +471,7 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
464
471
  dataSize: dataSize,
465
472
  itemRenderer: itemRenderer,
466
473
  itemSize: itemSize,
467
- itemSizes: itemSizes,
474
+ itemSizes: (_scaledItemSizesRef$c = scaledItemSizesRef.current) !== null && _scaledItemSizesRef$c !== void 0 ? _scaledItemSizesRef$c : props.itemSizes,
468
475
  overhang: overhang,
469
476
  pageScroll: pageScroll,
470
477
  spacing: spacing,
@@ -476,15 +483,18 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
476
483
  var propsHandleResizeWindow = props.handleResizeWindow;
477
484
  if (_resolution["default"].scale(1) !== riRatio) {
478
485
  if (scrollContentProps.itemSize) {
486
+ var ratio = _resolution["default"].scale(1) / riRatio;
479
487
  if (scrollContentProps.itemSize.minWidth && scrollContentProps.itemSize.minHeight) {
480
- scrollContentProps.itemSize.minWidth *= _resolution["default"].scale(1) / riRatio;
481
- scrollContentProps.itemSize.minHeight *= _resolution["default"].scale(1) / riRatio;
488
+ scrollContentProps.itemSize = _objectSpread(_objectSpread({}, scrollContentProps.itemSize), {}, {
489
+ minWidth: scrollContentProps.itemSize.minWidth * ratio,
490
+ minHeight: scrollContentProps.itemSize.minHeight * ratio
491
+ });
482
492
  } else {
483
- scrollContentProps.itemSize *= _resolution["default"].scale(1) / riRatio;
493
+ scrollContentProps.itemSize *= ratio;
484
494
  if (scrollContentProps.itemSizes) {
485
- for (var i = 0; i < scrollContentProps.itemSizes.length; i++) {
486
- scrollContentProps.itemSizes[i] *= _resolution["default"].scale(1) / riRatio;
487
- }
495
+ scaledItemSizesRef.current = scrollContentProps.itemSizes.map(function (s) {
496
+ return s * ratio;
497
+ });
488
498
  }
489
499
  }
490
500
  setItemSize(scrollContentProps.itemSize);
@@ -918,7 +928,8 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
918
928
  * Handler for scrollend event
919
929
  */
920
930
  function onScrollEnd(ev) {
921
- if (!mutableRef.current.scrolling) {
931
+ var _scrollContentHandle$;
932
+ if (!mutableRef.current.scrolling || mutableRef.current.keyPressed || (_scrollContentHandle$ = scrollContentHandle.current) !== null && _scrollContentHandle$ !== void 0 && _scrollContentHandle$.scrolling) {
922
933
  return;
923
934
  }
924
935
  updateScrollPosition(ev);
@@ -927,7 +938,7 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
927
938
  mutableRef.current.scrollStopJob.stop();
928
939
 
929
940
  // stop for non-accumulating scrolls (mouse/touch)
930
- if (!mutableRef.current.isScrollAnimationTargetAccumulated) {
941
+ if (!mutableRef.current.isScrollAnimationTargetAccumulated && !mutableRef.current.keyScroll) {
931
942
  scrollStopOnScroll();
932
943
  return;
933
944
  }
@@ -938,6 +949,7 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
938
949
  }
939
950
  mutableRef.current.scrollEndGraceTimer = setTimeout(function () {
940
951
  mutableRef.current.scrollEndGraceTimer = null;
952
+ mutableRef.current.keyScroll = false;
941
953
  scrollStopOnScroll();
942
954
  }, 100);
943
955
  }
@@ -955,12 +967,15 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
955
967
  var _props$preventScroll;
956
968
  (_props$preventScroll = props.preventScroll) === null || _props$preventScroll === void 0 || _props$preventScroll.call(props, ev);
957
969
  mutableRef.current.repeat = ev.repeat;
958
- if (ev.repeat && mutableRef.current.lastInputType === 'arrowKey') return;
970
+ var isArrowKey = mutableRef.current.lastInputType === 'arrowKey';
971
+ var isPageKey = mutableRef.current.lastInputType === 'pageKey';
972
+ if (ev.repeat && (isArrowKey || isPageKey)) return;
959
973
  (0, _handle.forward)('onKeyDown', ev, props);
960
974
  }
961
975
  }
962
976
  function onKeyUp(ev) {
963
977
  mutableRef.current.keyPressed = false;
978
+ mutableRef.current.keyScroll = true;
964
979
  (0, _handle.forward)('onKeyUp', ev, props);
965
980
  }
966
981
  function scrollToAccumulatedTarget(delta, vertical, overscrollEffect) {
@@ -1275,6 +1290,7 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
1275
1290
  roundedTargetX = _roundTarget.roundedTargetX,
1276
1291
  roundedTargetY = _roundTarget.roundedTargetY;
1277
1292
  if (animate) {
1293
+ scrollContentRef.current.lastInputType = mutableRef.current.lastInputType;
1278
1294
  scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'smooth', mutableRef.current.repeat);
1279
1295
  } else {
1280
1296
  scrollContentHandle.current.scrollToPosition(roundedTargetX, roundedTargetY, 'instant');