React-datepicker: Keyboard navigation does not work with customInput

Created on 31 Mar 2018  路  4Comments  路  Source: Hacker0x01/react-datepicker

Expected behavior

  1. Calendar with custom input works with keyboard

Actual behavior

  1. Using a custom input, keyboard navigation does not work

Steps to reproduce

  1. usign example page, go to the Custom Input section
  2. click on the button to open the calendar
  3. press keyboard arrow keys and notice that the browser window scrolls

Code used in example

class ExampleCustomInput extends React.Component {

  render () {
    return (
      <button
        className="example-custom-input"
        onClick={this.props.onClick}>
        {this.props.value}
      </button>
    )
  }
}

ExampleCustomInput.propTypes = {
  onClick: PropTypes.func,
  value: PropTypes.string
};

...

<DatePicker
  customInput={<ExampleCustomInput />}
  selected={this.state.startDate}
  onChange={this.handleChange} />
wontfix

Most helpful comment

I found a way... the customInput element should has to use the onKeyDown-event (that gets passed to the custom input element by the DatePicker)

class ExampleCustomInput extends React.Component {

  render () {
    return (
      <button
       onKeyDown={this.props.onKeyDown}
        className="example-custom-input"
        onClick={this.props.onClick}>
        {this.props.value}
      </button>
    )
  }
}

i found this, analyzing the code... i think this should be mentioned in the documentation!

All 4 comments

this is indeed an issue.

Seeing the same thing.

I found a way... the customInput element should has to use the onKeyDown-event (that gets passed to the custom input element by the DatePicker)

class ExampleCustomInput extends React.Component {

  render () {
    return (
      <button
       onKeyDown={this.props.onKeyDown}
        className="example-custom-input"
        onClick={this.props.onClick}>
        {this.props.value}
      </button>
    )
  }
}

i found this, analyzing the code... i think this should be mentioned in the documentation!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lclemence picture lclemence  路  3Comments

jjjss94 picture jjjss94  路  3Comments

carmouche picture carmouche  路  3Comments

dhruvparmar372 picture dhruvparmar372  路  3Comments

ericreis picture ericreis  路  3Comments