sapcc / juno

Monorepo for the Juno microfrontend framework, microfrontend apps, design system and component library
Apache License 2.0
5 stars 3 forks source link

DateTimerPicker fix endless loop. Fixes #575, #578 #582

Closed franzheidl closed 2 months ago

franzheidl commented 2 months ago

Fix #575 Fix #578

Fix endless Loop

Listening to our value prop (and its aliases) in a useEffect to set the flatpickr instance, and enforcing onChange events to update our state on the onChange resulting in our updating the FP instance caused an endless loop. We now JSON.stringify the value prop and its aliases and keep these in our dependency array, so they will only be recognized as changed when they actually have changed, eventually preventing DateTimePicker from going into an endless loop.

Fix calendar icon click

The problem was caused by some weird behavior of the open() method of the flatpickr instance that we used in handleCalendarIconClick. In order to avoid having to use this method, we remove the calendar icon button element completely, and set the calendar icon (or clock icon for pure time pickers) as an inlined background image. By doing this, when users click the icon, they actually click the input element as if they were clicking somewhere else in the DateTimePicker. As a resutl, the open() method of flatpickr is not used at all anymore in our component and can not play up.