Skip to content

Commit d49885a

Browse files
committed
fix(firefox): EditableLabel reloading when pressing enter
1 parent a193c2a commit d49885a

File tree

4 files changed

+18
-76
lines changed

4 files changed

+18
-76
lines changed

apps/front-end/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
// FIXME Collaboration features not working correctly on React.StrictMode
4-
reactStrictMode: true,
4+
reactStrictMode: false,
55
};
66

77
module.exports = nextConfig;

apps/front-end/src/components/Sidebar/Category.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { registerShortcuts } from "@/lib/hotkeys";
33
import * as Accordion from "@radix-ui/react-accordion";
44
import clsx from "clsx";
55
import { usePathname, useRouter } from "next/navigation";
6-
import { KeyboardEventHandler, useState } from "react";
6+
import { KeyboardEventHandler, MouseEvent, useState } from "react";
77
import { useSnapshot } from "valtio";
88
import ContextMenu from "../ContextMenu";
99
import {
@@ -125,14 +125,21 @@ function Category({
125125
const router = useRouter();
126126
const eventHandlers = useSidebarEvents();
127127
const isActive = usePathname() === snap.href;
128+
const isEditable = Boolean(editable);
129+
130+
const handleClick = (event: MouseEvent<HTMLButtonElement>) => {
131+
if (isEditable) {
132+
event.preventDefault();
133+
event.stopPropagation();
134+
return;
135+
}
128136

129-
const handleClick = () => {
130137
eventHandlers.onSelected?.(category);
131138
router.push(snap.href);
132139
};
133140

134141
return (
135-
<Accordion.Item value={snap.id} onKeyDown={onKeyDown}>
142+
<Accordion.Item value={snap.id} onKeyDown={isEditable ? undefined : onKeyDown}>
136143
<Accordion.Header className="p-0.5">
137144
<Accordion.Trigger
138145
data-testid="sidebar-item"

apps/front-end/src/components/Sidebar/EditableLabel.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ function EditableLabel({
2828
else onRename?.(label);
2929
};
3030

31-
const handleKeyUp = (e: KeyboardEvent<HTMLInputElement>) => {
32-
e.preventDefault();
31+
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
32+
if (e.key === "Enter" || e.key === "Escape") {
33+
// Prevent parent link/trigger activation while committing edits
34+
e.preventDefault();
35+
e.stopPropagation();
36+
}
3337

3438
if (e.key === "Enter") {
3539
handleRename();
@@ -60,7 +64,7 @@ function EditableLabel({
6064
ref={inputRef}
6165
onBlur={handleRename}
6266
onChange={(e) => setLabel(e.target.value)}
63-
onKeyUp={handleKeyUp}
67+
onKeyDown={handleKeyDown}
6468
placeholder="new note name..."
6569
/>
6670
);

apps/front-end/src/config/auth-options.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)