feat: enhance FloatingLabelInput to manage selected value for select type
This commit is contained in:
parent
01e27dff66
commit
75f8a526de
@ -17,9 +17,15 @@ export default function FloatingLabelInput({
|
||||
onChange,
|
||||
}: FloatingLabelInputProps) {
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [selectedValue, setSelectedValue] = useState(defaultValue || '');
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
||||
const value = e.target.value;
|
||||
|
||||
if (type === 'select') {
|
||||
setSelectedValue(value);
|
||||
}
|
||||
|
||||
if (onChange) {
|
||||
onChange(value);
|
||||
}
|
||||
@ -34,7 +40,8 @@ export default function FloatingLabelInput({
|
||||
<select
|
||||
className="input-form focus:ring-2 focus:ring-blue-500 outline-none"
|
||||
name={name}
|
||||
value={defaultValue}
|
||||
value={selectedValue}
|
||||
onChange={handleChange}
|
||||
>
|
||||
{options?.map((option, index) => (
|
||||
<option key={index} value={option.value}>{option.label}</option>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user