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

[Select] pass label information in renderValue() #29497

Closed
1 task done
ifndefdeadmau5 opened this issue Nov 4, 2021 · 6 comments
Closed
1 task done

[Select] pass label information in renderValue() #29497

ifndefdeadmau5 opened this issue Nov 4, 2021 · 6 comments
Labels
component: select This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow

Comments

@ifndefdeadmau5
Copy link
Contributor

ifndefdeadmau5 commented Nov 4, 2021

renderValue() prop provides nice way of customizing how the displayed value should be looks like in Select.
However, some information is leaking:
e.g)

<MenuItem value="our value here">Label</MenuItem>
                                 ^^^^^
                                 // label of selected item is missing

Currently there's no way around accessing Label text, hence users should create some mapper for displayed value.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

rednerValue() prop should be given 'label' data somehow

Examples 🌈

<Select
  ...
  renderValue={(value, label /* this is just my proposal */) => (<option value={value}>{label}</option>)}
/>

Motivation 🔦

I want to utilize label information inside of renderValue() callback

@ifndefdeadmau5 ifndefdeadmau5 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 4, 2021
@siriwatknp
Copy link
Member

Thanks for the feedback but I don't think the library should provide that because there is afford to find the label related to the value.

I think this work should be on the consumer side, like this:

<Select
  ...
  renderValue={value => {
    const item = items.find(({ value: v }) => v === value ); 
    return item.label
  }}
/>

cc @mnajdova @michaldudak for other opinions.

@siriwatknp siriwatknp added support: question Community support but can be turned into an improvement discussion and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: question Community support but can be turned into an improvement labels Nov 4, 2021
@ifndefdeadmau5
Copy link
Contributor Author

@siriwatknp Thanks for the quick response. I thought this could be pretty handy and could eliminate fair amount of look-up code but I always support what you guys towards to regarding API design :)

@michaldudak
Copy link
Member

Agree with @siriwatknp - this is pretty simple to implement on the application side and if done in the library, it would also impact the developers who don't need it.

@mnajdova
Copy link
Member

mnajdova commented Nov 5, 2021

Agree, I am closing since instructions on how it can be achieved has been provided.

@mnajdova mnajdova closed this as completed Nov 5, 2021
@mnajdova mnajdova added component: select This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow and removed discussion labels Nov 5, 2021
@nishantdotcom
Copy link

But in single select ,How can i implement RenderValue()?

@m-awais-kwanso
Copy link

But in single select ,How can i implement RenderValue()?

@nishantdotcom had you find any way around for single select ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

6 participants