Amount
1 month ago
Consent
1 year ago
utils
1 year ago
Checkbox.tsx
1 year ago
Date.tsx
1 year ago
Email.tsx
1 year ago
File.tsx
1 year ago
Gateways.tsx
1 year ago
Hidden.tsx
2 years ago
Honeypot.tsx
1 year ago
MultiSelect.tsx
2 years ago
Password.tsx
2 years ago
Phone.tsx
1 year ago
Radio.tsx
2 years ago
Select.tsx
1 year ago
Text.tsx
1 year ago
TextArea.tsx
2 years ago
Url.tsx
2 years ago
Text.tsx
51 lines
| 1 | import {FieldHasDescriptionProps} from '@givewp/forms/propTypes'; |
| 2 | import autoCompleteAttr from '@givewp/forms/registrars/templates/fields/utils/autoCompleteAttr'; |
| 3 | |
| 4 | /** |
| 5 | * @since 4.3.0 Add autoComplete support and aria-labelledby and aria-describedby attributes. |
| 6 | */ |
| 7 | export default function Text({ |
| 8 | Label, |
| 9 | ErrorMessage, |
| 10 | fieldError, |
| 11 | description, |
| 12 | placeholder, |
| 13 | inputProps, |
| 14 | }: FieldHasDescriptionProps) { |
| 15 | const autoComplete = autoCompleteAttr(inputProps?.name); |
| 16 | const FieldDescription = window.givewp.form.templates.layouts.fieldDescription; |
| 17 | const baseId = `givewp-fields-text-${inputProps.name}`; |
| 18 | const inputId = `${baseId}-input`; |
| 19 | const labelId = `${baseId}-label`; |
| 20 | const descriptionId = `${baseId}-description`; |
| 21 | |
| 22 | return ( |
| 23 | <label |
| 24 | className={fieldError && 'givewp-field-error-label'} |
| 25 | htmlFor={inputId} |
| 26 | > |
| 27 | <span id={labelId}> |
| 28 | <Label /> |
| 29 | </span> |
| 30 | {description && ( |
| 31 | <span id={descriptionId}> |
| 32 | <FieldDescription description={description} /> |
| 33 | </span> |
| 34 | )} |
| 35 | |
| 36 | <input |
| 37 | id={inputId} |
| 38 | type="text" |
| 39 | aria-invalid={fieldError ? 'true' : 'false'} |
| 40 | aria-labelledby={labelId} |
| 41 | aria-describedby={description ? descriptionId : undefined} |
| 42 | placeholder={placeholder} |
| 43 | {...inputProps} |
| 44 | autoComplete={autoComplete} |
| 45 | /> |
| 46 | |
| 47 | <ErrorMessage /> |
| 48 | </label> |
| 49 | ); |
| 50 | } |
| 51 |