Fixed dropdown default value and styling issue when text was too long

This commit is contained in:
Emir Karabeg
2025-01-21 18:12:39 -08:00
parent 9600627a0c
commit 7b11c958eb
@@ -6,6 +6,7 @@ import {
SelectValue,
} from '@/components/ui/select'
import { useSubBlockValue } from '../hooks/use-sub-block-value'
import { useEffect } from 'react'
interface DropdownProps {
options: string[]
@@ -22,12 +23,20 @@ export function Dropdown({
}: DropdownProps) {
const [value, setValue] = useSubBlockValue(blockId, subBlockId)
// Set the value to the first option if it's not set
useEffect(() => {
if (!value && options.length > 0) {
setValue(defaultValue ?? options[0])
}
}, [value, options, defaultValue, setValue])
return (
<Select
value={value as string | undefined}
defaultValue={defaultValue ?? options[0]}
onValueChange={(value) => setValue(value)}
>
<SelectTrigger>
<SelectTrigger className="text-left">
<SelectValue placeholder="Select an option" />
</SelectTrigger>
<SelectContent>