Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inputs as children cannot be focused #1831

Closed
dwoznicki opened this issue Jul 23, 2019 · 1 comment
Closed

Inputs as children cannot be focused #1831

dwoznicki opened this issue Jul 23, 2019 · 1 comment
Labels

Comments

@dwoznicki
Copy link

Expected behavior

When passing in inputs as children to DatePicker, it should be possible to focus them.

Actual behavior

Currently, once the calendar input is blurred, focus is immediately reapplied to it. You can see this happening below.

handleBlur = event => {
if (
this.state.open &&
!this.props.withPortal &&
!this.props.showTimeInput
) {
this.deferFocusInput();
} else {
this.props.onBlur(event);
}
this.setState({ focused: false });
};

The reasoning behind this behavior is mentioned here: #730 (comment)

Refocusing the calendar input makes it impossible to focus other elements inside the popper.

Steps to reproduce

Something like so:

import React, { useState } from "react";
import DatePicker from "react-datepicker";

const Demo = () => {
    const [ date, setDate ] = useState(new Date());
    const handleChange = date => setDate(date);
    return <DatePicker selected={ date } onChange={ handleChange }>
        <input type="time" name="time" />
    </DatePicker>
};

What I'm trying to achieve

My goal is to create a picker that supports date time ranges in a single DatePicker. My current plan is to add two time inputs below the calendar: one for start and one for end. Basically, just showTimeInput x2.

Possible solutions (for my case)

  1. Add a prop to prevent calendar refocus on blur: Kinda ugly, but then the client could decide if/when they want this behavior.
  2. Allow multiple time inputs: deferFocusInput is already disabled for time input, so allowing for multiple inputs would not require a change to the current blur behavior.
  3. I should just find a different way to do this: I'm not sold on my current implementation, and would be interested to hear other thoughts. That said, other users may find this behavior unintuitive in the future.
@dwoznicki dwoznicki changed the title Child inputs cannot be focused Inputs as children cannot be focused Jul 23, 2019
@stale
Copy link

stale bot commented Jan 19, 2020

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.

@stale stale bot added the wontfix label Jan 19, 2020
@stale stale bot closed this as completed Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant