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 itemToElement isn't working anymore (regression) #15724

Closed
2 tasks done
janhassel opened this issue Feb 9, 2024 · 3 comments
Closed
2 tasks done

[Bug]: Dropdown itemToElement isn't working anymore (regression) #15724

janhassel opened this issue Feb 9, 2024 · 3 comments
Assignees
Labels

Comments

@janhassel
Copy link
Member

Package

@carbon/react

Browser

Safari

Package version

1.49.0

React version

No response

Description

The Dropdown's itemToElement prop doesn't seem to be called anymore. Interestingly enough, itemToString can be used as a substitute for this (though based on the console outputs I don't think this is the intended use).

I couldn't find anything in the documentation or issues regarding a deprecation so I assume this is a regression?

Reproduction/example

https://stackblitz.com/edit/github-jxltcv?file=src%2FApp.jsx

Steps to reproduce

  1. Pass a function to itemToElement: (item) => <em>{item.toLowerCase()}</em>
  2. It's not used when rendering

itemToElement:

image

itemToString (results in expected result):

image

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

@tay1orjones tay1orjones added the severity: 3 https://ibm.biz/carbon-severity label Aug 1, 2024
@tay1orjones tay1orjones moved this to ⏱ Backlog in Design System Aug 1, 2024
@tay1orjones tay1orjones added component: dropdown severity: 2 https://ibm.biz/carbon-severity and removed severity: 3 https://ibm.biz/carbon-severity labels Aug 1, 2024
@guidari guidari self-assigned this Aug 14, 2024
@guidari
Copy link
Contributor

guidari commented Aug 19, 2024

Hey @janhassel
itemToElement only work with objects. I was checking your example and the typeof is a string.

Here it is an Stackblitz example using an object.

Below you can check the logic in carbon:

 {typeof item === 'object' &&
    ItemToElement !== undefined &&
    ItemToElement !== null ? (
      <ItemToElement key={itemProps.id} {...item} />
    ) : (
      itemToString(item)
    )}

@guidari guidari closed this as completed Aug 19, 2024
@github-project-automation github-project-automation bot moved this from ⏱ Backlog to ✅ Done in Design System Aug 19, 2024
@janhassel
Copy link
Member Author

@guidari Interesting, I didn't know that. So if I only have strings and need to display them as elements I need to wrap them in dummy objects, like { id: 'my-value' }?

Could you elaborate on the reasoning for this constraint?

@guidari
Copy link
Contributor

guidari commented Aug 22, 2024

@janhassel I'm not sure the reason behind that. I know that itemTostring is a props from Downshift and the itemToElement is a prop we created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants