mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-11-18 01:58:36 +00:00
If opening another input dialog with select in the same row it would cause the value to be the same as the previous one as there was no rerender being forced because their keys were the same
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Box, Select } from '@chakra-ui/react';
|
|
import { useEffect } from 'react';
|
|
import { ISelect } from '../../../../interfaces/dialog';
|
|
|
|
interface Props {
|
|
row: ISelect;
|
|
index: number;
|
|
handleChange: (value: string, index: number) => void;
|
|
}
|
|
|
|
const SelectField: React.FC<Props> = (props) => {
|
|
useEffect(() => {
|
|
if (props.row.default) {
|
|
props.row.options?.map((option) => {
|
|
if (props.row.default === option.value) {
|
|
props.handleChange(option.value, props.index);
|
|
}
|
|
});
|
|
}
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<Box mb={3} key={`select-${props.row.label}-${props.index}`}>
|
|
<Select
|
|
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => props.handleChange(e.target.value, props.index)}
|
|
defaultValue={props.row.default || ''}
|
|
isDisabled={props.row.disabled}
|
|
>
|
|
{/* Hacky workaround for selectable placeholder issue */}
|
|
{!props.row.default && (
|
|
<option value="" hidden disabled>
|
|
{props.row.label}
|
|
</option>
|
|
)}
|
|
{props.row.options?.map((option, index) => (
|
|
<option key={`option-${index}`} value={option.value}>
|
|
{option.label || option.value}
|
|
</option>
|
|
))}
|
|
</Select>
|
|
</Box>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default SelectField;
|