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

Commit 42f94e8

Browse files
committed
onKeyDown events
1 parent 714fa0a commit 42f94e8

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

src/components/cellTypes/CalendarCell.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const CalendarCell = (calendarProps: CellComponentProps) => {
3939
/** state of cell value */
4040
const [showDatePicker, setShowDatePicker] = useState(false);
4141

42-
function handleSpanOnClick(event: any) {
43-
event.preventDefault();
42+
function handleSpanOnClick() {
4443
setShowDatePicker(true);
4544
}
4645

@@ -104,6 +103,13 @@ const CalendarCell = (calendarProps: CellComponentProps) => {
104103
className={`${c("calendar")}`}
105104
onClick={handleSpanOnClick}
106105
style={{ width: column.getSize() }}
106+
onKeyDown={(e) => {
107+
if (e.key === "Enter") {
108+
e.preventDefault();
109+
handleSpanOnClick();
110+
}
111+
}}
112+
tabIndex={0}
107113
>
108114
{parseLuxonDateToString(
109115
calendarCell,

src/components/cellTypes/CalendarTimeCell.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const CalendarTimeCell = (calendarTimeProps: CellComponentProps) => {
3939
/** state of cell value */
4040
const [showDatePicker, setShowDatePicker] = useState(false);
4141

42-
function handleSpanOnClick(event: any) {
43-
event.preventDefault();
42+
function handleSpanOnClick() {
4443
setShowDatePicker(true);
4544
}
4645

@@ -105,6 +104,13 @@ const CalendarTimeCell = (calendarTimeProps: CellComponentProps) => {
105104
className={`${c("calendar")}`}
106105
style={{ width: column.getSize() }}
107106
onClick={handleSpanOnClick}
107+
onKeyDown={(e) => {
108+
if (e.key === "Enter") {
109+
e.preventDefault();
110+
handleSpanOnClick();
111+
}
112+
}}
113+
tabIndex={0}
108114
>
109115
{parseLuxonDatetimeToString(
110116
calendarCell,

src/components/cellTypes/NumberCell.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CellComponentProps } from "cdm/ComponentsModel";
22
import { TableColumn } from "cdm/FolderModel";
3-
import { InputType } from "helpers/Constants";
3+
import { InputType, SUGGESTER_REGEX } from "helpers/Constants";
44
import { c, getAlignmentClassname } from "helpers/StylesHelper";
55
import React, {
66
ChangeEventHandler,
@@ -95,8 +95,17 @@ const NumberCell = (props: CellComponentProps) => {
9595
className={c(
9696
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
9797
)}
98-
onClick={handleEditableOnclick}
98+
onDoubleClick={handleEditableOnclick}
9999
style={{ width: column.getSize() }}
100+
onKeyDown={(e) => {
101+
if (SUGGESTER_REGEX.CELL_VALID_KEYDOWN.test(e.key)) {
102+
handleEditableOnclick();
103+
} else if (e.key === "Enter") {
104+
e.preventDefault();
105+
handleEditableOnclick();
106+
}
107+
}}
108+
tabIndex={0}
100109
>
101110
{(numberCell !== undefined && numberCell.toString()) || ""}
102111
</span>

src/components/cellTypes/RelationCell.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { InputType } from "helpers/Constants";
44
import { c, getAlignmentClassname } from "helpers/StylesHelper";
55
import { Notice } from "obsidian";
66
import { Link } from "obsidian-dataview";
7-
import React, { MouseEventHandler, useEffect, useRef, useState } from "react";
7+
import React, { useEffect, useRef, useState } from "react";
88
import { DataviewService } from "services/DataviewService";
99
import { ParseService } from "services/ParseService";
1010
import RelationEditor from "components/cellTypes/Editor/RelationEditor";
@@ -87,8 +87,7 @@ const RelationCell = (mdProps: CellComponentProps) => {
8787
setDirtyCell(false);
8888
};
8989

90-
const handleOnClick: MouseEventHandler<HTMLSpanElement> = (event) => {
91-
event.stopPropagation();
90+
const handleOnClick = () => {
9291
// Check if the column has a relation asotiated
9392
if (tableColumn.config.related_note_path) {
9493
setDirtyCell(true);
@@ -114,6 +113,13 @@ const RelationCell = (mdProps: CellComponentProps) => {
114113
className={c(
115114
getAlignmentClassname(tableColumn.config, configInfo.getLocalSettings())
116115
)}
116+
onKeyDown={(e) => {
117+
if (e.key === "Enter") {
118+
e.preventDefault();
119+
handleOnClick();
120+
}
121+
}}
122+
tabIndex={0}
117123
/>
118124
);
119125
};

src/components/cellTypes/SelectCell.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ const SelectCell = (popperProps: CellComponentProps) => {
143143
)}
144144
onClick={() => setShowSelect(true)}
145145
style={{ width: column.getSize() }}
146+
onKeyDown={(e) => {
147+
if (e.key === "Enter") {
148+
e.preventDefault();
149+
setShowSelect(true);
150+
}
151+
}}
152+
tabIndex={0}
146153
>
147154
{cellValue ? (
148155
<Relationship value={cellValue} backgroundColor={getColor()} />

src/components/cellTypes/TagsCell.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ const TagsCell = (tagsProps: CellComponentProps) => {
148148
onClick={() => setShowSelectTags(true)}
149149
style={{ width: column.getSize() }}
150150
key={`tags-${row.index}-${tableColumn.key}`}
151+
onKeyDown={(e) => {
152+
if (e.key === "Enter") {
153+
e.preventDefault();
154+
setShowSelectTags(true);
155+
}
156+
}}
157+
tabIndex={0}
151158
>
152159
{tagsCell ? (
153160
tagsCell

0 commit comments

Comments
 (0)