-
Notifications
You must be signed in to change notification settings - Fork 375
chore(DatePicker): updated controlled examples #9171
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
Merged
tlabaj
merged 2 commits into
patternfly:v5
from
thatblindgeye:iss9136_datePickerAlignment
May 31, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -72,7 +72,7 @@ export interface DatePickerRef { | |
| * If the eventKey parameter is set to 'Escape', that will invoke the date pickers | ||
| * onEscapePress event to toggle the correct control appropriately. | ||
| */ | ||
| toggleCalendar: (isOpen?: boolean, eventKey?: string) => void; | ||
| toggleCalendar: (isOpen?: boolean) => void; | ||
| } | ||
|
|
||
| export const yyyyMMddFormat = (date: Date) => | ||
|
|
@@ -189,10 +189,8 @@ const DatePickerBase = ( | |
| ref, | ||
| () => ({ | ||
| setCalendarOpen: (isOpen: boolean) => setPopoverOpen(isOpen), | ||
| toggleCalendar: (setOpen?: boolean, eventKey?: string) => { | ||
| if (eventKey === KeyTypes.Escape && popoverOpen && !selectOpen) { | ||
| setPopoverOpen((prev) => (setOpen !== undefined ? setOpen : !prev)); | ||
| } | ||
| toggleCalendar: (setOpen?: boolean) => { | ||
| setPopoverOpen((prev) => (setOpen !== undefined ? setOpen : !prev)); | ||
| }, | ||
| isCalendarOpen: popoverOpen | ||
| }), | ||
|
|
@@ -222,7 +220,7 @@ const DatePickerBase = ( | |
| } | ||
| showClose={false} | ||
| isVisible={popoverOpen} | ||
| shouldClose={(event, _fn) => { | ||
| shouldClose={(event, hideFunction) => { | ||
| event = event as KeyboardEvent; | ||
| if (event.key === KeyTypes.Escape && selectOpen) { | ||
| event.stopPropagation(); | ||
|
|
@@ -233,7 +231,12 @@ const DatePickerBase = ( | |
| if (buttonRef.current && buttonRef.current.contains(event.target as Node)) { | ||
| return false; | ||
| } | ||
| setPopoverOpen(false); | ||
|
|
||
| if (popoverOpen) { | ||
| event.stopPropagation(); | ||
| setPopoverOpen(false); | ||
| hideFunction(); | ||
| } | ||
|
Comment on lines
+235
to
+239
Contributor
Author
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. This prevents the CalendarMonth from opening again when pressing the "Toggle" button to close it, and also allows clicking outside the CalendarMonth to close it. |
||
| if (event.key === KeyTypes.Escape && popoverOpen) { | ||
| event.stopPropagation(); | ||
| } | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
@nicolethoen @tlabaj Pushed an update that makes the example work as intended and added an integration test for the functionality.
I removed the
eventKeyparam as it wasn't being used in the example when added, and it doesn't seem like it would be necessary any more? I tested the datepicker in modal demo and pressing Escape to close the datepicker didn't cause the issue of also closing the modal.