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.
Files changed (2) hide show
  1. package/dist/DropDown.js +17 -10
  2. 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
- if (prevTabId === undefined || prevTabId >= display.length - 1) {
15
- return 0; // wrap to start
16
- }
17
- return prevTabId + 1; // move down
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
- if (prevTabId === undefined || prevTabId <= 0) {
23
- return display.length - 1; // wrap to end
24
- }
25
- return prevTabId - 1; // move up
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ehscan-react-components",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "components",
5
5
  "main": "dist/Components.js",
6
6
  "types": "dist/Components.d.ts",