ehscan-react-components 0.1.35 → 0.1.37
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/dist/DropDown.js +26 -11
- package/package.json +1 -1
package/dist/DropDown.js
CHANGED
|
@@ -4,31 +4,46 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
4
4
|
const [position, setPosition] = useState({ top: 0, left: 0, width: 0, maxHeight: 0 });
|
|
5
5
|
const containerRef = useRef(null);
|
|
6
6
|
const [tabId, setTabId] = useState(undefined);
|
|
7
|
+
const itemRefs = useRef([]);
|
|
7
8
|
useEffect(() => {
|
|
8
9
|
if (!openDropDown || display.length === 0)
|
|
9
10
|
return;
|
|
10
11
|
const handleKeyDown = (e) => {
|
|
11
|
-
console.log(e.key);
|
|
12
12
|
if (e.key === 'ArrowDown') {
|
|
13
13
|
setTabId(prevTabId => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
const next = prevTabId === undefined || prevTabId >= display.length - 1 ? 0 : prevTabId + 1;
|
|
16
|
+
// scroll into view
|
|
17
|
+
(_a = itemRefs.current[next]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
18
|
+
behavior: 'smooth',
|
|
19
|
+
block: 'nearest',
|
|
20
|
+
});
|
|
21
|
+
return next;
|
|
18
22
|
});
|
|
19
23
|
}
|
|
20
24
|
if (e.key === 'ArrowUp') {
|
|
21
25
|
setTabId(prevTabId => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
var _a;
|
|
27
|
+
const next = prevTabId === undefined || prevTabId <= 0 ? display.length - 1 : prevTabId - 1;
|
|
28
|
+
(_a = itemRefs.current[next]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
29
|
+
behavior: 'smooth',
|
|
30
|
+
block: 'nearest',
|
|
31
|
+
});
|
|
32
|
+
return next;
|
|
26
33
|
});
|
|
27
34
|
}
|
|
28
35
|
if (e.key === "Enter" && tabId !== undefined) {
|
|
29
36
|
console.log('use', display[tabId]);
|
|
30
37
|
addItem(tabId);
|
|
31
|
-
setTabId(
|
|
38
|
+
setTabId(prevTabId => {
|
|
39
|
+
if (prevTabId === undefined)
|
|
40
|
+
return 0;
|
|
41
|
+
if (display[prevTabId])
|
|
42
|
+
return prevTabId;
|
|
43
|
+
if (display[prevTabId - 1])
|
|
44
|
+
return prevTabId - 1;
|
|
45
|
+
return 0;
|
|
46
|
+
});
|
|
32
47
|
}
|
|
33
48
|
// Add other keys here if needed
|
|
34
49
|
};
|
|
@@ -110,5 +125,5 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
110
125
|
top: position.top,
|
|
111
126
|
left: position.left,
|
|
112
127
|
width: position.width
|
|
113
|
-
}, children: [maxDropDownEntries !== undefined && (_jsxs("div", { className: "dropdown-amount-row", children: [display.length, " / ", maxDropDownEntries, " entries"] })), _jsx("div", { className: "ext-window-dropdown-wrapper _ewb", style: { maxHeight: `${position.maxHeight}px`, }, children: display.map((item, index) => (_jsx("div", { className: `dropdown-item ${index === tabId ? 'focused' : ''}`, tabIndex: 0, onClick: () => addDropDownItem(index), onFocus: () => setTabId(index), children: _jsx(HighlightedText, { text: item, searchTerm: searchTerm }) }, index))) })] }))] }));
|
|
128
|
+
}, children: [maxDropDownEntries !== undefined && (_jsxs("div", { className: "dropdown-amount-row", children: [display.length, " / ", maxDropDownEntries, " entries"] })), _jsx("div", { className: "ext-window-dropdown-wrapper _ewb", style: { maxHeight: `${position.maxHeight}px`, }, children: display.map((item, index) => (_jsx("div", { ref: el => { itemRefs.current[index] = el; }, className: `dropdown-item ${index === tabId ? 'focused' : ''}`, tabIndex: 0, onClick: () => addDropDownItem(index), onFocus: () => setTabId(index), children: _jsx(HighlightedText, { text: item, searchTerm: searchTerm }) }, index))) })] }))] }));
|
|
114
129
|
});
|