Skip to content

Commit

Permalink
Fix primefaces#4030: Changing Calendar input (with mask) clears the r…
Browse files Browse the repository at this point in the history
…est of the form's state (primefaces#4796)

* Fix bug causing swipe events to not work

* Add onChangeRef
Fixes primefaces#4030

* Add comment

Co-authored-by: Melloware <mellowaredev@gmail.com>

---------

Co-authored-by: Melloware <mellowaredev@gmail.com>
  • Loading branch information
cxo05 and melloware authored Aug 17, 2023
1 parent db55201 commit a091ce7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const Calendar = React.memo(
const ignoreMaskChange = React.useRef(false);
const previousButton = React.useRef(false);
const nextButton = React.useRef(false);
const onChangeRef = React.useRef(null);

const [currentView, setCurrentView] = React.useState('date');
const [currentMonth, setCurrentMonth] = React.useState(null);
Expand Down Expand Up @@ -1424,7 +1425,7 @@ export const Calendar = React.memo(

viewStateChanged.current = true;

props.onChange({
onChangeRef.current({
originalEvent: event,
value: newValue,
stopPropagation: () => {
Expand Down Expand Up @@ -2517,6 +2518,11 @@ export const Calendar = React.memo(
}
});

React.useEffect(() => {
// see https://github.com/primefaces/primereact/issues/4030
onChangeRef.current = props.onChange;
}, [props.onChange]);

React.useEffect(() => {
let unbindMaskEvents = null;

Expand Down

0 comments on commit a091ce7

Please sign in to comment.