-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
The value and label with empty string doesn't display properly #3775
Comments
If your intend is to use this option to clear the selected value, then you could use |
No, I don't want to clear the selected value, I want to have empty string as a selected option. Thanks |
@hyphen1370 take a look at |
Perhaps css |
andrea-ligios, is doesn't work. For a workaround, is there anyway to change font color for particular option in the dropdown list? For example, I can put 'empty' as label for value "", change color to white, which match the background color of the dropdown, to make to option "invisible"?: |
I had this problem too. I fixed it by a hack but it works
|
Hello - In an effort to sustain the We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version. If you aren't using the latest version of However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you! |
Just as we close this out, I've got a couple of suggestions: As @rationalthinker1 said, you can add a min-height, the alternative for that if you don't want to put the styles in your stylesheet is to use the styles override: <Select
styles={{ option: styles => ({ minHeight: 40, ...styles }) }}
id={name}
name={name}
options={options}
/> Probably a better solution is to actually give the option a label though, and style it so the text is transparent (@hyphen1370 asked about whether you can do this) It's a bit more code, but will work better for accessibility (e.g screenreaders will say "empty" instead of nothing) <Select
styles={{
option: (styles, { data }) => ({
...styles, color: data.value === '' ? 'transparent' : styles.color
}),
singleValue: (styles, { data }) => ({
...styles, color: data.value === '' ? 'transparent' : styles.color
}),
}}
id={name}
name={name}
options={options}
/> This is where the power of using css-in-js is really obvious, because we're only applying the style to options that have an empty string as their value. (Note that you'll want to style the |
Hello,
I have a select option like this:
selectOptionList: [
{value: '', label: ''},
{value: 'Y', label: 'Y'},
{value: 'N', label: 'N'}
]
I call react-select like this
<Select
id={"alter_item_check_" + selectID}
value={{value: this.state.selectedOption, label: this.state.selectOption}}
onChange={this.changeSelectOption}
options={this.state.selectOptionList}
/>
However, you can see in the attachment, the value and label with empty string doesn't have the same height as other options. Is there anyway to make all three options with the same height?
Thanks
The text was updated successfully, but these errors were encountered: