Skip to content

Commit 8466914

Browse files
committed
Fix project title when empty
1 parent 1de0912 commit 8466914

File tree

1 file changed

+16
-3
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Title

1 file changed

+16
-3
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Title/Title.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import { observer } from 'mobx-react-lite';
33
import { getSandboxName } from '@codesandbox/common/lib/utils/get-sandbox-name';
4+
import { ESC, ENTER } from '@codesandbox/common/lib/utils/keycodes';
45
import { useSignals, useStore } from 'app/store';
56
import { WorkspaceInputContainer } from '../../elements';
67
import { EditPen } from '../elements';
@@ -32,7 +33,7 @@ export const Title = observer<ITitleProps>(({ editable }) => {
3233
el.focus();
3334
}
3435
}}
35-
value={title || getSandboxName(currentSandbox)}
36+
value={title}
3637
onChange={event => {
3738
valueChanged({
3839
field: 'title',
@@ -44,17 +45,29 @@ export const Title = observer<ITitleProps>(({ editable }) => {
4445
setEditing(false);
4546
}}
4647
onKeyUp={event => {
47-
if (event.keyCode === 13) {
48+
if (event.keyCode === ENTER) {
4849
sandboxInfoUpdated();
4950
setEditing(false);
51+
} else if (event.keyCode === ESC) {
52+
setEditing(false);
5053
}
5154
}}
5255
/>
5356
</WorkspaceInputContainer>
5457
) : (
5558
<SandboxTitle>
5659
{getSandboxName(currentSandbox)}
57-
{editable && <EditPen onClick={() => setEditing(true)} />}
60+
{editable && (
61+
<EditPen
62+
onClick={() => {
63+
valueChanged({
64+
field: 'title',
65+
value: getSandboxName(currentSandbox),
66+
});
67+
setEditing(true);
68+
}}
69+
/>
70+
)}
5871
</SandboxTitle>
5972
);
6073
});

0 commit comments

Comments
 (0)