question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Placeholder does not seem to update even if objects are different

See original GitHub issue

YOU MUST FILL OUT THE ENTIRE BUG REPORT

Describe the bug
I seem to be having issues with updating the placeholder after the component is mounted.

To Reproduce
Steps to reproduce the behavior:

  1. Have a managed loading state
  2. Set input to be loading
  3. Have a ternary to switch between placeholders
  4. See error

Expected behavior
The placeholder should update to the loading placeholder and back to the given placeholder

Smartphone (please complete the following information):

  • Device: iPad Mini
  • OS: iOS 12.2
  • react-native-picker-select version: ^6.1.0
  • react-native version: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz
  • react version: 16.5.0

Reproduction and/or code sample

Investigation:
export default class RNPickerSelect extends PureComponent {
    // <snip>

    static getDerivedStateFromProps(nextProps, prevState) {
        // <snip>

        // update selectedItem if value prop is defined and differs from currently selected item
        const { selectedItem, idx } = RNPickerSelect.getSelectedItem({
            items,
            key: nextProps.itemKey,
            value: nextProps.value,
        });

        const selectedItemChanged =
            !isEqual(nextProps.value, undefined) && !isEqual(prevState.selectedItem, selectedItem);

        console.log(selectedItem, selectedItemChanged) // <-- Logging here

        if (itemsChanged || selectedItemChanged) {
            if (selectedItemChanged) {
                nextProps.onValueChange(selectedItem.value, idx);
            }

            return {
                ...(itemsChanged ? { items } : {}),
                ...(selectedItemChanged ? { selectedItem } : {}),
            };
        }

        return null;
    }

    // <snip>
}
Output:
Object {
  "color": "#9EA0A4",
  "label": "Select an item...",
  "value": null,
} false
Object {
  "label": "Loading...",
  "value": null,
} false
JSX:
<Select
    {...props}
    placeholder={(
        this.isLoading(name)
            ? {
                label: 'Loading...',
                value: null,
            }
            : null
    )}
    disabled={disabled}
    value={this.getValue(name)}
    items={options}
    style={{
        inputIOS: newStyle,
        inputAndroid: newStyle,
    }}
    onValueChange={text => call([this.onChange, onChange], { field, text })}
/>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
HarshitMadhavcommented, Feb 3, 2020

Set the placeholder like this

placeholder={
{ label: 'Select Gender', value: null, color: '#909090', }
}

It works for me.

1reaction
yl-flyercommented, Mar 11, 2020

Same bug here When i reset the select it still remember the old value:

<RNPickerSelect
     key="csp"
     onValueChange={(value): void => SetSalePointsFilter({ key: 'csp', value })}
     Icon={(): React.ReactNode => <Unicons name="angle-down" size={22} />}
     useNativeAndroidPickerStyle={false}
     placeholder={{
          label: 'CSP',
          value: null,
          ...styles.placeholderColor,
      }}
      value={listing.filters.csp}
      style={styles.select}
      items={items.csp}
 />

Ok, it works for me. To reset the select, set the component value to null and the value of placeholder also null

<RNPickerSelect
     key="csp"
     onValueChange={(value): void => SetSalePointsFilter({ key: 'csp', value: value || null })}
     Icon={(): React.ReactNode => <Unicons name="angle-down" size={22} />}
     useNativeAndroidPickerStyle={false}
     placeholder={{
          label: 'CSP',
          value: null,
          ...styles.placeholderColor,
      }}
      value={listing.filters.csp}
      style={styles.select}
      items={items.csp}
 />
Read more comments on GitHub >

github_iconTop Results From Across the Web

In React a Material UI Textfield does not update or reset to ...
In a React project, I am rendering a material-ui TextField component which is supposed to render conditionally different things.
Read more >
placeholder - CSS: Cascading Style Sheets - MDN Web Docs
Placeholder text will appear with the same styling as user-entered text content when rendered in Windows High Contrast Mode. This will make it ......
Read more >
::placeholder | CSS-Tricks - CSS-Tricks
You would use a selector like input:focus::placeholder , which you wouldn't be able to do with a pseudo class (they don't stack the...
Read more >
Add, edit, or remove a placeholder on a slide layout
In the main pane, on the layout, select the current prompt text (such as Click to edit text, and then type the text...
Read more >
Move and edit objects using the object list in Keynote on Mac
You can still move your own objects in front of or behind any slide layout object—even if it doesn't appear in the object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found