React-select: custom labels for control vs. options - currently they have to be the same

Created on 14 Nov 2019  路  2Comments  路  Source: JedWatson/react-select

I apologize if this is a duplicate question, but i was not able to find the answer anywhere.

I'd like to set a conditional formatting to the control label, but not on the option labels.

For Example, I want the label on the control to be Show: All while i want the label in the options list to just be All. I also have other options such as Human Names that i want to conditionally _not_ set the label to be anything different. When the All option is selected, the control shows Show: All and when the John Doe option is selected, the control still just shows John Doe is my desired outcome

getOptionLabel changes both the labels in the options and the control

I would love something like a controlLabelFormatter or something of the sorts - I've seen these in other selector packages and was totally expecting it here - Which is why i think i might just be missing something.

Thanks!

Most helpful comment

There is already a prop which would allow for something like this: formatOptionLabel, which accepts a function as a value. It gets the option as its first argument and a context as a second.

Two contexts I found were value for formatting the option in the control and menu for an option in the dropdown menu.

All 2 comments

There is already a prop which would allow for something like this: formatOptionLabel, which accepts a function as a value. It gets the option as its first argument and a context as a second.

Two contexts I found were value for formatting the option in the control and menu for an option in the dropdown menu.

Thank you so much! it's the context that i wasn't aware of - super helpful!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MindRave picture MindRave  路  3Comments

joshualimpj picture joshualimpj  路  3Comments

coder-guy22296 picture coder-guy22296  路  3Comments

Meesam picture Meesam  路  3Comments

mjuopperi picture mjuopperi  路  3Comments