evidence icon indicating copy to clipboard operation
evidence copied to clipboard

[Bug]: Initially selected value in Dropdown is the last value in range rather than first

Open archiewood opened this issue 10 months ago • 1 comments

Describe the bug

In the case where you do not select a value, the expected behaviour is that the first value in the range would be the initial state of the dropdown. Instead the last is used.

This happens even if you sort it descending, in which case it then starts to use the first value!

Steps to Reproduce

Clean project

```sql days
select
  date_trunc('day', order_datetime)::varchar as order_day,
  from needful_things.orders
group by all
order by order_day
```

Would expect the default value to be 2019-01-01

<Dropdown data={days} value=order_day name=order_day/>

---

Would expect the default value to be 2019-01-01

<Dropdown data={days} value=order_day name=order_day_1 order="order_day"/>

---
Would expect the default value to be 2021-12-31

<Dropdown data={days} value=order_day name=order_day_2 order="order_day desc"/>

https://github.com/archiewood/dropdown-selected-sort-bug

Image

Severity

serious, but I can work around it

archiewood avatar Apr 08 '25 15:04 archiewood

my suspicion is something like this:

  • when we initialize the dropdown, we loop through all the options, and do an operation that sets them as the default.
  • And since we loop in the of the query order, the final option is the one that is set as the default last

archiewood avatar Apr 08 '25 15:04 archiewood