Skip to content

Commit 88fa3a5

Browse files
author
Sithara Balasuriya
committed
Updated editable-demo with error message example.
1 parent 45a3543 commit 88fa3a5

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

components-demo/editable-demo.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import {
22
Editable,
3-
EditablePreview,
3+
EditableError,
44
EditableInput,
5+
EditablePreview,
56
EditableTextarea,
67
} from "@/components/ui/editable";
8+
import { cn } from "@/lib/utils";
9+
import { useState } from "react";
10+
11+
const ERROR_MESSAGE = "This field is required";
712

813
export function EditableDemo() {
914

15+
const [showError, setShowError] = useState(false);
16+
1017
return (
1118
<div>
1219
<h2 className="font-semibold text-4xl wrap-break-words">Editable</h2>
@@ -30,7 +37,23 @@ export function EditableDemo() {
3037
</div>
3138
</div>
3239

33-
40+
<div id="editable-with-error">
41+
<div className="w-96">
42+
<Editable
43+
defaultValue=""
44+
placeholder="Click to edit this text"
45+
hasError={showError}
46+
onEdit={() => setShowError(true)}
47+
>
48+
<EditablePreview className="w-80" />
49+
<EditableInput
50+
className={cn("w-80", showError && "border-destructive")}
51+
aria-invalid={showError}
52+
/>
53+
{showError ? <EditableError>{ERROR_MESSAGE}</EditableError> : null}
54+
</Editable>
55+
</div>
56+
</div>
3457

3558
</div>
3659
);

0 commit comments

Comments
 (0)