@enact/ui 5.4.2 → 5.4.4

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,20 @@
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.4.4] - 2026-05-22
6
+
7
+ ### Fixed
8
+
9
+ - `ui/Scroller` jumping back when scrolled by long press
10
+
11
+ ## [5.4.3] - 2026-02-26
12
+
13
+ ### Fixed
14
+
15
+ - `ui/VirtualList` to revert 5.4.2 cix that not to jump to the top when item size was changed
16
+ - `ui/VirtulList` to revert 5.4.2 fix that not to cut off focused item when scroll by pressing key
17
+ - `ui/VirtualList.VirtualGridList` to revert 5.4.2 fix to adjust itemSize properly when resizing window
18
+
5
19
  ## [5.4.2] - 2026-01-28
6
20
 
7
21
  ### Changed
@@ -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
  });
@@ -104,22 +104,16 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
104
104
  _this.isItemSized = false;
105
105
  _this.shouldUpdateBounds = false;
106
106
  _this.dimensionToExtent = 0;
107
- _this.itemMarginLeft = null;
108
- _this.itemMarginRight = null;
109
- _this.itemMarginTop = null;
110
- _this.itemMarginBottom = null;
111
107
  _this.threshold = 0;
112
108
  _this.maxFirstIndex = 0;
113
109
  _this.curDataSize = 0;
114
110
  _this.hasDataSizeChanged = false;
115
111
  _this.cc = [];
116
112
  _this.scrollPosition = 0;
117
- _this.prevScrollPosition = 0;
118
113
  _this.scrollPositionTarget = 0;
119
114
  _this.scrollToPositionTarget = -1;
120
115
  // For individually sized item
121
116
  _this.itemPositions = [];
122
- _this.prevItemPositions = [];
123
117
  _this.indexToScrollIntoView = -1;
124
118
  _this.updateScrollPosition = function (_ref, behavior) {
125
119
  var x = _ref.x,
@@ -171,19 +165,18 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
171
165
  var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
172
166
  var position = _this.getGridPosition(index);
173
167
  var offset = 0;
174
- var marginOffset = isPrimaryDirectionVertical ? _this.itemMarginTop + _this.itemMarginBottom : _this.itemMarginLeft + _this.itemMarginRight;
175
168
  if (stickTo === 'start') {
176
169
  // 'start'
177
170
  offset = optionalOffset;
178
171
  } else if (_this.props.itemSizes) {
179
172
  // 'end' for different item sizes
180
- offset = primary.clientSize - _this.props.itemSizes[index] - marginOffset - optionalOffset;
173
+ offset = primary.clientSize - _this.props.itemSizes[index] - optionalOffset;
181
174
  } else if (stickTo === 'center') {
182
175
  // 'center'
183
176
  offset = primary.clientSize / 2 - primary.gridSize / 2 - optionalOffset;
184
177
  } else {
185
178
  // 'end' for same item sizes
186
- offset = primary.clientSize - primary.itemSize - marginOffset - optionalOffset;
179
+ offset = primary.clientSize - primary.itemSize - optionalOffset;
187
180
  }
188
181
 
189
182
  /* istanbul ignore next */
@@ -394,16 +387,6 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
394
387
  }, {
395
388
  key: "componentDidUpdate",
396
389
  value: function componentDidUpdate(prevProps, prevState) {
397
- var items = document.getElementsByClassName(_VirtualListModule["default"].listItem);
398
- if (!this.itemMarginTop && this.itemMarginTop !== 0 && items.length > 0) {
399
- var firstItemStyle = window.getComputedStyle(items[0].children[0]);
400
- this.itemMarginTop = Number(firstItemStyle.getPropertyValue('margin-top').slice(0, -2));
401
- this.itemMarginBottom = Number(firstItemStyle.getPropertyValue('margin-bottom').slice(0, -2));
402
- this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
403
- this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
404
- }
405
- this.scrollBounds.maxTop += this.itemMarginTop + this.itemMarginBottom;
406
- this.scrollBounds.maxLeft += this.itemMarginLeft + this.itemMarginRight;
407
390
  var deferScrollTo = false;
408
391
  var _this$state = this.state,
409
392
  firstIndex = _this$state.firstIndex,
@@ -459,42 +442,17 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
459
442
  }
460
443
  }
