setting selectedOption for options as an object
See original GitHub issueUsing segmented controls for options as value pairs i cant get the selected option to highlight the selected field.
My on selection if firing and it is returning the value in the text below but the selected field remains unstyled any advice?
I tried setting the selected field to both the value and the label and indeed the object itself.
Also i have bound all the functions in the contructor to “this”
setSelectedOption(option){
console.log(option.label)
this.setState({selectedOption: option})
}
renderOption(option, selected, onSelect, index){
const style = selected ? { fontWeight: 'bold'} : {};
return (
<TouchableWithoutFeedback onPress={onSelect} key={index}>
<Text style={style}>{option}</Text>
</TouchableWithoutFeedback>
);
}
renderContainer(optionNodes){
return <View>{optionNodes}</View>;
}
const options = [
{
label: 'Walking',
value: 'walking'
},
{
label: 'Driving',
value: 'driving'
},
]
return (
<SegmentedControls
options={ options }
onSelection={ (option) => this.setSelectedOption(option) }
extractText={ (option) => option.label }
selectedOption={this.state.selectedOption}
/>)
<Text>{this.state.selectedOption.value}</Text>
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
HTMLSelectElement.selectedOptions - Web APIs | MDN
The list of selected options is an HTMLCollection object with one entry per currently selected option. An option is considered selected if ...
Read more >Angular 4 - using objects for option values in a select list
I'm currently using [ngValue] and it stores objects just fine. The explanation as to why you experienced issues using (change) instead of ...
Read more >How to Change an HTML Selected Option Using JavaScript
We can change the HTML select element's selected option with JavaScript by setting the value property of the select element object.
Read more >How to set selected option dynamically in Angular 6 - Medium
Selects in Forms are great when you have multiple options. In Angular as a OPTION value we can use not only string literals,...
Read more >Option object JavaScript - Dottoro Web Reference
Specifies an item in a selection list. The option element is used to add items to a select element. If the select element...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue as you. In the source code I found this undocumented prop,
testOptionEqual
. It seems to check for strict equality by default. This wouldn’t work in my use case, so I changed it to something like this:And now I can just pass values of the options in
selectedOption
😃.@hosusan6 @SpaceK33z are you able to change the option after using
testOptionEqual={(selectedValue, option) => selectedValue === option.value}
?After using that, the UI won’t update when changing option.