mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
fix: autofocus input field and submit on enter
This commit is contained in:
@@ -39,21 +39,30 @@ const FilePathInputModal = ({
|
|||||||
setFilePath(value)
|
setFilePath(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault()
|
||||||
|
if (hasError || !filePath) return
|
||||||
|
saveFile(filePath)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
|
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
|
||||||
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
|
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
|
||||||
Save File
|
Save File
|
||||||
</BootstrapDialogTitle>
|
</BootstrapDialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<TextField
|
<form onSubmit={handleSubmit}>
|
||||||
fullWidth
|
<TextField
|
||||||
variant="outlined"
|
fullWidth
|
||||||
label="File Path"
|
autoFocus
|
||||||
value={filePath}
|
variant="outlined"
|
||||||
onChange={handleChange}
|
label="File Path"
|
||||||
error={hasError}
|
value={filePath}
|
||||||
helperText={errorText}
|
onChange={handleChange}
|
||||||
/>
|
error={hasError}
|
||||||
|
helperText={errorText}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button variant="contained" onClick={() => setOpen(false)}>
|
<Button variant="contained" onClick={() => setOpen(false)}>
|
||||||
@@ -61,9 +70,7 @@ const FilePathInputModal = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => saveFile(filePath)}
|
||||||
saveFile(filePath)
|
|
||||||
}}
|
|
||||||
disabled={hasError || !filePath}
|
disabled={hasError || !filePath}
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ const NameInputModal = ({
|
|||||||
if (defaultName) setName(defaultName)
|
if (defaultName) setName(defaultName)
|
||||||
}, [defaultName])
|
}, [defaultName])
|
||||||
|
|
||||||
|
const handleFocus = (
|
||||||
|
event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement, Element>
|
||||||
|
) => {
|
||||||
|
if (defaultName) {
|
||||||
|
event.target.select()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const value = event.target.value
|
const value = event.target.value
|
||||||
|
|
||||||
@@ -55,21 +63,32 @@ const NameInputModal = ({
|
|||||||
setName(value)
|
setName(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault()
|
||||||
|
if (hasError || !name) return
|
||||||
|
action(name)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
|
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
|
||||||
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
|
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
|
||||||
{title}
|
{title}
|
||||||
</BootstrapDialogTitle>
|
</BootstrapDialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<TextField
|
<form onSubmit={handleSubmit}>
|
||||||
fullWidth
|
<TextField
|
||||||
variant="outlined"
|
id="input-box"
|
||||||
label={isFolder ? 'Folder Name' : 'File Name'}
|
fullWidth
|
||||||
value={name}
|
autoFocus
|
||||||
onChange={handleChange}
|
onFocus={handleFocus}
|
||||||
error={hasError}
|
variant="outlined"
|
||||||
helperText={errorText}
|
label={isFolder ? 'Folder Name' : 'File Name'}
|
||||||
/>
|
value={name}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={hasError}
|
||||||
|
helperText={errorText}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button variant="contained" onClick={() => setOpen(false)}>
|
<Button variant="contained" onClick={() => setOpen(false)}>
|
||||||
@@ -77,9 +96,7 @@ const NameInputModal = ({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => action(name)}
|
||||||
action(name)
|
|
||||||
}}
|
|
||||||
disabled={hasError || !name}
|
disabled={hasError || !name}
|
||||||
>
|
>
|
||||||
{actionLabel}
|
{actionLabel}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ const TreeViewNode = ({
|
|||||||
useState(false)
|
useState(false)
|
||||||
const [deleteConfirmationModalMessage, setDeleteConfirmationModalMessage] =
|
const [deleteConfirmationModalMessage, setDeleteConfirmationModalMessage] =
|
||||||
useState('')
|
useState('')
|
||||||
|
const [defaultInputModalName, setDefaultInputModalName] = useState('')
|
||||||
const [nameInputModalOpen, setNameInputModalOpen] = useState(false)
|
const [nameInputModalOpen, setNameInputModalOpen] = useState(false)
|
||||||
const [nameInputModalTitle, setNameInputModalTitle] = useState('')
|
const [nameInputModalTitle, setNameInputModalTitle] = useState('')
|
||||||
const [nameInputModalActionLabel, setNameInputModalActionLabel] = useState('')
|
const [nameInputModalActionLabel, setNameInputModalActionLabel] = useState('')
|
||||||
@@ -129,6 +130,7 @@ const TreeViewNode = ({
|
|||||||
setNameInputModalTitle('Add Folder')
|
setNameInputModalTitle('Add Folder')
|
||||||
setNameInputModalActionLabel('Add')
|
setNameInputModalActionLabel('Add')
|
||||||
setNameInputModalForFolder(true)
|
setNameInputModalForFolder(true)
|
||||||
|
setDefaultInputModalName('')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleNewFileItemClick = () => {
|
const handleNewFileItemClick = () => {
|
||||||
@@ -137,6 +139,7 @@ const TreeViewNode = ({
|
|||||||
setNameInputModalTitle('Add File')
|
setNameInputModalTitle('Add File')
|
||||||
setNameInputModalActionLabel('Add')
|
setNameInputModalActionLabel('Add')
|
||||||
setNameInputModalForFolder(false)
|
setNameInputModalForFolder(false)
|
||||||
|
setDefaultInputModalName('')
|
||||||
}
|
}
|
||||||
|
|
||||||
const addFileFolder = (name: string) => {
|
const addFileFolder = (name: string) => {
|
||||||
@@ -152,6 +155,7 @@ const TreeViewNode = ({
|
|||||||
setNameInputModalTitle('Rename')
|
setNameInputModalTitle('Rename')
|
||||||
setNameInputModalActionLabel('Rename')
|
setNameInputModalActionLabel('Rename')
|
||||||
setNameInputModalForFolder(node.isFolder)
|
setNameInputModalForFolder(node.isFolder)
|
||||||
|
setDefaultInputModalName(node.relativePath.split('/').pop() ?? '')
|
||||||
}
|
}
|
||||||
|
|
||||||
const renameFileFolder = (name: string) => {
|
const renameFileFolder = (name: string) => {
|
||||||
@@ -208,7 +212,7 @@ const TreeViewNode = ({
|
|||||||
action={
|
action={
|
||||||
nameInputModalActionLabel === 'Add' ? addFileFolder : renameFileFolder
|
nameInputModalActionLabel === 'Add' ? addFileFolder : renameFileFolder
|
||||||
}
|
}
|
||||||
defaultName={node.relativePath.split('/').pop()}
|
defaultName={defaultInputModalName}
|
||||||
/>
|
/>
|
||||||
<Menu
|
<Menu
|
||||||
open={contextMenu !== null}
|
open={contextMenu !== null}
|
||||||
|
|||||||
Reference in New Issue
Block a user