🚸 Frontend create directory modal focuses text box and accepts enter key
This commit is contained in:
committed by
Anton Shepilov
parent
a054621d2e
commit
48fdad0519
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
import { CreateModalAtom } from '.';
|
import { CreateModalAtom, CreateModalAtomType } from '.';
|
||||||
import { Button } from '@atoms/button/button';
|
import { Button } from '@atoms/button/button';
|
||||||
import { Input } from '@atoms/input/input-text';
|
import { Input } from '@atoms/input/input-text';
|
||||||
import { Info } from '@atoms/text';
|
import { Info } from '@atoms/text';
|
||||||
@@ -12,26 +12,44 @@ export const CreateFolder = () => {
|
|||||||
const [loading, _] = useState<boolean>(false);
|
const [loading, _] = useState<boolean>(false);
|
||||||
const [state, setState] = useRecoilState(CreateModalAtom);
|
const [state, setState] = useRecoilState(CreateModalAtom);
|
||||||
const { create } = useDriveActions();
|
const { create } = useDriveActions();
|
||||||
|
const inputRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
const firstInput = inputRef.current && inputRef.current.querySelector("input") as HTMLInputElement;
|
||||||
|
if (firstInput)
|
||||||
|
firstInput.focus();
|
||||||
|
}, 100);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const createFolderHandler = async () => {
|
||||||
|
await create({ name, parent_id: state.parent_id, is_directory: true }, {});
|
||||||
|
setState({ ...state, open: false });
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Info>{ Languages.t('components.create_folder_modal.hint')}</Info>
|
<Info>{ Languages.t('components.create_folder_modal.hint')}</Info>
|
||||||
|
<div ref={inputRef}>
|
||||||
<Input
|
<Input
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
placeholder={ Languages.t('components.create_folder_modal.placeholder')}
|
placeholder={ Languages.t('components.create_folder_modal.placeholder')}
|
||||||
className="w-full mt-4"
|
className="w-full mt-4"
|
||||||
onChange={(e: any) => setName(e.target.value)}
|
onKeyDown={(e: any) => {
|
||||||
/>
|
if (e.keyCode === 13) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.target.value)
|
||||||
|
createFolderHandler();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onChange={(e: any) => setName(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
disabled={!name}
|
disabled={!name}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
className="mt-4 float-right"
|
className="mt-4 float-right"
|
||||||
onClick={async () => {
|
onClick={createFolderHandler}
|
||||||
await create({ name, parent_id: state.parent_id, is_directory: true }, {});
|
|
||||||
setState({ ...state, open: false });
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user