fix: add composition checkout when input create workspace name, fixed… (#1035)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { styled } from '@affine/component';
|
import { styled } from '@affine/component';
|
||||||
import { Modal, ModalWrapper, ModalCloseButton } from '@affine/component';
|
import { Modal, ModalWrapper, ModalCloseButton } from '@affine/component';
|
||||||
import { Button } from '@affine/component';
|
import { Button } from '@affine/component';
|
||||||
import { useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { Input } from '@affine/component';
|
import { Input } from '@affine/component';
|
||||||
import { KeyboardEvent } from 'react';
|
import { KeyboardEvent } from 'react';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
@@ -18,6 +18,7 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
const [workspaceName, setWorkspaceName] = useState('');
|
const [workspaceName, setWorkspaceName] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { createWorkspace } = useWorkspaceHelper();
|
const { createWorkspace } = useWorkspaceHelper();
|
||||||
|
const isComposition = useRef(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const handleCreateWorkspace = async () => {
|
const handleCreateWorkspace = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -32,8 +33,7 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter' && workspaceName && !isComposition.current) {
|
||||||
// 👇 Get input value
|
|
||||||
handleCreateWorkspace();
|
handleCreateWorkspace();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -62,7 +62,13 @@ export const CreateWorkspaceModal = ({ open, onClose }: ModalProps) => {
|
|||||||
onChange={value => {
|
onChange={value => {
|
||||||
setWorkspaceName(value);
|
setWorkspaceName(value);
|
||||||
}}
|
}}
|
||||||
></Input>
|
onCompositionStart={() => {
|
||||||
|
isComposition.current = true;
|
||||||
|
}}
|
||||||
|
onCompositionEnd={() => {
|
||||||
|
isComposition.current = false;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
<Button
|
<Button
|
||||||
disabled={!workspaceName}
|
disabled={!workspaceName}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
useState,
|
useState,
|
||||||
FocusEventHandler,
|
FocusEventHandler,
|
||||||
KeyboardEventHandler,
|
KeyboardEventHandler,
|
||||||
|
HTMLAttributes,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { StyledInput } from './style';
|
import { StyledInput } from './style';
|
||||||
|
|
||||||
@@ -18,9 +19,8 @@ type inputProps = {
|
|||||||
onChange?: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
onBlur?: FocusEventHandler<HTMLInputElement>;
|
onBlur?: FocusEventHandler<HTMLInputElement>;
|
||||||
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
||||||
};
|
} & Omit<HTMLAttributes<HTMLInputElement>, 'onChange'>;
|
||||||
export const Input = (props: inputProps) => {
|
export const Input = ({
|
||||||
const {
|
|
||||||
disabled,
|
disabled,
|
||||||
value: valueProp,
|
value: valueProp,
|
||||||
placeholder,
|
placeholder,
|
||||||
@@ -31,7 +31,8 @@ export const Input = (props: inputProps) => {
|
|||||||
onChange,
|
onChange,
|
||||||
onBlur,
|
onBlur,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
} = props;
|
...otherProps
|
||||||
|
}: inputProps) => {
|
||||||
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;
|
||||||
@@ -61,6 +62,7 @@ export const Input = (props: inputProps) => {
|
|||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
height={height}
|
height={height}
|
||||||
|
{...otherProps}
|
||||||
></StyledInput>
|
></StyledInput>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user