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 not showing

See original GitHub issue

<Datepicker placeholderText="Click to select a date" selected={this.state.startDate}

The problem is that the datepicker show the date selected instead of the placeholder text. If i ever remove the selected attribute, the whole component stop working ( this behaviour is expected ). I’ve tried to change the startDate state by an empty string or an empty object and i got an error.

So i dont quite get the logic of this, the placeholder functionality is only working when the datepicker isn’t ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:8

github_iconTop GitHub Comments

16reactions
annetterscommented, Jul 8, 2017

This caught me as well. The demo does not explain that the placeholder won’t appear if the date is there. But changes to null worked.

class DatePickerContainer extends React.Component {
    constructor (props) {
        super(props)
        this.state = {
            startDate: ''

            // Enable this if you want todays date to appear by default
            // startDate: moment()
        };
        this.handleChange = this.handleChange.bind(this);
    }

    handleChange(date) {
        this.setState({
            startDate: date
        });
    }

    render() {
        return <DatePicker
            selected={this.state.startDate}
            onChange={this.handleChange}
            placeholderText="MM/DD/YYYY"
        />;
    }
}
12reactions
rafeememoncommented, Apr 9, 2016

To have no date selected you should set selected to null.

If i ever remove the selected attribute, the whole component stop working ( this behaviour is expected ).

Can you elaborate more on how it stops working? Why is this expected?

Read more comments on GitHub >

github_iconTop Results From Across the Web

input placeholder is not showing - Stack Overflow
so when the page loads then placeholder will show. <input type="tel" name="natid" id= ...
Read more >
Input placeholder not visible
Hi Gareth, You can change the visibility of the placeholder text, by adding this CSS to your app: The first input, has 'enabled'...
Read more >
Placeholder not appearing in textbox - HTML-CSS
I have no idea why this is happening. Placeholder shows up properly in the textbox of type “number” called Age. It seems to...
Read more >
:placeholder-shown - CSS: Cascading Style Sheets | MDN
The :placeholder-shown CSS pseudo-class represents any <input> or <textarea> element that is currently displaying placeholder text.
Read more >
placeholder-shown - CSS-Tricks
The :placeholder-shown pseudo-class selects the input element itself when placeholder text exists in a form input. Think of it as a nice way ......
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