mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-09 01:09:49 +03:00
fix: autofocus (#1614)
Co-authored-by: VictorNanka <victornanka@gmail.com>
This commit is contained in:
parent
c00d39f929
commit
1bbb0aee4b
@ -68,6 +68,11 @@ export const WorkspaceDeleteModal = ({
|
|||||||
)}
|
)}
|
||||||
<StyledInputContent>
|
<StyledInputContent>
|
||||||
<Input
|
<Input
|
||||||
|
ref={ref => {
|
||||||
|
if (ref) {
|
||||||
|
setTimeout(() => ref.focus(), 0);
|
||||||
|
}
|
||||||
|
}}
|
||||||
onChange={setDeleteStr}
|
onChange={setDeleteStr}
|
||||||
data-testid="delete-workspace-input"
|
data-testid="delete-workspace-input"
|
||||||
placeholder={t('Placeholder of delete workspace')}
|
placeholder={t('Placeholder of delete workspace')}
|
||||||
|
@ -19,6 +19,7 @@ export const CreateWorkspaceModal = ({
|
|||||||
}: ModalProps) => {
|
}: ModalProps) => {
|
||||||
const [workspaceName, setWorkspaceName] = useState('');
|
const [workspaceName, setWorkspaceName] = useState('');
|
||||||
const isComposition = useRef(false);
|
const isComposition = useRef(false);
|
||||||
|
|
||||||
const handleCreateWorkspace = useCallback(() => {
|
const handleCreateWorkspace = useCallback(() => {
|
||||||
onCreate(workspaceName);
|
onCreate(workspaceName);
|
||||||
}, [onCreate, workspaceName]);
|
}, [onCreate, workspaceName]);
|
||||||
@ -48,6 +49,11 @@ export const CreateWorkspaceModal = ({
|
|||||||
<ContentTitle>{t('New Workspace')}</ContentTitle>
|
<ContentTitle>{t('New Workspace')}</ContentTitle>
|
||||||
<p>{t('Workspace description')}</p>
|
<p>{t('Workspace description')}</p>
|
||||||
<Input
|
<Input
|
||||||
|
ref={ref => {
|
||||||
|
if (ref) {
|
||||||
|
setTimeout(() => ref.focus(), 0);
|
||||||
|
}
|
||||||
|
}}
|
||||||
data-testid="create-workspace-input"
|
data-testid="create-workspace-input"
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
placeholder={t('Set a Workspace name')}
|
placeholder={t('Set a Workspace name')}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
import type {
|
import type {
|
||||||
FocusEventHandler,
|
FocusEventHandler,
|
||||||
|
ForwardedRef,
|
||||||
HTMLAttributes,
|
HTMLAttributes,
|
||||||
InputHTMLAttributes,
|
InputHTMLAttributes,
|
||||||
KeyboardEventHandler,
|
KeyboardEventHandler,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import { forwardRef } from 'react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { StyledInput } from './style';
|
import { StyledInput } from './style';
|
||||||
|
|
||||||
type inputProps = {
|
type inputProps = {
|
||||||
value?: string;
|
value?: string;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@ -19,19 +22,23 @@ type inputProps = {
|
|||||||
onBlur?: FocusEventHandler<HTMLInputElement>;
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
||||||
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
||||||
} & Omit<HTMLAttributes<HTMLInputElement>, 'onChange'>;
|
} & Omit<HTMLAttributes<HTMLInputElement>, 'onChange'>;
|
||||||
export const Input = ({
|
|
||||||
disabled,
|
export const Input = forwardRef<HTMLInputElement, inputProps>(function Input(
|
||||||
value: valueProp,
|
{
|
||||||
placeholder,
|
disabled,
|
||||||
maxLength,
|
value: valueProp,
|
||||||
minLength,
|
placeholder,
|
||||||
height,
|
maxLength,
|
||||||
width = 260,
|
minLength,
|
||||||
onChange,
|
height,
|
||||||
onBlur,
|
width = 260,
|
||||||
onKeyDown,
|
onChange,
|
||||||
...otherProps
|
onBlur,
|
||||||
}: inputProps) => {
|
onKeyDown,
|
||||||
|
...otherProps
|
||||||
|
}: inputProps,
|
||||||
|
ref: ForwardedRef<HTMLInputElement>
|
||||||
|
) {
|
||||||
const [value, setValue] = useState<string>(valueProp || '');
|
const [value, setValue] = useState<string>(valueProp || '');
|
||||||
const handleChange: InputHTMLAttributes<HTMLInputElement>['onChange'] = e => {
|
const handleChange: InputHTMLAttributes<HTMLInputElement>['onChange'] = e => {
|
||||||
const { value } = e.target;
|
const { value } = e.target;
|
||||||
@ -51,6 +58,7 @@ export const Input = ({
|
|||||||
}, [valueProp]);
|
}, [valueProp]);
|
||||||
return (
|
return (
|
||||||
<StyledInput
|
<StyledInput
|
||||||
|
ref={ref}
|
||||||
value={value}
|
value={value}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
@ -64,4 +72,4 @@ export const Input = ({
|
|||||||
{...otherProps}
|
{...otherProps}
|
||||||
></StyledInput>
|
></StyledInput>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user