-
Notifications
You must be signed in to change notification settings - Fork 4.1k
v2 - display icon in selected option #2553
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
Comments
I see that you need MultiValue - that wasn't clear to me from the docs but was obvious when I implemented it for SingleValue. Please close, sorry for the noise. |
No worries @jechlin, glad you got to the bottom of it |
I came exactly into the same error by mistake. What do you think about reducing the burden in the docs? And I it would be nice to have some description for what each component represents. (A screenshot would be fantastic). Again this are just a few suggestions, take whatever you feel to. |
hello, |
Just override the Option component with yours and you will have full control on what you want to render.
And then you apply it to your Select component
|
@canda showed how to implement an icon with your option labels. Works perfect with v2. Anyone know how to accomplish similar with v1.2.1? I'm stuck in the past. ☕ |
Did the same solutions and working fine. but for the selected option its not showing the icons. It should work like the example 'Custom Placeholder' on this page https://jedwatson.github.io/react-select/ |
@AbhaysinghBhosale You might have to also overwrite the @TroyWolf For v1.x check out the example |
@canda You are legend sir! |
I am using version 2.0 and its not working for the selected option |
@Rall3n Thanks for pointing its worked after using Single Value componentas follows and passing to select as |
If your Icon is image, how should I be able to do :
The fact that I use require(...) gives me a bug cause react can't reach module props.data.image as path, even if the path exists and work if I type it as string. Any solution? |
can you plz share your version and code sample ... i am also using 2.0 but unable to achieve the result |
@tapas100 - I don't know if you're still looking for this code sample or not... please see below full example... I used the example from @AbhaysinghBhosale along with insight provided by @Rall3n and @canda and came up with this which is basically the same thing that @AbhaysinghBhosale has provided: import React from "react";
import Select, {components} from 'react-select';
import {avatarOptions} from '../helpers/ddOptions';
class MyApp extends React.Component {
// Change event handler for React-Select component.
handleOnChangeReactSelect = (selectValue) => {
// Update the current stopwatch.
// Take a copy of the current stopwatch.
const updatedStopwatch = {
...this.props.stopwatch,
"avatar": selectValue
};
this.props.updateStopwatch(this.props.stopwatchindex, updatedStopwatch);
}
render() {
// React Select mods.
const { Option, SingleValue } = components;
const IconOption = (props) => (
<Option {...props}>
<img className="maybeUseClassName" src={props.data.label} style={{width:30}} alt="" />
</Option>
);
const ValueOption = (props) => (
<SingleValue {...props}>
<img className="maybeUseClassName" src={props.data.label} style={{width:30}} alt="" />
</SingleValue>
);
return (
<div className="name-container">
<Select
name="avatar"
value={avatar}
onChange={this.handleOnChangeReactSelect}
options={avatarOptions()}
components={{ Option: IconOption, SingleValue: ValueOption }}
/>
</div>
)
}
}
export default MyApp; Thx @canda, @Rall3n and @AbhaysinghBhosale! |
Hi - I'm trying to use MultiValueContainer (same problem with MultiValueLabel) to render an icon image alongside the selected text.
However the props passed to MultiValueContainer don't contain the Option object that it's responsible for for drawing. By traversing through the children I could find the label, but the icon url is already part of my Option object.
Any help appreciated.
cheers, jamie
The text was updated successfully, but these errors were encountered: