diff --git a/packages/frontend/core/src/components/page-list/view/create-collection.tsx b/packages/frontend/core/src/components/page-list/view/create-collection.tsx index 34083054d0..c075868aef 100644 --- a/packages/frontend/core/src/components/page-list/view/create-collection.tsx +++ b/packages/frontend/core/src/components/page-list/view/create-collection.tsx @@ -1,5 +1,6 @@ import { Button, Input, Modal } from '@affine/component'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; +import { type KeyboardEvent } from 'react'; import { useCallback, useMemo, useState } from 'react'; import * as styles from './create-collection.css'; @@ -73,6 +74,19 @@ export const CreateCollection = ({ } onConfirm(value); }, [onConfirm, value, isNameEmpty]); + const onKeyDown = useCallback( + (e: KeyboardEvent) => { + if (e.key === 'Escape') { + if (isNameEmpty) { + return; + } else { + e.currentTarget.blur(); + } + } + e.stopPropagation(); + }, + [isNameEmpty] + ); return (
@@ -82,13 +96,11 @@ export const CreateCollection = ({ { - e.stopPropagation(); - }} data-testid="input-collection-title" placeholder={t['com.affine.editCollectionName.name.placeholder']()} onChange={useCallback((value: string) => onChange(value), [onChange])} onEnter={save} + onKeyDown={onKeyDown} > {showTips ? (