Skip to content

Commit

Permalink
Add search input focus and save shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
jonandernovella committed Aug 5, 2022
1 parent 1e948a6 commit cc03327
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/QuickAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export const QuickAdd = ({
addIssueActivity,
toastList,
onToastListUpdate,
issueInputRef,
}: {
addIssueActivity: (pair: IssueActivityPair) => void;
toastList: ToastMsg[];
onToastListUpdate: (newToast: ToastMsg) => void;
issueInutRef: React.RefObject<HTMLInputElement>;
}) => {
const [activities, setActivities] = useState<IdName[]>([]);
const [issue, setIssue] = useState<Issue>(null);
Expand Down Expand Up @@ -204,7 +206,6 @@ export const QuickAdd = ({

const suggestionsRef = useRef(null);
useEscaper(suggestionsRef, handleHideAutocomplete);
const issueInputRef = useRef(null);

const handleInputToAutocompleteFocus = (event: any) => {
event.preventDefault();
Expand Down Expand Up @@ -254,6 +255,7 @@ export const QuickAdd = ({
<div className="row">
<input
id="input-issue"
aria-keyshortcuts="ctrl+a"
ref={issueInputRef}
autoComplete="off"
className={getSearchClasses()}
Expand Down
24 changes: 21 additions & 3 deletions frontend/src/pages/Report.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useRef } from "react";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import {
format as formatDate,
Expand Down Expand Up @@ -651,6 +651,8 @@ export const Report = () => {

if (context.user === null) return <></>;

const issueInputRef = useRef(null);

// Main content
return (
<>
Expand Down Expand Up @@ -680,7 +682,18 @@ export const Report = () => {
/>
<HeaderUser username={context.user ? context.user.login : ""} />
</header>
<main className="spreadsheet">
<main
className="spreadsheet"
onKeyDown={(e) => {
if (e.key.toLowerCase() === "s" && e.ctrlKey) {
e.preventDefault();
handleSave();
} else if (e.key.toLowerCase() === "a" && e.ctrlKey) {
e.preventDefault();
issueInputRef.current.focus();
}
}}
>
{favorites && favorites.length > 0 && (
<DragDropContext onDragEnd={onDragEnd}>
<section className="favorites-container">
Expand Down Expand Up @@ -858,6 +871,7 @@ export const Report = () => {
addIssueActivity={addIssueActivityHandler}
toastList={toastList}
onToastListUpdate={handleToastListUpdate}
issueInputRef={issueInputRef}
></QuickAdd>
</div>
{toastList.length > 0 && (
Expand All @@ -869,7 +883,11 @@ export const Report = () => {
<p role="status">⚠ You have unsaved changes</p>
)}
</div>
<button className="basic-button save-button" onClick={handleSave}>
<button
className="basic-button save-button"
aria-keyshortcuts="ctrl+s"
onClick={handleSave}
>
Save changes
</button>
</div>
Expand Down

0 comments on commit cc03327

Please sign in to comment.