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]: Dropdown doesn't render items to element if they're backed by string (not object) #18183

Open
2 tasks done
kubijo opened this issue Nov 29, 2024 · 1 comment
Open
2 tasks done

Comments

@kubijo
Copy link
Contributor

kubijo commented Nov 29, 2024

Package

@carbon/react

Browser

Edge, Firefox, Safari, Chrome

Package version

1.70.0

React version

18.3.1

Description

There are three props that control how items are rendered in dropdown instances:

  • itemToString
  • itemToElement
  • renderSelectedItem

However, the itemToElement callback is useless when you supply items as strings.

The relevant code is here: https://github.com/carbon-design-system/carbon/blob/main/packages/react/src/components/Dropdown/Dropdown.tsx#L694

Please do not cancel this on the grounds of not having a reproduction link... the code itself shows abundantly clearly that what I say is true.

To me, this is clearly a bug because itemToElement is for presentation purposes only and conditioning its usage based on data type does not make sense.

Note that I am not on latest @carbon/react because of a regression you have there.

Reproduction/example

Steps to reproduce

function itemToElement(x) {
    return <strong style={{ color: 'red' }} children={x} />;
}

<Dropdown<string>
    titleText="title"
    items={['a', 'b', 'c', 'd']}
    selectedItem="a"
    onChange={console.log.bind(console)}
    itemToElement={itemToElement}
    renderSelectedItem={itemToElement}
/>

Suggested Severity

Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

@kubijo
Copy link
Contributor Author

kubijo commented Nov 29, 2024

Reagarding the workaround ... I've created a wrapper component that wraps the items into object and then wraps the callbacks too to make it transparent...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ⏱ Backlog
Development

No branches or pull requests

2 participants