Skip to content

Commit

Permalink
fix(core): sync list titles in sidebar (#6157)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Mar 18, 2024
1 parent 0b0b3e0 commit 8301d82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/frontend/component/src/components/rename-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useState } from 'react';
import type { KeyboardEvent } from 'react';
import { useCallback, useEffect, useState } from 'react';

import Input from '../../ui/input';
import { Menu } from '../../ui/menu';
Expand All @@ -15,10 +16,24 @@ export const RenameModal = ({
currentName: string;
}) => {
const [value, setValue] = useState(currentName);

const handleRename = useCallback(() => {
onRename(value);
onOpenChange(false);
}, [onOpenChange, onRename, value]);

const onKeyDown = useCallback(
(e: KeyboardEvent<HTMLInputElement>) => {
if (e.key !== 'Escape') return;
if (currentName !== value) setValue(currentName);
onOpenChange(false);
},
[currentName, value, onOpenChange]
);

// Synchronize when the title is changed in the page header or title.
useEffect(() => setValue(currentName), [currentName]);

return (
<Menu
rootOptions={{
Expand All @@ -33,9 +48,10 @@ export const RenameModal = ({
items={
<Input
autoFocus
defaultValue={value}
value={value}
onChange={setValue}
onEnter={handleRename}
onKeyDown={onKeyDown}
data-testid="rename-modal-input"
style={{ width: 220, height: 34 }}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const OperationItems = ({
: []),

{
element: <MenuSeparator />,
element: <MenuSeparator key="menu-separator" />,
},
{
icon: (
Expand Down

0 comments on commit 8301d82

Please sign in to comment.