mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
fix: use the esc shortcut to exit in create collection dialog (#6138)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Button, Input, Modal } from '@affine/component';
|
import { Button, Input, Modal } from '@affine/component';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
|
import { type KeyboardEvent } from 'react';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import * as styles from './create-collection.css';
|
import * as styles from './create-collection.css';
|
||||||
@@ -73,6 +74,19 @@ export const CreateCollection = ({
|
|||||||
}
|
}
|
||||||
onConfirm(value);
|
onConfirm(value);
|
||||||
}, [onConfirm, value, isNameEmpty]);
|
}, [onConfirm, value, isNameEmpty]);
|
||||||
|
const onKeyDown = useCallback(
|
||||||
|
(e: KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (e.key === 'Escape') {
|
||||||
|
if (isNameEmpty) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
e.currentTarget.blur();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.stopPropagation();
|
||||||
|
},
|
||||||
|
[isNameEmpty]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
@@ -82,13 +96,11 @@ export const CreateCollection = ({
|
|||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
value={value}
|
value={value}
|
||||||
onKeyDown={e => {
|
|
||||||
e.stopPropagation();
|
|
||||||
}}
|
|
||||||
data-testid="input-collection-title"
|
data-testid="input-collection-title"
|
||||||
placeholder={t['com.affine.editCollectionName.name.placeholder']()}
|
placeholder={t['com.affine.editCollectionName.name.placeholder']()}
|
||||||
onChange={useCallback((value: string) => onChange(value), [onChange])}
|
onChange={useCallback((value: string) => onChange(value), [onChange])}
|
||||||
onEnter={save}
|
onEnter={save}
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
></Input>
|
></Input>
|
||||||
{showTips ? (
|
{showTips ? (
|
||||||
<div className={styles.createTips}>
|
<div className={styles.createTips}>
|
||||||
|
|||||||
Reference in New Issue
Block a user