fix: disable button when value is empty (#3590)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
SaveIcon,
|
SaveIcon,
|
||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import { uuidv4 } from '@blocksuite/store';
|
import { uuidv4 } from '@blocksuite/store';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -167,6 +167,12 @@ export const EditCollection = ({
|
|||||||
},
|
},
|
||||||
[value]
|
[value]
|
||||||
);
|
);
|
||||||
|
const isNameEmpty = useMemo(() => value.name.trim().length === 0, [value]);
|
||||||
|
const onSaveCollection = useCallback(() => {
|
||||||
|
if (!isNameEmpty) {
|
||||||
|
onConfirm(value);
|
||||||
|
}
|
||||||
|
}, [value, isNameEmpty, onConfirm]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -273,11 +279,8 @@ export const EditCollection = ({
|
|||||||
size="large"
|
size="large"
|
||||||
data-testid="save-collection"
|
data-testid="save-collection"
|
||||||
type="primary"
|
type="primary"
|
||||||
onClick={() => {
|
disabled={isNameEmpty}
|
||||||
if (value.name.trim().length > 0) {
|
onClick={onSaveCollection}
|
||||||
onConfirm(value);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{onConfirmText ?? t['Create']()}
|
{onConfirmText ?? t['Create']()}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user