ehscan-react-components 0.1.35 → 0.1.36
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 +17 -10
- package/package.json +1 -1
package/dist/DropDown.js
CHANGED
|
@@ -4,25 +4,32 @@ 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) {
|
|
@@ -110,5 +117,5 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
110
117
|
top: position.top,
|
|
111
118
|
left: position.left,
|
|
112
119
|
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))) })] }))] }));
|
|
120
|
+
}, 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
121
|
});
|