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
Select.tsx
41 lines
| 1 | import type {SelectableFieldProps} 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 |
| 6 | */ |
| 7 | export default function Select({ |
| 8 | Label, |
| 9 | ErrorMessage, |
| 10 | placeholder, |
| 11 | fieldError, |
| 12 | options, |
| 13 | description, |
| 14 | inputProps, |
| 15 | }: SelectableFieldProps) { |
| 16 | const autoComplete = autoCompleteAttr(inputProps?.name); |
| 17 | const FieldDescription = window.givewp.form.templates.layouts.fieldDescription; |
| 18 | |
| 19 | return ( |
| 20 | <label> |
| 21 | <Label /> |
| 22 | {description && <FieldDescription description={description} />} |
| 23 | <select {...inputProps} aria-invalid={fieldError ? 'true' : 'false'} autoComplete={autoComplete}> |
| 24 | {placeholder && ( |
| 25 | <> |
| 26 | <option hidden>{placeholder}</option> |
| 27 | <option disabled>{placeholder}</option> |
| 28 | </> |
| 29 | )} |
| 30 | {options.map(({value, label}) => ( |
| 31 | <option key={value} value={value}> |
| 32 | {label ?? value} |
| 33 | </option> |
| 34 | ))} |
| 35 | </select> |
| 36 | |
| 37 | <ErrorMessage /> |
| 38 | </label> |
| 39 | ); |
| 40 | } |
| 41 |