React-datepicker: Inline DatePicker with text input

Created on 2 May 2019  路  5Comments  路  Source: Hacker0x01/react-datepicker

Expected behavior

Is there a way to have an inline date picker with an input. Seems like this isn't possible.

An example of what I'd expect to be able to accomplish:

Screen Shot 2019-05-01 at 4 18 37 PM

Most helpful comment

Is there a better way to achieve this through props instead of adding multiple pickers?

All 5 comments

This could also be possible with an option to only have a text parsing input and use DatePicker components sharing the same prop and handlers (one with only text parsing and one inline)

I was able to solve this by using two DatePicker components that share the same selected and onChange props:

  • One with inline=true
  • Another with popperClassName equal to a class that had display: none

Is there a better way to achieve this through props instead of adding multiple pickers?

@aditigoel23 just add a prop open={true}

It could help someone

image

const someComponent = (props) => {
  const [startDate, setStartDate] = useState(new Date("2019/08/08"));
  const [endDate, setEndDate] = useState(new Date("2020/02/08"));

  const onChange = dates => {
    const [start, end] = dates;
    setStartDate(start);
    setEndDate(end);
  };

  return (
    <div className="popup-window">
      <div>
        <DatePicker
          selected={startDate}
          onChange={(date) => setStartDate(date)}
          popperClassName="d-none"
          dateFormat="d MMM yyyy"
          placeholderText="Select from date"
        />
        <DatePicker
          selected={endDate}
          onChange={(date) => setEndDate(date)}
          popperClassName="d-none"
          dateFormat="d MMM yyyy"
          placeholderText="Select to date"
        />
        <DatePicker
          selected={startDate}
          onChange={onChange}
          startDate={startDate}
          endDate={endDate}
          disabledKeyboardNavigation
          selectsRange
          monthsShown={2}
          inline
        />
      </div>
    </div>
  );
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jjjss94 picture jjjss94  路  3Comments

jbccollins picture jbccollins  路  3Comments

formigone picture formigone  路  3Comments

tamitutor picture tamitutor  路  3Comments

ali-master picture ali-master  路  3Comments