fix(core): sync list titles in sidebar (#6157)
This commit is contained in:
@@ -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 Input from '../../ui/input';
|
||||||
import { Menu } from '../../ui/menu';
|
import { Menu } from '../../ui/menu';
|
||||||
@@ -15,10 +16,24 @@ export const RenameModal = ({
|
|||||||
currentName: string;
|
currentName: string;
|
||||||
}) => {
|
}) => {
|
||||||
const [value, setValue] = useState(currentName);
|
const [value, setValue] = useState(currentName);
|
||||||
|
|
||||||
const handleRename = useCallback(() => {
|
const handleRename = useCallback(() => {
|
||||||
onRename(value);
|
onRename(value);
|
||||||
onOpenChange(false);
|
onOpenChange(false);
|
||||||
}, [onOpenChange, onRename, value]);
|
}, [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 (
|
return (
|
||||||
<Menu
|
<Menu
|
||||||
rootOptions={{
|
rootOptions={{
|
||||||
@@ -33,9 +48,10 @@ export const RenameModal = ({
|
|||||||
items={
|
items={
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
defaultValue={value}
|
value={value}
|
||||||
onChange={setValue}
|
onChange={setValue}
|
||||||
onEnter={handleRename}
|
onEnter={handleRename}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
data-testid="rename-modal-input"
|
data-testid="rename-modal-input"
|
||||||
style={{ width: 220, height: 34 }}
|
style={{ width: 220, height: 34 }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export const OperationItems = ({
|
|||||||
: []),
|
: []),
|
||||||
|
|
||||||
{
|
{
|
||||||
element: <MenuSeparator />,
|
element: <MenuSeparator key="menu-separator" />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: (
|
icon: (
|
||||||
|
|||||||
Reference in New Issue
Block a user