
* Added ValidationHooks and attribute to FormControl * Event listener uses data attribute to set type * Changed default event listener to blur * Add validation data attribute to other components * Adjusted querySelector to remove condition * Added nullish operator to prevent error * Added optional chaining to validator
45 lines
877 B
Text
45 lines
877 B
Text
---
|
|
/**
|
|
* DROPDOWN COMPONENT
|
|
*/
|
|
import type { Dropdown, ControlOption } from '@astro-reactive/common';
|
|
|
|
export interface Props {
|
|
control: Dropdown;
|
|
readOnly?: boolean;
|
|
}
|
|
|
|
const { control, readOnly } = Astro.props;
|
|
|
|
const options = control.options.map((option: string | ControlOption) => {
|
|
if (typeof option === 'string') {
|
|
return {
|
|
label: option,
|
|
value: option,
|
|
};
|
|
}
|
|
return option;
|
|
});
|
|
---
|
|
|
|
<select
|
|
name={control.name}
|
|
id={control.id}
|
|
disabled={readOnly || null}
|
|
data-validation-on={control.triggerValidationOn ? control.triggerValidationOn : null}
|
|
>
|
|
{
|
|
control?.placeholder && (
|
|
<option value="" disabled selected={!control?.value}>
|
|
{control.placeholder}
|
|
</option>
|
|
)
|
|
}
|
|
{
|
|
options.map((option: ControlOption) => (
|
|
<option value={option.value} selected={option.value === control.value}>
|
|
{option.label}
|
|
</option>
|
|
))
|
|
}
|
|
</select>
|