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] - Listbox typing issue when using dynamic collections #2365

Closed
Cowjiang opened this issue Feb 16, 2024 · 4 comments · Fixed by #3362
Closed

[BUG] - Listbox typing issue when using dynamic collections #2365

Cowjiang opened this issue Feb 16, 2024 · 4 comments · Fixed by #3362
Labels
🐛 Type: Bug Something isn't working

Comments

@Cowjiang
Copy link

NextUI Version

2.2.9

Describe the bug

When I try to use the Listbox & ListboxSection via dynamic collections, typing issue will be reported as below screenshot but rendering without any error.

image

TS2322: Type (item: ListboxItemBaseProps) => Element is not assignable to type (ItemElement<ListboxItemBaseProps> | ItemElement<ListboxItemBaseProps>[] | ItemRenderer<ListboxItemBaseProps>) & (ReactI18NextChildren | Iterable<...>) Type (item: ListboxItemBaseProps) => Element is not assignable to type ItemRenderer<ListboxItemBaseProps> & string Type (item: ListboxItemBaseProps) => Element is not assignable to type string

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

import { Listbox, ListboxItem, ListboxItemProps, ListboxSection, ListboxSectionProps } from '@nextui-org/react'
import { useState } from 'react'

const settingList: Partial<ListboxSectionProps<ListboxItemProps>>[] = [
  {
    key: 'application',
    title: 'Application',
    items: [
      {
        key: 'appearance',
        title: 'Appearance'
      }
    ]
  }
]

function Setting() {
  const [selectedKeys, setSelectedKeys] = useState(new Set(['text']))
  return (
    <Listbox
      selectionMode="single"
      selectedKeys={selectedKeys}
      onSelectionChange={setSelectedKeys}
      items={settingList}
    >
      {
        section => (
          <ListboxSection {...section}>
            {(item) => (
              <ListboxItem {...item} />
            )}
          </ListboxSection>
        )
      }
    </Listbox>
  )
}

export default Setting

Expected behavior

Nah, please take a look

Screenshots or Videos

No response

Operating System Version

Windows

Browser

Chrome

@Cowjiang Cowjiang added the 🐛 Type: Bug Something isn't working label Feb 16, 2024
@Cowjiang
Copy link
Author

and no issue if I don't use ListboxSection , like the example in document - Listbox -> ListboxItem
the issue only produce on Listbox -> ListboxSection -> ListboxItem

@yahorbarkouski
Copy link

hey @Cowjiang, perhaps you have found a solution already?

@Cowjiang
Copy link
Author

hey @Cowjiang, perhaps you have found a solution already?

Not yet, just add @ts-ignore : (

@ahmadbafrani
Copy link

ahmadbafrani commented Jun 7, 2024

I have the same issue when using ListboxSection with dynamic items.

<Listbox aria-label='Page selection' > <ListboxSection items={items}> {(item) => ( <ListboxItem key={item.key} > {item.title} </ListboxItem> )} </ListboxSection> </Listbox>

Type '(item: { key: string; title: string; }) => Element' is not assignable to type '(ItemElement<{ key: string; title: string; }> | ItemElement<{ key: string; title: string; }>[] | ItemRenderer<{ key: string; title: string; }>) & ReactNode'.
Type '(item: { key: string; title: string; }) => Element' is not assignable to type 'ItemRenderer<{ key: string; title: string; }> & string'.
Type '(item: { key: string; title: string; }) => Element' is not assignable to type 'string'.ts(2322)

As mentioned in ListboxSection document, children prop accepts ReactNode, so I changed the code to this and the error is gone:
<Listbox aria-label='Page selection' > <ListboxSection> {items.map((item) => ( <ListboxItem key={item.key} > {item.title} </ListboxItem> ))} </ListboxSection> </Listbox>

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

Successfully merging a pull request may close this issue.

3 participants