Skip to content

Commit

Permalink
fix: disable button when value is empty (toeverything#3590)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Yang <[email protected]>
  • Loading branch information
Wzb3422 and himself65 authored Aug 5, 2023
1 parent 72c4aa0 commit 48350d7
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
<div
style={{
Expand Down Expand Up @@ -273,11 +279,8 @@ export const EditCollection = ({
size="large"
data-testid="save-collection"
type="primary"
onClick={() => {
if (value.name.trim().length > 0) {
onConfirm(value);
}
}}
disabled={isNameEmpty}
onClick={onSaveCollection}
>
{onConfirmText ?? t['Create']()}
</Button>
Expand Down

0 comments on commit 48350d7

Please sign in to comment.