| 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 |
|