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

fix(16740): DatePicker calendar close issue on clickAway, DatePicker not running onChange events, DatePicker setting and clearing date in range issues #17072

Merged
merged 10 commits into from
Aug 6, 2024

Conversation

2nikhiltom
Copy link
Contributor

@2nikhiltom 2nikhiltom commented Jul 31, 2024

Closes #16740
Closes #16710
Closes #17071
Closes #16991

Changelog

(a) Sets up a mousedown event listener on the document.
(b) Addes a handleMouseDown function which checks if any click is made outside the calendar(icon) and InputFields.

  • If click is made outside closeCalendar function is called immediately
  • (which basically closes the flat picker instance calendarRef.current.close() and removes the focus from inputField)
  • Adds event type clickOutside while calling onCalendarClose (to capture it and return without processing )

(c) Deprecates the use of setTimeout

  • Moved the logic from inside of setTimeout to handleCalendarClose function.
  • a new useEffect is add to call handleCalendarClose whenever calendar closes
useEffect(() => {
  if (calendarCloseEvent) {
    const { selectedDates, dateStr, instance } = calendarCloseEvent;
   //handleCalendarClose handles the core logic of setTImeout 
    handleCalendarClose(selectedDates, dateStr, instance);
    setCalendarCloseEvent(null);
  }
}, [calendarCloseEvent, handleCalendarClose]);

Would love some review on usage of this interface

 interface CalendarCloseEvent {
    selectedDates: Date[];
    dateStr: string;
    instance: object; //This is `Intance` of flatpicker
  }

Testing / Reviewing

Open deploy preview and visit all the storybook examples

Each has demonstration on existing bugs fix (make sure calendar closes on clickaway, dates are rested on clear option, onchange events happens as expected )
Storybook examples needs to be restored or older version before merging

Copy link

netlify bot commented Jul 31, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 3779dc1
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/66b072bdeb80dd000839a14e
😎 Deploy Preview https://deploy-preview-17072--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@2nikhiltom 2nikhiltom changed the title fix(16740, 17071): DatePicker calendar close issue on clickAway fix(16740): DatePicker calendar close issue on clickAway Jul 31, 2024
Copy link

netlify bot commented Aug 1, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3779dc1
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/66b072bd8182b00008a5fdc3
😎 Deploy Preview https://deploy-preview-17072--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@2nikhiltom 2nikhiltom marked this pull request as ready for review August 1, 2024 16:41
@2nikhiltom 2nikhiltom requested a review from a team as a code owner August 1, 2024 16:41
Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

The storybook interaction looks good, but I'm concerned this change as is could have some unintended effects due to how the code is modifying how savedOnClose is used.

@2nikhiltom 2nikhiltom requested a review from tay1orjones August 1, 2024 19:43
@2nikhiltom 2nikhiltom changed the title fix(16740): DatePicker calendar close issue on clickAway fix(16740): DatePicker calendar close issue on clickAway, DatePicker not running onChange events, DatePicker setting and clearing date in range issues Aug 2, 2024
@guidari
Copy link
Contributor

guidari commented Aug 2, 2024

Hey Nikhil, looks like the overview page is not loading
Screenshot 2024-08-02 at 10 04 27

Copy link
Contributor

@guidari guidari left a comment

Choose a reason for hiding this comment

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

I pulled down locally to test and looks good!
You can also close this issue #16991, It's working fine now!
🚀

Copy link
Member

@emyarod emyarod left a comment

Choose a reason for hiding this comment

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

looks good to me! I think we can update the stories to remove the console.logs now

Copy link
Contributor

@riddhybansal riddhybansal left a comment

Choose a reason for hiding this comment

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

Great Work !! 🚀

Merged via the queue into carbon-design-system:main with commit e93167f Aug 6, 2024
22 checks passed
tay1orjones pushed a commit to tay1orjones/carbon that referenced this pull request Aug 9, 2024
…not running onChange events, DatePicker setting and clearing date in range issues (carbon-design-system#17072)

* fix: fixes DatePicker calendar close issue on clickAway

* fix(DatePicker): fixes close calendar issue on click away

* fix: covers empty value conditions

* refactor: updates avt test as per 1.58 version

* refactor: reverts changes made by renovate on avt test

* refactor: removes callback and dependency from useeffect

* refactor: callback is only added to onCalendarClose

* refactor: deprecates the usage is setTimeout to use useEffect

* refactor: revert storybook changes
@tay1orjones tay1orjones mentioned this pull request Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants