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

🐛 Resolve the double-click focus issue of Time input and custom time component example #5088

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-site/src/examples/customTimeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<input
value={value}
onChange={(e) => onChange(e.target.value)}
onClick={(e) => e.target?.focus()}
style={{ border: "solid 1px pink" }}
/>
);
Expand Down
8 changes: 7 additions & 1 deletion src/input_time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default class InputTime extends Component<
InputTimeProps,
InputTimeState
> {
inputRef: React.RefObject<HTMLInputElement> = React.createRef();

constructor(props: InputTimeProps) {
super(props);

Expand Down Expand Up @@ -86,8 +88,12 @@ export default class InputTime extends Component<
<input
type="time"
className="react-datepicker-time__input"
placeholder="Time"
placeholder="Time1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? It feels like it could be a typo.

🔸 Spelling/Typo (Important)

Image of Jacob Jacob

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged before checking the comment, can you check this @balajis-qb

Copy link
Author

@balajis-qb balajis-qb Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @martijnrusschen, as the current PR is already merged I'll create a new PR and comment the link in this conversation.

Copy link
Author

@balajis-qb balajis-qb Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5092 @martijnrusschen, I created this PR to fix the typo. Please review and merge this PR or let me know if you need any changes.

name="time-input"
ref={this.inputRef}
onClick={() => {
this.inputRef.current?.focus();
}}
required
value={time}
onChange={(event) => {
Expand Down
15 changes: 15 additions & 0 deletions src/test/time_input_test.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,19 @@ describe("timeInput", () => {

dateSpy.mockRestore();
});

it("should focus on the time input when the time input gets the click event", () => {
const { container } = render(
<DatePicker shouldCloseOnSelect={false} showTimeInput />,
);

const input = safeQuerySelector(container, "input");
fireEvent.focus(input);
const timeInput = safeQuerySelector<HTMLInputElement>(
container,
'input[type="time"].react-datepicker-time__input',
);
fireEvent.click(timeInput);
expect(document.activeElement).toBe(timeInput);
});
});
Loading