Not showing selected value on Android
See original GitHub issueDescribe the bug
I am using picker-select in form for creating/editing notes. I am fetching items
from our API.
First issue is with create note:
- Open picker, can see all items
- Select item
- item label is not shown in select field
- if i save note, it is created with correct category
Issue with edit:
- click on edit
- do not see label
- can select different item, but after select, do not see label in field
It works fine only if i have items
array locally ( not acceptable) and also default value is set to value from items
, which is problem for creating new, because default is null. Also it is not accepting default value from props
(as can be seen in code snipet)
On iPhone works just fine, only Android issue.
To Reproduce
Steps to reproduce the behavior:
- Go to ‘…’
- Click on ‘…’
- Scroll down to ‘…’
- See error
Expected behavior
I expected the same behavior as on iPhone.
Screenshots
- Empty new form
- Show all items
- Select picker after select one of the items
Additional details
- Device: [Pixel 3]
- OS: [Android 11]
- react-native-picker-select version: [8.04]
- react-native version: [0.63]
- expo sdk version: [40]
Reproduction and/or code sample
function NewNote({ t, note: _note, loading, onSubmit, onCancel }) {
const [note, setNote] = useState(_note);
const [categories, setCategories] = useState([]);
const [categoryId, setCategoryId] = (_note && _note.categoryId );
const handleSubmit = async () => {
await onSubmit(note);
setNote(null);
onCancel();
};
const loadCategories = async () => {
const res = await axios('categories/autocompletes', {
params: {
params: { perPage: 9999 },
filters: [
{
by: 'categoryType',
rule: 'equal',
value: 'Note'
}
]
}
});
setCategories(
res.data.categories.map(c => ({
value: c.id,
label: c.name
}))
);
};
const handleNoteTypeChange = value => {
if (!value) return;
setCategoryId(value);
setNote({ ...note, categoryId: value });
};
useEffect(() => {
loadCategories();
}, []);
return (
<RNPickerSelect
value={note && note.categoryId}
onValueChange={handleNoteTypeChange}
style={_pickerStyles}
placeholder={{ label: 'Type', value: null }}
items={categories}
/>
)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:16
Top Results From Across the Web
Spinner does not show selected value - Stack Overflow
Spinner displays neither the default nor selected item value. ... Write a custom layout for a spiner item and use it instead of...
Read more >The HTML Option element - MDN Web Docs - Mozilla
The content of this attribute represents the value to be submitted with the form, should this option be selected. If this attribute is...
Read more >ion-select: Select One or Multiple Value Boxes or Placeholders
ion-select is represented by selected value(s), or a placeholder, and dropdown icon. When you tap select, a dialog box appears with an easy...
Read more >How to Set the Selected Item of Spinner By Value and Not By ...
Spinner is used in many android applications to display multiple options within a drop-down list and the user will be able to select...
Read more >react-native-select-dropdown - npm
Start using react-native-select-dropdown in your project by running `npm i ... dropdown | select | picker | menu for react native that works...
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
As a temporary workaround, I found two solutions.
Set one of the following prop to RNPickerSelect,
style={{ inputAndroid: { color: 'black' } }}
useNativeAndroidPickerStyle={false}
After many hours of twiddling with this thing finally found this thread. Low and behold this indeed does fix the problem!!
style={{ inputAndroid: { color: 'black' } }} useNativeAndroidPickerStyle={false}
My other solution was to set the placeholder as empty object, but this screws up the layout if you’re needing that placeholder
placeholder={{}}