File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import {
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
813export 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 ) ;
You can’t perform that action at this time.
0 commit comments