Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Select with numeric keys are not supported #3880

Closed
mngu opened this issue Oct 13, 2024 · 3 comments · Fixed by #3883
Closed

[BUG] - Select with numeric keys are not supported #3880

mngu opened this issue Oct 13, 2024 · 3 comments · Fixed by #3883
Assignees
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working

Comments

@mngu
Copy link

mngu commented Oct 13, 2024

NextUI Version

2.4.8

Describe the bug

Hi,

I got a little issue with the Select (which is working great btw).
The selectedKeys prop does not work when keys are numeric.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Here's how to reproduce it:

<Select selectedKeys={[1]}>
  <SelectItem key={1} value={1}>
    Num 1
  </SelectItem>
</Select>

I got the following warning:
Select: Keys "1" passed to "selectedKeys" are not present in the collection.

Expected behavior

The SelectItem with a numeric key should be selected

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

Copy link

linear bot commented Oct 13, 2024

@wingkwong wingkwong added 🐛 Type: Bug Something isn't working 📦 Scope : Components Related to the components labels Oct 13, 2024
@ryo-manba ryo-manba self-assigned this Oct 13, 2024
@ryo-manba
Copy link
Member

Thanks for the issue!

To handle numeric keys correctly in SelectItem, you can structure the items like this:

const items = [
  { id: 1, value: "Num 1" },
  { id: 2, value: "Num 2" },
  { id: 3, value: "Num 3" },
];

<Select items={items}>
  {(item) => <SelectItem>{item.value}</SelectItem>}
</Select>

However, a key is currently required, so this will be addressed in the following PR.
#3883

@mngu
Copy link
Author

mngu commented Oct 13, 2024

Thanks for the quick fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants