Skip to content

Commit

Permalink
fix: temporarily add the click event to fix #29
Browse files Browse the repository at this point in the history
  • Loading branch information
yzh990918 committed May 18, 2023
1 parent 58b7a52 commit 9b03e17
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/ui/base/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Select = <T extends SelectOptionType>(inputProps: Props<T>) => {
selectedOption: props.options.find(o => o.value === props.value),
readOnly: props.readonly,
onChange: (detail) => {
console.log('trigger')
if (detail) {
setSelectedItem(props.options.find(o => o.value === detail.value))
props.onChange(detail.value)
Expand All @@ -35,10 +36,8 @@ export const Select = <T extends SelectOptionType>(inputProps: Props<T>) => {

createEffect(on(() => props.value, () => {
const option = props.options.find(o => o.value === props.value)
if (option) {
api().setSelectedOption(option)
if (option)
setSelectedItem(option)
}
}))

const selectedComponent = (item: T | null) => {
Expand Down Expand Up @@ -81,8 +80,14 @@ export const Select = <T extends SelectOptionType>(inputProps: Props<T>) => {
<div class="w-$reference-width -mt-2 z-100 shadow-md" {...api().positionerProps}>
<ul class="bg-base" {...api().contentProps}>
{props.options.map(item => (
<li {...api().getOptionProps({ label: item.label, value: item.value })}>
{itemComponent(item, item.value === api().selectedOption?.value)}
<li
{...api().getOptionProps({ label: item.label, value: item.value })}
onClick={() => {
setSelectedItem(item)
props.onChange(item.value)
}}
>
{itemComponent(item, item.value === selectedItem()?.value)}
</li>
))}
</ul>
Expand Down

0 comments on commit 9b03e17

Please sign in to comment.