mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Fixed dropdown default value and styling issue when text was too long
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user