File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ export interface Props {
3+ /** Unique id for textarea */
4+ id: string ;
5+ /** Label text */
6+ label: string ;
7+ /** Name attribute */
8+ name: string ;
9+ /** Initial value */
10+ value? : string ;
11+ /** Number of rows */
12+ rows? : number ;
13+ /** Optional placeholder text */
14+ placeholder? : string ;
15+ /** Optional help text */
16+ helpText? : string ;
17+ /** Optional error text */
18+ errorText? : string ;
19+ /** Disabled state */
20+ disabled? : boolean ;
21+ /** Required field */
22+ required? : boolean ;
23+ /** Optional class */
24+ className? : string ;
25+ }
26+
27+ const {
28+ id,
29+ label,
30+ name,
31+ value = " " ,
32+ rows = 4 ,
33+ placeholder,
34+ helpText,
35+ errorText,
36+ disabled,
37+ required,
38+ className,
39+ } = Astro .props ;
40+
41+ const helpId = helpText ? ` ${id }-help ` : undefined ;
42+ const errorId = errorText ? ` ${id }-error ` : undefined ;
43+ const describedBy = [errorId , helpId ].filter (Boolean ).join (" " ) || undefined ;
44+ ---
45+
46+ <div class ={ className } >
47+ <label for ={ id } >
48+ { label }
49+ { required && <span aria-hidden = " true" > *</span >}
50+ </label >
51+
52+ { errorText && (
53+ <p id = { errorId } role = " alert" >
54+ { errorText }
55+ </p >
56+ )}
57+
58+ { helpText && <p id = { helpId } >{ helpText } </p >}
59+
60+ <textarea
61+ id ={ id }
62+ name ={ name }
63+ rows ={ rows }
64+ placeholder ={ placeholder }
65+ disabled ={ disabled }
66+ required ={ required }
67+ aria-describedby ={ describedBy }
68+ >{ value } </textarea >
69+ </div >
You can’t perform that action at this time.
0 commit comments