From 48350d76548b81c210ec7a334311bf9e271bff9e Mon Sep 17 00:00:00 2001 From: Zeb Wu Date: Sat, 5 Aug 2023 19:27:14 +0800 Subject: [PATCH] fix: disable button when value is empty (#3590) Co-authored-by: Alex Yang --- .../page-list/view/create-collection.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/component/src/components/page-list/view/create-collection.tsx b/packages/component/src/components/page-list/view/create-collection.tsx index ec4ea58d5..7aff8d2c3 100644 --- a/packages/component/src/components/page-list/view/create-collection.tsx +++ b/packages/component/src/components/page-list/view/create-collection.tsx @@ -9,7 +9,7 @@ import { SaveIcon, } from '@blocksuite/icons'; import { uuidv4 } from '@blocksuite/store'; -import { useCallback, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import { Button, @@ -167,6 +167,12 @@ export const EditCollection = ({ }, [value] ); + const isNameEmpty = useMemo(() => value.name.trim().length === 0, [value]); + const onSaveCollection = useCallback(() => { + if (!isNameEmpty) { + onConfirm(value); + } + }, [value, isNameEmpty, onConfirm]); return (
{ - if (value.name.trim().length > 0) { - onConfirm(value); - } - }} + disabled={isNameEmpty} + onClick={onSaveCollection} > {onConfirmText ?? t['Create']()}