Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 1ddc5d1

Browse files
committed
tabIndex and arrowControls
1 parent 42f94e8 commit 1ddc5d1

File tree

12 files changed

+91
-12
lines changed

12 files changed

+91
-12
lines changed

src/components/Table.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import HeaderContextMenuWrapper from "components/contextMenu/HeaderContextMenuWrapper";
4646
import TableActions from "components/tableActions/TableActions";
4747
import PaginationTable from "components/navbar/PaginationTable";
48+
import onKeyDownArrowKeys from "./behavior/ArrowKeysNavigation";
4849

4950
const defaultColumn: Partial<ColumnDef<RowDataType>> = {
5051
minSize: DatabaseLimits.MIN_COLUMN_WIDTH,
@@ -221,6 +222,7 @@ export function Table(tableData: TableDataType) {
221222
onMouseOver={obsidianMdLinksOnMouseOverMenuCallback(view)}
222223
/** Obsidian to open an internal link in a new pane */
223224
onClick={obsidianMdLinksOnClickCallback(stateManager, view, filePath)}
225+
onKeyDown={onKeyDownArrowKeys}
224226
style={{
225227
width: table.getCenterTotalSize(),
226228
}}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { c } from "helpers/StylesHelper";
2+
import { KeyboardEventHandler } from "react";
3+
4+
type TabIndexElement = HTMLDivElement | HTMLSpanElement;
5+
6+
const onKeyDownArrowKeys: KeyboardEventHandler<HTMLDivElement> = (event) => {
7+
const currentInput = activeDocument.activeElement;
8+
if (currentInput === null || !currentInput.classList.contains(c('tabIndex'))) return;
9+
10+
const currentTd = currentInput.parentElement;
11+
const currentTr = currentTd.parentElement;
12+
const index = Array.from(currentTr.children).indexOf(currentTd);
13+
14+
switch (event.key) {
15+
case "ArrowLeft":
16+
// Left pressed
17+
const TdLeft = currentTd.previousElementSibling;
18+
if (!TdLeft) break;
19+
const TdLeftTabIndex = TdLeft.getElementsByClassName(c('tabIndex'))[0] as TabIndexElement;
20+
if (!TdLeftTabIndex) break;
21+
TdLeftTabIndex.focus();
22+
break;
23+
case "ArrowRight":
24+
// Right pressed
25+
const TdRight = currentTd.nextElementSibling;
26+
if (!TdRight) break;
27+
const TdRightTabIndex = TdRight.getElementsByClassName(c('tabIndex'))[0] as TabIndexElement;
28+
if (!TdRightTabIndex) break;
29+
TdRightTabIndex.focus();
30+
break;
31+
case "ArrowUp":
32+
// Up pressed
33+
const TrUp = currentTr
34+
.previousElementSibling
35+
?.children;
36+
if (!TrUp) break;
37+
38+
const TdUp = (Array.from(TrUp)[index]
39+
.getElementsByClassName(c('tabIndex'))[0] as TabIndexElement);
40+
41+
if (!TdUp) break;
42+
TdUp.focus();
43+
break;
44+
case "ArrowDown":
45+
// Down pressed
46+
const TrDown = currentTr
47+
.nextElementSibling
48+
?.children;
49+
if (TrDown === undefined) break;
50+
51+
const TdDown = (Array.from(TrDown)[index]
52+
.getElementsByClassName(c('tabIndex'))[0] as TabIndexElement);
53+
54+
if (TdDown === undefined) break;
55+
TdDown.focus();
56+
break;
57+
}
58+
}
59+
60+
export default onKeyDownArrowKeys;

src/components/cellTypes/CalendarCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const CalendarCell = (calendarProps: CellComponentProps) => {
100100
/>
101101
) : (
102102
<span
103-
className={`${c("calendar")}`}
103+
className={`${c("calendar tabIndex")}`}
104104
onClick={handleSpanOnClick}
105105
style={{ width: column.getSize() }}
106106
onKeyDown={(e) => {

src/components/cellTypes/CalendarTimeCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const CalendarTimeCell = (calendarTimeProps: CellComponentProps) => {
101101
/>
102102
) : (
103103
<span
104-
className={`${c("calendar")}`}
104+
className={`${c("calendar tabIndex")}`}
105105
style={{ width: column.getSize() }}
106106
onClick={handleSpanOnClick}
107107
onKeyDown={(e) => {

src/components/cellTypes/CheckboxCell.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ function CheckboxCell(props: CellComponentProps) {
4444
};
4545

4646
return (
47-
<div key={`checkbox-div-${row.index}`} className={`${c("checkbox")}`}>
47+
<div
48+
key={`checkbox-div-${row.index}`}
49+
className={`${c("checkbox tabIndex")}`}
50+
>
4851
<input
4952
type="checkbox"
5053
checked={checkboxCell}

src/components/cellTypes/NumberCell.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ const NumberCell = (props: CellComponentProps) => {
9393
) : (
9494
<span
9595
className={c(
96-
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
96+
getAlignmentClassname(
97+
tableColumn.config,
98+
configInfo.getLocalSettings(),
99+
["tabIndex"]
100+
)
97101
)}
98102
onDoubleClick={handleEditableOnclick}
99103
style={{ width: column.getSize() }}

src/components/cellTypes/RelationCell.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ const RelationCell = (mdProps: CellComponentProps) => {
111111
onClick={handleOnClick}
112112
style={{ width: column.getSize() }}
113113
className={c(
114-
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
114+
getAlignmentClassname(
115+
tableColumn.config,
116+
configInfo.getLocalSettings(),
117+
["tabIndex"]
118+
)
115119
)}
116120
onKeyDown={(e) => {
117121
if (e.key === "Enter") {

src/components/cellTypes/SelectCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ const SelectCell = (popperProps: CellComponentProps) => {
138138
className={c(
139139
getAlignmentClassname(
140140
tableColumn.config,
141-
configInfo.getLocalSettings()
141+
configInfo.getLocalSettings(),
142+
["tabIndex"]
142143
)
143144
)}
144145
onClick={() => setShowSelect(true)}

src/components/cellTypes/TagsCell.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ const TagsCell = (tagsProps: CellComponentProps) => {
142142
className={c(
143143
getAlignmentClassname(
144144
tableColumn.config,
145-
configInfo.getLocalSettings()
146-
).concat(" tags-container")
145+
configInfo.getLocalSettings(),
146+
["tabIndex", "tags-container"]
147+
)
147148
)}
148149
onClick={() => setShowSelectTags(true)}
149150
style={{ width: column.getSize() }}

src/components/cellTypes/TextCell.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ const TextCell = (props: CellComponentProps) => {
9797
}}
9898
style={{ width: column.getSize() }}
9999
className={c(
100-
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
100+
getAlignmentClassname(
101+
tableColumn.config,
102+
configInfo.getLocalSettings(),
103+
["tabIndex"]
104+
)
101105
)}
102106
tabIndex={0}
103107
/>

0 commit comments

Comments
 (0)