-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DateRangePicker] Open view on click, Enter or Space instead of focus #4747
[DateRangePicker] Open view on click, Enter or Space instead of focus #4747
Conversation
These are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless they are very complicated, I think it is worth trying to fix #4550 and the fact that clicking on the 2nd input while the 1st is focused closes the panel instead of just switching the currentlySelectingRangeEnd
state.
That would allow us to have a global vision of the range pickers modal opening / closing behavior.
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This PR fixes #4550 for free since we do not rely anymore on component focus Not closing the panel when clicking on the second input is a bit more complex.
const handleBlur = () => {
executeInTheNextEventLoopTick(() => {
if (
inputContainerRef.current?.contains(document.activeElement) ||
popperRef.current?.contains(document.activeElement)
) {
return;
}
onDismiss();
});
}; I'm wondering if the community component shoudl have the similar behavior, becaus for now, we can not have both view and keyboard interaction. If I use the same code on keyboarViewinteractions.mp4 |
For the consistence between the range pickers and the other, it's maybe just a legacy thing. But maybe not in this PR |
I looked at adding tests, but the focus behavior is too weird, event by setting focus manually on input, it calls |
@alexfauquette I don't know if it was the test you were trying to writ I am using it.only('should not close picker when switching focus from start to end input', () => {
const onChange = spy();
const onAccept = spy();
const onClose = spy();
render(
<WrappedDesktopDateRangePicker
onChange={onChange}
onAccept={onAccept}
onClose={onClose}
initialValue={[
adapterToUse.date('2018-01-01T00:00:00.000'),
adapterToUse.date('2018-01-06T00:00:00.000'),
]}
/>,
);
// Open the picker (already tested)
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' });
// Switch to end date
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'end' })
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
})
it.only('should not close picker when switching focus from end to start input', () => {
const onChange = spy();
const onAccept = spy();
const onClose = spy();
render(
<WrappedDesktopDateRangePicker
onChange={onChange}
onAccept={onAccept}
onClose={onClose}
initialValue={[
adapterToUse.date('2018-01-01T00:00:00.000'),
adapterToUse.date('2018-01-06T00:00:00.000'),
]}
/>,
);
// Open the picker (already tested)
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'end' });
// Switch to start date
openPicker({ type: 'date-range', variant: 'desktop', initialFocus: 'start' })
expect(onChange.callCount).to.equal(0);
expect(onAccept.callCount).to.equal(0);
expect(onClose.callCount).to.equal(0);
}) |
Fix #4439
Fix #4550
The view did not close on select, because the focus goes back to the input and DateRangePickerInput open the view when focussed, So
onOpen
was called just afteronClose
I took the same behavior as mobile components: open the view on the click event, or when space/Enter is pressed
I did not managed to test the bug. I thought testing how many times
onOpen
is called would be enough because the bug add aonOpen
after closing on select, but when runningyarn test:karma
I did not get the last call toonOpen