Add tests for CreateFileModal component and improve form handling

This commit is contained in:
2025-05-29 22:03:28 +02:00
parent e01ae5b815
commit 2964963f98
2 changed files with 425 additions and 1 deletions

View File

@@ -12,12 +12,19 @@ const CreateFileModal: React.FC<CreateFileModalProps> = ({ onCreateFile }) => {
const handleSubmit = async (): Promise<void> => {
if (fileName) {
await onCreateFile(fileName);
await onCreateFile(fileName.trim());
setFileName('');
setNewFileModalVisible(false);
}
};
const handleKeyDown = (event: React.KeyboardEvent): void => {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
void handleSubmit();
}
};
return (
<Modal
opened={newFileModalVisible}
@@ -29,9 +36,11 @@ const CreateFileModal: React.FC<CreateFileModalProps> = ({ onCreateFile }) => {
<Box maw={400} mx="auto">
<TextInput
label="File Name"
type="text"
placeholder="Enter file name"
value={fileName}
onChange={(event) => setFileName(event.currentTarget.value)}
onKeyDown={handleKeyDown}
mb="md"
w="100%"
/>