feat: support enter to create workspace
This commit is contained in:
@@ -20,6 +20,12 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
onClose({ workspaceId: workspace.id });
|
onClose({ workspaceId: workspace.id });
|
||||||
setActiveWorkspace(workspace);
|
setActiveWorkspace(workspace);
|
||||||
};
|
};
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
// 👇 Get input value
|
||||||
|
handleCreateWorkspace();
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Modal open={open} onClose={onClose}>
|
<Modal open={open} onClose={onClose}>
|
||||||
@@ -40,6 +46,7 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
just one person or together as a team.
|
just one person or together as a team.
|
||||||
</p>
|
</p>
|
||||||
<Input
|
<Input
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
setWorkspaceName(value);
|
setWorkspaceName(value);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export const WorkspaceAvatar = (props: IWorkspaceAvatar) => {
|
|||||||
background: stringToColour(props.name || 'AFFiNE'),
|
background: stringToColour(props.name || 'AFFiNE'),
|
||||||
borderRadius: '50%',
|
borderRadius: '50%',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
lineHeight: sizeStr,
|
// Let the text inside the avatar be absolutely in the play
|
||||||
|
lineHeight: size - 2 + '[x',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(props.name || 'AFFiNE').substring(0, 1)}
|
{(props.name || 'AFFiNE').substring(0, 1)}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type inputProps = {
|
|||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
onBlur?: (e: any) => void;
|
onBlur?: (e: any) => void;
|
||||||
|
onKeyDown?: (e: any) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Input = (props: inputProps) => {
|
export const Input = (props: inputProps) => {
|
||||||
@@ -23,6 +24,7 @@ export const Input = (props: inputProps) => {
|
|||||||
width = 260,
|
width = 260,
|
||||||
onChange,
|
onChange,
|
||||||
onBlur,
|
onBlur,
|
||||||
|
onKeyDown,
|
||||||
} = props;
|
} = props;
|
||||||
const [value, setValue] = useState<string>(valueProp || '');
|
const [value, setValue] = useState<string>(valueProp || '');
|
||||||
const handleChange: InputHTMLAttributes<HTMLInputElement>['onChange'] = e => {
|
const handleChange: InputHTMLAttributes<HTMLInputElement>['onChange'] = e => {
|
||||||
@@ -37,6 +39,10 @@ export const Input = (props: inputProps) => {
|
|||||||
const handleBlur: InputHTMLAttributes<HTMLInputElement>['onBlur'] = e => {
|
const handleBlur: InputHTMLAttributes<HTMLInputElement>['onBlur'] = e => {
|
||||||
onBlur && onBlur(e);
|
onBlur && onBlur(e);
|
||||||
};
|
};
|
||||||
|
const handleKeyDown: InputHTMLAttributes<HTMLInputElement>['onKeyDown'] =
|
||||||
|
e => {
|
||||||
|
onKeyDown && onKeyDown(e);
|
||||||
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(valueProp || '');
|
setValue(valueProp || '');
|
||||||
}, [valueProp]);
|
}, [valueProp]);
|
||||||
@@ -50,6 +56,7 @@ export const Input = (props: inputProps) => {
|
|||||||
minLength={minLength}
|
minLength={minLength}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
></StyledInput>
|
></StyledInput>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user