oolib 2.206.3 → 2.206.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.
|
@@ -6,11 +6,6 @@ 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
|
-
}, []);
|
|
14
9
|
// if search string is not empty, then reset focussedOp to first op
|
|
15
10
|
// else set it to minus 1
|
|
16
11
|
(0, react_1.useEffect)(function () {
|
|
@@ -26,6 +21,12 @@ var useKeyboardControl = function (_a) {
|
|
|
26
21
|
}, [showOptions]);
|
|
27
22
|
(0, react_1.useEffect)(function () {
|
|
28
23
|
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
|
+
*/
|
|
29
30
|
var code = (0, getKeyCode_1.getKeyCode)(e);
|
|
30
31
|
if (code === 'Enter') {
|
|
31
32
|
if (options[focussedOp])
|
|
@@ -49,8 +50,8 @@ var useKeyboardControl = function (_a) {
|
|
|
49
50
|
return function () { return window.removeEventListener('keydown', handleKeyDown); };
|
|
50
51
|
});
|
|
51
52
|
var scrollFocussedOpIntoView = function (el) {
|
|
52
|
-
//
|
|
53
|
-
if (!
|
|
53
|
+
// Only scroll if options are actually showing to prevent unwanted auto-scroll
|
|
54
|
+
if (!showOptions)
|
|
54
55
|
return;
|
|
55
56
|
var _a = el.getBoundingClientRect(), elBottom = _a.bottom, elTop = _a.top;
|
|
56
57
|
var _b = optionsWrapperRef.current.getBoundingClientRect(), opsWrapperBottom = _b.bottom, opsWrapperTop = _b.top;
|