461
444
  if (prevProps.direction !== this.props.direction || prevProps.overhang !== this.props.overhang || prevProps.spacing !== this.props.spacing || !(0, _equals["default"])(prevProps.itemSize, this.props.itemSize) || !this.hasDataSizeChanged && !(0, _util.shallowEqual)(prevProps.itemSizes, this.props.itemSizes)) {
462
- var _this$scrollBounds = this.scrollBounds,
463
- clientHeight = _this$scrollBounds.clientHeight,
464
- clientWidth = _this$scrollBounds.clientWidth,
465
- scrollHeight = _this$scrollBounds.scrollHeight,
466
- scrollWidth = _this$scrollBounds.scrollWidth;
467
-
468
- /* istanbul ignore next */
469
- if (this.scrollPosition === 0 && this.moreInfo.firstVisibleIndex !== 0) {
470
- this.scrollPosition = this.prevScrollPosition;
471
- this.setState({
472
- firstIndex: prevState.firstIndex
473
- });
474
- this.updateMoreInfo(this.props.dataSize, this.scrollPosition);
475
- for (var i = prevState.firstIndex; i < prevState.firstIndex + this.state.numOfItems; i++) {
476
- var _this$itemPositions, _this$prevItemPositio, _this$itemPositions2, _this$prevItemPositio2;
477
- var size = this.isPrimaryDirectionVertical ? clientHeight : clientWidth;
478
- if (((_this$itemPositions = this.itemPositions[i + 1]) === null || _this$itemPositions === void 0 ? void 0 : _this$itemPositions.position) > ((_this$prevItemPositio = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio === void 0 ? void 0 : _this$prevItemPositio.position)) {
479
- if (i === this.moreInfo.lastVisibleIndex && this.getItemBottomPosition(i) > this.scrollPosition + size) {
480
- this.scrollPosition = this.getItemBottomPosition(i) - size;
481
- }
482
- break;
483
- }
484
- if (((_this$itemPositions2 = this.itemPositions[i + 1]) === null || _this$itemPositions2 === void 0 ? void 0 : _this$itemPositions2.position) < ((_this$prevItemPositio2 = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio2 === void 0 ? void 0 : _this$prevItemPositio2.position)) {
485
- if (this.itemPositions[i].position < this.scrollPosition) {
486
- this.scrollPosition = this.itemPositions[i].position;
487
- }
488
- break;
489
- }
490
- }
491
- }
492
445
  var _this$getXY = this.getXY(this.scrollPosition, 0),
493
446
  x = _this$getXY.x,
494
447
  y = _this$getXY.y;
495
448
  this.calculateMetrics(this.props);
496
- this.setState(this.getStatesAndUpdateBounds(this.props, prevState.firstIndex ? prevState.firstIndex : 0));
449
+ this.setState(this.getStatesAndUpdateBounds(this.props));
497
450
  this.setContainerSize();
451
+ var _this$scrollBounds = this.scrollBounds,
452
+ clientHeight = _this$scrollBounds.clientHeight,
453
+ clientWidth = _this$scrollBounds.clientWidth,
454
+ scrollHeight = _this$scrollBounds.scrollHeight,
455
+ scrollWidth = _this$scrollBounds.scrollWidth;
498
456
  var xMax = scrollWidth - clientWidth;
499
457
  var yMax = scrollHeight - clientHeight;
500
458
  this.updateScrollPosition({
@@ -633,10 +591,6 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
633
591
  this.secondary = secondary;
634
592
 
635
593
  // reset
636
- this.prevScrollPosition = this.scrollPosition;
637
- for (var i = 0; i < this.itemPositions.length; i++) {
638
- this.prevItemPositions[i] = this.itemPositions[i];
639
- }
640
594
  this.scrollPosition = 0;
641
595
  this.scrollToPositionTarget = -1;
642
596
  if (scrollMode === 'translate' && this.contentRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/ui",
3
- "version": "5.4.2",
3
+ "version": "5.4.4",
4
4
  "description": "A collection of simplified unstyled cross-platform UI components for Enact",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,16 +32,16 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@enact/core": "^5.4.2",
36
- "@enact/i18n": "^5.4.2",
35
+ "@enact/core": "^5.4.4",
36
+ "@enact/i18n": "^5.4.4",
37
37
  "classnames": "^2.5.1",
38
- "ilib": "^14.21.2",
38
+ "ilib": "^14.22.0",
39
39
  "invariant": "^2.2.4",
40
40
  "prop-types": "^15.8.1",
41
41
  "ramda": "^0.32.0",
42
- "react": "^19.2.3",
43
- "react-dom": "^19.2.3",
44
- "react-is": "^19.2.3",
42
+ "react": "^19.2.6",
43
+ "react-dom": "^19.2.6",
44
+ "react-is": "^19.2.6",
45
45
  "warning": "^4.0.3"
46
46
  }
47
47
  }
@@ -6,111 +6,125 @@ var _useScroll = require("../useScroll");
6
6
  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
7
  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
8
  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; }
9
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
10
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
11
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
12
9
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
13
10
  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); }
14
- // Mock all dependencies at the top level BEFORE importing useScroll
15
- var mockRiScale;
16
11
  var mockPlatform;
17
- jest.mock('../../resolution', function () {
18
- return {
19
- __esModule: true,
20
- "default": {
21
- get scale() {
22
- return mockRiScale || function (val) {
23
- return val;
24
- };
25
- }
26
- }
27
- };
28
- });
29
12
  jest.mock('@enact/core/platform', function () {
30
13
  return {
31
14
  __esModule: true,
32
15
  get platform() {
33
- return mockPlatform || {
34
- chrome: 120
35
- };
16
+ return mockPlatform;
36
17
  }
37
18
  };
38
19
  });
39
- global.ResizeObserver = /*#__PURE__*/function () {
40
- function ResizeObserver() {
41
- _classCallCheck(this, ResizeObserver);
42
- }
43
- return _createClass(ResizeObserver, [{
44
- key: "observe",
45
- value: function observe() {}
46
- }, {
47
- key: "unobserve",
48
- value: function unobserve() {}
49
- }, {
50
- key: "disconnect",
51
- value: function disconnect() {}
52
- }]);
53
- }();
54
-
55
- // Import AFTER all mocks
56
-
57
- // Helper function to create complete mock refs
58
20
  function createMockRefs() {
21
+ var el = document.createElement('div');
22
+ document.body.appendChild(el);
59
23
  return {
24
+ scrollContainerRef: {
25
+ current: el
26
+ },
60
27
  scrollContentHandle: {
61
28
  current: {
62
- getScrollBounds: jest.fn(function () {
29
+ getScrollBounds: function getScrollBounds() {
63
30
  return {
64
- clientWidth: 1920,
65
- clientHeight: 1080,
66
- scrollWidth: 1000,
67
- scrollHeight: 800,
68
- maxTop: 200,
69
- maxLeft: 200
31
+ maxTop: 0,
32
+ maxLeft: 0,
33
+ clientWidth: 0,
34
+ clientHeight: 0,
35
+ scrollWidth: 0,
36
+ scrollHeight: 0
70
37
  };
71
- }),
72
- getMoreInfo: jest.fn(function () {
73
- return {};
74
- }),
75
- hasDataSizeChanged: false,
76
- syncClientSize: jest.fn(function () {
77
- return false;
78
- }),
79
- getRtlPositionX: jest.fn(function (x) {
80
- return x;
81
- }),
82
- calculateMetrics: jest.fn(),
83
- props: {}
38
+ }
84
39
  }
85
40
  },
86
- scrollContainerRef: {
87
- current: document.createElement('div')
88
- },
89
41
  scrollContentRef: {
90
- current: document.createElement('div')
42
+ current: el
91
43
  },
92
44
  horizontalScrollbarHandle: {
93
- current: {
94
- update: jest.fn(),
95
- getContainerRef: jest.fn(function () {
96
- return document.createElement('div');
97
- }),
98
- startHidingScrollbarTrack: jest.fn()
99
- }
45
+ current: {}
100
46
  },
101
47
  verticalScrollbarHandle: {
102
- current: {
103
- update: jest.fn(),
104
- getContainerRef: jest.fn(function () {
105
- return document.createElement('div');
106
- }),
107
- startHidingScrollbarTrack: jest.fn()
108
- }
48
+ current: {}
109
49
  }
110
50
  };
111
51
  }
112
52
  describe('useScroll', function () {
113
- describe('riRatio itemSize scaling on window resize', function () {
53
+ describe('Rounding target scroll position', function () {
54
+ beforeEach(function () {
55
+ jest.resetModules(); // important! clears cached modules
56
+ });
57
+ test('should round target position upwards when target is bigger than current position', function () {
58
+ jest.doMock('@enact/core/platform', function () {
59
+ return {
60
+ __esModule: true,
61
+ platform: {
62
+ chrome: 132
63
+ }
64
+ };
65
+ });
66
+ var _require = require('../useScroll'),
67
+ roundTarget = _require.roundTarget;
68
+ var currentPosition = {
69
+ scrollPos: {
70
+ left: 100,
71
+ top: 100
72
+ }
73
+ };
74
+ var _roundTarget = roundTarget(currentPosition, 120.5, 120.4),
75
+ roundedTargetX = _roundTarget.roundedTargetX,
76
+ roundedTargetY = _roundTarget.roundedTargetY;
77
+ expect(roundedTargetX).toEqual(121);
78
+ expect(roundedTargetY).toEqual(121);
79
+ });
80
+ test('should round target position downwards when target is bigger than current position', function () {
81
+ jest.doMock('@enact/core/platform', function () {
82
+ return {
83
+ __esModule: true,
84
+ platform: {
85
+ chrome: 132
86
+ }
87
+ };
88
+ });
89
+ var _require2 = require('../useScroll'),
90
+ roundTarget = _require2.roundTarget;
91
+ var currentPosition = {
92
+ scrollPos: {
93
+ left: 100,
94
+ top: 100
95
+ }
96
+ };
97
+ var _roundTarget2 = roundTarget(currentPosition, 90.4, 80.8),
98
+ roundedTargetX = _roundTarget2.roundedTargetX,
99
+ roundedTargetY = _roundTarget2.roundedTargetY;
100
+ expect(roundedTargetX).toEqual(90);
101
+ expect(roundedTargetY).toEqual(80);
102
+ });
103
+ test('should not round target position when chrome <= 120', function () {
104
+ jest.doMock('@enact/core/platform', function () {
105
+ return {
106
+ __esModule: true,
107
+ platform: {
108
+ chrome: 119
109
+ }
110
+ };
111
+ });
112
+ var _require3 = require('../useScroll'),
113
+ roundTarget = _require3.roundTarget;
114
+ var currentPosition = {
115
+ scrollPos: {
116
+ left: 100,
117
+ top: 100
118
+ }
119
+ };
120
+ var _roundTarget3 = roundTarget(currentPosition, 90.4, 80.8),
121
+ roundedTargetX = _roundTarget3.roundedTargetX,
122
+ roundedTargetY = _roundTarget3.roundedTargetY;
123
+ expect(roundedTargetX).toEqual(90.4);
124
+ expect(roundedTargetY).toEqual(80.8);
125
+ });
126
+ });
127
+ describe('onKeyDown repeat handling (native scroll mode)', function () {
114
128
  beforeEach(function () {
115
129
  jest.useFakeTimers();
116
130
  mockPlatform = {
@@ -121,195 +135,125 @@ describe('useScroll', function () {
121
135
  jest.runOnlyPendingTimers();
122
136
  jest.useRealTimers();
123
137
  });
124
- test('should scale itemSize when ri.scale(1) changes from 1 to 2', function () {
125
- mockRiScale = jest.fn(function (val) {
126
- return val;
127
- });
128
- var itemSize = {
129
- minWidth: 100,
130
- minHeight: 50
131
- };
132
- var mocks = createMockRefs();
133
- var props = _objectSpread(_objectSpread({
134
- itemRenderer: jest.fn(),
135
- itemSize: itemSize,
138
+ function createNativeScrollProps(mocks) {
139
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
140
+ return _objectSpread(_objectSpread({
136
141
  direction: 'vertical',
137
- scrollMode: 'translate'
142
+ scrollMode: 'native'
138
143
  }, mocks), {}, {
139
144
  assignProperties: jest.fn(),
140
145
  horizontalScrollbar: 'auto',
141
146
  verticalScrollbar: 'auto'
147
+ }, extra);
148
+ }
149
+ test('should forward onKeyDown event when key is not repeated', function () {
150
+ var mocks = createMockRefs();
151
+ var onKeyDown = jest.fn();
152
+ var props = createNativeScrollProps(mocks, {
153
+ onKeyDown: onKeyDown
142
154
  });
143
155
  (0, _react.renderHook)(function () {
144
156
  return (0, _useScroll.useScrollBase)(props);
145
157
  });
146
- mockRiScale = jest.fn(function () {
147
- return 2;
148
- });
149
158
 
150
159
  // eslint-disable-next-line testing-library/no-unnecessary-act
151
160
  (0, _react.act)(function () {
152
- (0, _react.fireEvent)(window, new Event('resize'));
153
- jest.runAllTimers();
161
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
162
+ keyCode: 40,
163
+ repeat: false
164
+ });
154
165
  });
155
- expect(itemSize.minWidth).toBe(200);
156
- expect(itemSize.minHeight).toBe(100);
166
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
157
167
  });
158
- test('should NOT scale when ri.scale(1) remains unchanged', function () {
159
- mockRiScale = jest.fn(function (val) {
160
- return val;
161
- });
162
- var itemSize = {
163
- minWidth: 100,
164
- minHeight: 50
165
- };
168
+ test('should not forward onKeyDown event when arrowKey is repeated and lastInputType is arrowKey', function () {
166
169
  var mocks = createMockRefs();
167
- var props = _objectSpread(_objectSpread({
168
- itemRenderer: jest.fn(),
169
- itemSize: itemSize,
170
- direction: 'vertical',
171
- scrollMode: 'translate'
172
- }, mocks), {}, {
173
- assignProperties: jest.fn(),
174
- horizontalScrollbar: 'auto',
175
- verticalScrollbar: 'auto'
170
+ var onKeyDown = jest.fn();
171
+ var scrollContainerHandle = null;
172
+ var props = createNativeScrollProps(mocks, {
173
+ onKeyDown: onKeyDown,
174
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
175
+ scrollContainerHandle = handle;
176
+ }
176
177
  });
177
178
  (0, _react.renderHook)(function () {
178
179
  return (0, _useScroll.useScrollBase)(props);
179
180
  });
180
181
 
182
+ // Set lastInputType to arrowKey via the exposed themeScrollContainerHandle
183
+ (0, _react.act)(function () {
184
+ if (scrollContainerHandle) {
185
+ scrollContainerHandle.lastInputType = 'arrowKey';
186
+ }
187
+ });
188
+
181
189
  // eslint-disable-next-line testing-library/no-unnecessary-act
182
190
  (0, _react.act)(function () {
183
- (0, _react.fireEvent)(window, new Event('resize'));
184
- jest.runAllTimers();
191
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
192
+ keyCode: 40,
193
+ repeat: true
194
+ });
185
195
  });
186
- expect(itemSize.minWidth).toBe(100);
187
- expect(itemSize.minHeight).toBe(50);
196
+ expect(onKeyDown).not.toHaveBeenCalled();
188
197
  });
189
- test('should NOT scale when minWidth is missing', function () {
190
- mockRiScale = jest.fn(function (val) {
191
- return val;
192
- });
193
- var itemSize = {
194
- minHeight: 50
195
- };
198
+ test('should not forward onKeyDown event when pageKey is repeated and lastInputType is pageKey', function () {
196
199
  var mocks = createMockRefs();
197
- var props = _objectSpread(_objectSpread({
198
- itemRenderer: jest.fn(),
199
- itemSize: itemSize,
200
- direction: 'vertical',
201
- scrollMode: 'translate'
202
- }, mocks), {}, {
203
- assignProperties: jest.fn(),
204
- horizontalScrollbar: 'auto',
205
- verticalScrollbar: 'auto'
200
+ var onKeyDown = jest.fn();
201
+ var scrollContainerHandle = null;
202
+ var props = createNativeScrollProps(mocks, {
203
+ onKeyDown: onKeyDown,
204
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
205
+ scrollContainerHandle = handle;
206
+ }
206
207
  });
207
208
  (0, _react.renderHook)(function () {
208
209
  return (0, _useScroll.useScrollBase)(props);
209
210
  });
210
- mockRiScale = jest.fn(function () {
211
- return 2;
211
+
212
+ // Set lastInputType to pageKey via the exposed themeScrollContainerHandle
213
+ (0, _react.act)(function () {
214
+ if (scrollContainerHandle) {
215
+ scrollContainerHandle.lastInputType = 'pageKey';
216
+ }
212
217
  });
213
218
 
214
219
  // eslint-disable-next-line testing-library/no-unnecessary-act
215
220
  (0, _react.act)(function () {
216
- (0, _react.fireEvent)(window, new Event('resize'));
217
- jest.runAllTimers();
221
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
222
+ keyCode: 33,
223
+ repeat: true
224
+ });
218
225
  });
219
- expect(itemSize.minHeight).toBe(50);
220
- expect(itemSize.minWidth).toBeUndefined();
226
+ expect(onKeyDown).not.toHaveBeenCalled();
221
227
  });
222
- test('should NOT scale when minHeight is missing', function () {
223
- mockRiScale = jest.fn(function (val) {
224
- return val;
225
- });
226
- var itemSize = {
227
- minWidth: 100
228
- };
228
+ test('should forward onKeyDown event when repeat is true but lastInputType is neither arrowKey nor pageKey', function () {
229
229
  var mocks = createMockRefs();
230
- var props = _objectSpread(_objectSpread({
231
- itemRenderer: jest.fn(),
232
- itemSize: itemSize,
233
- direction: 'vertical',
234
- scrollMode: 'translate'
235
- }, mocks), {}, {
236
- assignProperties: jest.fn(),
237
- horizontalScrollbar: 'auto',
238
- verticalScrollbar: 'auto'
230
+ var onKeyDown = jest.fn();
231
+ var scrollContainerHandle = null;
232
+ var props = createNativeScrollProps(mocks, {
233
+ onKeyDown: onKeyDown,
234
+ setScrollContainerHandle: function setScrollContainerHandle(handle) {
235
+ scrollContainerHandle = handle;
236
+ }
239
237
  });
240
238
  (0, _react.renderHook)(function () {
241
239
  return (0, _useScroll.useScrollBase)(props);
242
240
  });
243
- mockRiScale = jest.fn(function () {
244
- return 2;
241
+
242
+ // Set lastInputType to wheel (not arrowKey or pageKey)
243
+ (0, _react.act)(function () {
244
+ if (scrollContainerHandle) {
245
+ scrollContainerHandle.lastInputType = 'wheel';
246
+ }
245
247
  });
246
248
 
247
249
  // eslint-disable-next-line testing-library/no-unnecessary-act
248
250
  (0, _react.act)(function () {
249
- (0, _react.fireEvent)(window, new Event('resize'));
250
- jest.runAllTimers();
251
+ _react.fireEvent.keyDown(mocks.scrollContainerRef.current, {
252
+ keyCode: 40,
253
+ repeat: true
254
+ });
251
255
  });
252
- expect(itemSize.minWidth).toBe(100);
253
- expect(itemSize.minHeight).toBeUndefined();
254
- });
255
- });
256
- describe('Rounding target scroll position', function () {
257
- beforeEach(function () {
258
- jest.resetModules(); // important! clears cached modules
259
- });
260
- test('should round target position upwards when target is bigger than current position', function () {
261
- mockPlatform = {
262
- chrome: 132
263
- };
264
- var _require = require('../useScroll'),
265
- roundTarget = _require.roundTarget;
266
- var currentPosition = {
267
- scrollPos: {
268
- left: 100,
269
- top: 100
270
- }
271
- };
272
- var _roundTarget = roundTarget(currentPosition, 120.5, 120.4),
273
- roundedTargetX = _roundTarget.roundedTargetX,
274
- roundedTargetY = _roundTarget.roundedTargetY;
275
- expect(roundedTargetX).toEqual(121);
276
- expect(roundedTargetY).toEqual(121);
277
- });
278
- test('should round target position downwards when target is bi than current position', function () {
279
- mockPlatform = {
280
- chrome: 132
281
- };
282
- var _require2 = require('../useScroll'),
283
- roundTarget = _require2.roundTarget;
284
- var currentPosition = {
285
- scrollPos: {
286
- left: 100,
287
- top: 100
288
- }
289
- };
290
- var _roundTarget2 = roundTarget(currentPosition, 90.4, 80.8),
291
- roundedTargetX = _roundTarget2.roundedTargetX,
292
- roundedTargetY = _roundTarget2.roundedTargetY;
293
- expect(roundedTargetX).toEqual(90);
294
- expect(roundedTargetY).toEqual(80);
295
- });
296
- test('should not round target position when chrome <= 120', function () {
297
- mockPlatform = {
298
- chrome: 119
299
- };
300
- var _require3 = require('../useScroll'),
301
- roundTarget = _require3.roundTarget;
302
- var currentPosition = {
303
- scrollPos: {
304
- left: 100,
305
- top: 100
306
- }
307
- };
308
- var _roundTarget3 = roundTarget(currentPosition, 90.4, 80.8),
309
- roundedTargetX = _roundTarget3.roundedTargetX,
310
- roundedTargetY = _roundTarget3.roundedTargetY;
311
- expect(roundedTargetX).toEqual(90.4);
312
- expect(roundedTargetY).toEqual(80.8);
256
+ expect(onKeyDown).toHaveBeenCalledTimes(1);
313
257
  });
314
258
  });
315
259
  });
@@ -207,10 +207,6 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
207
207
  _useState4 = _slicedToArray(_useState3, 2),
208
208
  isVerticalScrollbarVisible = _useState4[0],
209
209
  setIsVerticalScrollbarVisible = _useState4[1];
210
- var _useState5 = (0, _react.useState)(_resolution["default"].scale(1)),
211
- _useState6 = _slicedToArray(_useState5, 2),
212
- riRatio = _useState6[0],
213
- setRiRatio = _useState6[1];
214
210
  var mutableRef = (0, _react.useRef)({
215
211
  overscrollEnabled: !!props.applyOverscrollEffect,
216
212
  // Enable the early bail out of repeated scrolling to the same position
@@ -437,31 +433,8 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
437
433
  }, [forceUpdate, scrollContentHandle]);
438
434
  // scrollMode 'translate' ]]
439
435
 
440
- var scrollContentProps = props.itemRenderer ?
441
- // If the child component is a VirtualList
442
- {
443
- childProps: childProps,
444
- clientSize: clientSize,
445
- dataSize: dataSize,
446
- itemRenderer: itemRenderer,
447
- itemSize: itemSize,
448
- itemSizes: itemSizes,
449
- overhang: overhang,
450
- pageScroll: pageScroll,
451
- spacing: spacing,
452
- wrap: wrap
453
- } : {
454
- children: children
455
- };
456
436
  function handleResizeWindow() {
457
437
  var propsHandleResizeWindow = props.handleResizeWindow;
458
- if (_resolution["default"].scale(1) !== riRatio) {
459
- if (scrollContentProps.itemSize.minWidth && scrollContentProps.itemSize.minHeight) {
460
- scrollContentProps.itemSize.minWidth *= _resolution["default"].scale(1) / riRatio;
461
- scrollContentProps.itemSize.minHeight *= _resolution["default"].scale(1) / riRatio;
462
- setRiRatio(_resolution["default"].scale(1));
463
- }
464
- }
465
438
 
466
439
  // `handleSize` in `ui/resolution.ResolutionDecorator` should be executed first.
467
440
  setTimeout(function () {
@@ -877,7 +850,9 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
877
850
  var _props$preventScroll;
878
851
  (_props$preventScroll = props.preventScroll) === null || _props$preventScroll === void 0 || _props$preventScroll.call(props, ev);
879
852
  mutableRef.current.repeat = ev.repeat;
880
- if (ev.repeat && mutableRef.current.lastInputType === 'arrowKey') return;
853
+ var isArrowKey = mutableRef.current.lastInputType === 'arrowKey';
854
+ var isPageKey = mutableRef.current.lastInputType === 'pageKey';
855
+ if (ev.repeat && (isArrowKey || isPageKey)) return;
881
856
  (0, _handle.forward)('onKeyDown', ev, props);
882
857
  }
883
858
  }
@@ -1539,6 +1514,22 @@ var useScrollBase = exports.useScrollBase = function useScrollBase(props) {
1539
1514
  onFlick: onFlick,
1540
1515
  onTouchStart: scrollMode === 'native' ? onTouchStart : null // scrollMode 'native'
1541
1516
  }));
1517
+ var scrollContentProps = props.itemRenderer ?
1518
+ // If the child component is a VirtualList
1519
+ {
1520
+ childProps: childProps,
1521
+ clientSize: clientSize,
1522
+ dataSize: dataSize,
1523
+ itemRenderer: itemRenderer,
1524
+ itemSize: itemSize,
1525
+ itemSizes: itemSizes,
1526
+ overhang: overhang,
1527
+ pageScroll: pageScroll,
1528
+ spacing: spacing,
1529
+ wrap: wrap
1530
+ } : {
1531
+ children: children
1532
+ };
1542
1533
  assignProperties('scrollContentProps', _objectSpread(_objectSpread({}, scrollContentProps), {}, {
1543
1534
  cbScrollTo: scrollTo,
1544
1535
  className: [_useScrollModule["default"].scrollFill],