ehscan-react-components 0.1.34 → 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 CHANGED
@@ -3,6 +3,47 @@ import { useEffect, useState, useRef, forwardRef, useImperativeHandle } from "re
3
3
  export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm, maxDropDownEntries, maxDropDownHeight }, ref) => {
4
4
  const [position, setPosition] = useState({ top: 0, left: 0, width: 0, maxHeight: 0 });
5
5
  const containerRef = useRef(null);
6
+ const [tabId, setTabId] = useState(undefined);
7
+ const itemRefs = useRef([]);
8
+ useEffect(() => {
9
+ if (!openDropDown || display.length === 0)
10
+ return;
11
+ const handleKeyDown = (e) => {
12
+ if (e.key === 'ArrowDown') {
13
+ setTabId(prevTabId => {
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;
22
+ });
23
+ }
24
+ if (e.key === 'ArrowUp') {
25
+ setTabId(prevTabId => {
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;
33
+ });
34
+ }
35
+ if (e.key === "Enter" && tabId !== undefined) {
36
+ console.log('use', display[tabId]);
37
+ addItem(tabId);
38
+ setTabId(0);
39
+ }
40
+ // Add other keys here if needed
41
+ };
42
+ window.addEventListener('keydown', handleKeyDown);
43
+ return () => {
44
+ window.removeEventListener('keydown', handleKeyDown); // cleanup
45
+ };
46
+ }, [openDropDown, display, tabId]);
6
47
  useImperativeHandle(ref, () => ({
7
48
  calc: () => {
8
49
  console.log("calc");
@@ -76,5 +117,5 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
76
117
  top: position.top,
77
118
  left: position.left,
78
119
  width: position.width
79
- }, 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", onClick: () => addDropDownItem(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))) })] }))] }));
80
121
  });
@@ -123,9 +123,9 @@ export const TextAreaDropDown = ({ id, tabIndex, alwaysOpenDropDown, closeComman
123
123
  }
124
124
  };
125
125
  const blurInput = () => {
126
- setOpenDropDown(false);
127
- setNewBtn(false);
128
- setSearchTerm('');
126
+ // setOpenDropDown(false)
127
+ // setNewBtn(false)
128
+ // setSearchTerm('')
129
129
  };
130
130
  if (!tags)
131
131
  return null;
@@ -375,4 +375,8 @@ input:-webkit-autofill:active {
375
375
  min-width: 0;
376
376
  width: 100%;
377
377
  box-sizing: border-box;
378
+ }
379
+
380
+ .dropdown-item.focused{
381
+ border: 1px solid red
378
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-components",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",