oolib 2.206.2 → 2.206.3
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.
|
@@ -6,6 +6,11 @@ var getKeyCode_1 = require("../../../../utils/getKeyCode");
|
|
|
6
6
|
var useKeyboardControl = function (_a) {
|
|
7
7
|
var showOptions = _a.showOptions, handleHideOptions = _a.handleHideOptions, optionsWrapperRef = _a.optionsWrapperRef, handleSelect = _a.handleSelect, options = _a.options, searchString = _a.searchString, id = _a.id;
|
|
8
8
|
var _b = (0, react_1.useState)(-1), focussedOp = _b[0], setFocussedOp = _b[1];
|
|
9
|
+
var hasMountedRef = (0, react_1.useRef)(false);
|
|
10
|
+
// Track if component has mounted to prevent initial scroll
|
|
11
|
+
(0, react_1.useEffect)(function () {
|
|
12
|
+
hasMountedRef.current = true;
|
|
13
|
+
}, []);
|
|
9
14
|
// if search string is not empty, then reset focussedOp to first op
|
|
10
15
|
// else set it to minus 1
|
|
11
16
|
(0, react_1.useEffect)(function () {
|
|
@@ -21,12 +26,6 @@ var useKeyboardControl = function (_a) {
|
|
|
21
26
|
}, [showOptions]);
|
|
22
27
|
(0, react_1.useEffect)(function () {
|
|
23
28
|
var handleKeyDown = function (e) {
|
|
24
|
-
if (!showOptions)
|
|
25
|
-
return;
|
|
26
|
-
/**
|
|
27
|
-
* dont prevent default outside the condition, else
|
|
28
|
-
* all other key actions stop working..
|
|
29
|
-
*/
|
|
30
29
|
var code = (0, getKeyCode_1.getKeyCode)(e);
|
|
31
30
|
if (code === 'Enter') {
|
|
32
31
|
if (options[focussedOp])
|
|
@@ -50,6 +49,9 @@ var useKeyboardControl = function (_a) {
|
|
|
50
49
|
return function () { return window.removeEventListener('keydown', handleKeyDown); };
|
|
51
50
|
});
|
|
52
51
|
var scrollFocussedOpIntoView = function (el) {
|
|
52
|
+
// Prevent automatic scrolling during initial render
|
|
53
|
+
if (!hasMountedRef.current || !showOptions)
|
|
54
|
+
return;
|
|
53
55
|
var _a = el.getBoundingClientRect(), elBottom = _a.bottom, elTop = _a.top;
|
|
54
56
|
var _b = optionsWrapperRef.current.getBoundingClientRect(), opsWrapperBottom = _b.bottom, opsWrapperTop = _b.top;
|
|
55
57
|
if (elBottom > opsWrapperBottom) {
|