-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix DateRangeInput3 focus with timePrecision #6881
Open
evansjohnson
wants to merge
7
commits into
develop
Choose a base branch
from
evanj/fix-date-range-input-focus
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec0666b
Fix DateRangeInput3 focus with timePrecision
evansjohnson d22fe85
lint and format
evansjohnson ec45c07
dont early return before checking timePrecision...
evansjohnson 410431c
diff
evansjohnson dbfc8e6
fix tests
evansjohnson 88c0f45
add more tests and fix more tests
evansjohnson 9b6f3f0
format lint
evansjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,45 +177,54 @@ describe("<DateRangeInput3>", () => { | |
expectPropValidationError(DateRangeInput3, { ...DATE_FORMAT, value: null! }); | ||
}); | ||
|
||
describe("timePrecision prop", () => { | ||
it("<TimePicker /> should not lose focus on increment/decrement with up/down arrows", () => { | ||
const { root } = wrap(<DateRangeInput3 {...DATE_FORMAT} timePrecision={TimePrecision.MINUTE} />, true); | ||
describe("<TimePicker /> focus", () => { | ||
// there are multiple ways to render the underlying TimePicker component so run same tests on all | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice coverage of tests! I like that we're checking all these variants. |
||
const toTest = [ | ||
{ label: "timePrecision != null", props: { timePrecision: TimePrecision.MINUTE } }, | ||
{ | ||
label: "timePickerProps.precision != null", | ||
props: { timePickerProps: { precision: TimePrecision.MINUTE } }, | ||
}, | ||
{ label: "timePickerProps is {}", props: { timePickerProps: {} } }, | ||
]; | ||
|
||
root.setState({ isOpen: true }).update(); | ||
expect(root.find(Popover).prop("isOpen"), "Popover isOpen").to.be.true; | ||
toTest.forEach(({ label, props }) => { | ||
it(`when ${label}, <TimePicker /> should not lose focus on increment/decrement with up/down arrows`, () => { | ||
const { root } = wrap(<DateRangeInput3 {...DATE_FORMAT} {...props} />, true); | ||
|
||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
expect(isStartInputFocused(root), "start input is focused").to.be.false; | ||
expect(isEndInputFocused(root), "end input is focused").to.be.false; | ||
}); | ||
root.setState({ isOpen: true }).update(); | ||
expect(root.find(Popover).prop("isOpen"), "Popover isOpen").to.be.true; | ||
|
||
it("when timePrecision != null && closeOnSelection=true && <TimePicker /> values is changed popover should not close", () => { | ||
const { root, getDayElement } = wrap( | ||
<DateRangeInput3 {...DATE_FORMAT} timePrecision={TimePrecision.MINUTE} />, | ||
true, | ||
); | ||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
expect(isStartInputFocused(root), "start input is focused").to.be.false; | ||
expect(isEndInputFocused(root), "end input is focused").to.be.false; | ||
}); | ||
|
||
root.setState({ isOpen: true }).update(); | ||
it(`when ${label} && closeOnSelection=true && <TimePicker /> values is changed popover should not close`, () => { | ||
const { root, getDayElement } = wrap(<DateRangeInput3 {...DATE_FORMAT} {...props} />, true); | ||
|
||
getDayElement(1).simulate("click"); | ||
getDayElement(10).simulate("click"); | ||
root.setState({ isOpen: true }).update(); | ||
|
||
root.setState({ isOpen: true }).update(); | ||
getDayElement(1).simulate("click"); | ||
getDayElement(10).simulate("click"); | ||
|
||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
root.update(); | ||
expect(root.find(Popover).prop("isOpen")).to.be.true; | ||
}); | ||
root.setState({ isOpen: true }).update(); | ||
|
||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
root.update(); | ||
expect(root.find(Popover).prop("isOpen")).to.be.true; | ||
}); | ||
|
||
it("when timePrecision != null && closeOnSelection=true && end <TimePicker /> values is changed directly (without setting the selectedEnd date) - popover should not close", () => { | ||
const { root } = wrap(<DateRangeInput3 {...DATE_FORMAT} timePrecision={TimePrecision.MINUTE} />, true); | ||
it(`when ${label} && closeOnSelection=true && end <TimePicker /> values is changed directly (without setting the selectedEnd date) - popover should not close`, () => { | ||
const { root } = wrap(<DateRangeInput3 {...DATE_FORMAT} {...props} />, true); | ||
|
||
root.setState({ isOpen: true }); | ||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
root.update(); | ||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp", 1); | ||
root.update(); | ||
expect(root.find(Popover).prop("isOpen")).to.be.true; | ||
root.setState({ isOpen: true }); | ||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp"); | ||
root.update(); | ||
keyDownOnInput(DatetimeClasses.TIMEPICKER_HOUR, "ArrowUp", 1); | ||
root.update(); | ||
expect(root.find(Popover).prop("isOpen")).to.be.true; | ||
}); | ||
}); | ||
|
||
function keyDownOnInput(className: string, key: string, inputElementIndex: number = 0) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A bit confused by the comment above. Will the
TimePicker
still render with its default precision iftimePickerProps
isundefined
?I'm curious how important it is to return
TimePicker.defaultProps.precision
vsundefined
here.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.
because of this bit of existing behavior, which I tried to explain more here: https://github.com/palantir/blueprint/pull/6881/files#diff-d2a31417b184106fdf4054399ab49455504ff747c19714aa6df0bb7f8e26bf90R238-R239
let me know any suggestions you can think of to help clarify this
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.
if
timePickerProps
is not defined, the underlyingDateRangePicker
will have defaulttimePickerProps
, and therefor not show the time pickers - so in that case we say the precision is `undefined.if
timePickerProps
is defined, we return the defaultprecision
, since at this point in this method we already would have returned an explicitly defined precision either directly on this component, or from thetimePickerProps