Exposed current view when changing the value of the default value property (#4786)

This commit is contained in:
Kavin Venkatachalam 2022-12-07 18:52:37 +05:30 committed by GitHub
parent 34f7be5bb2
commit 7fc641d12a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,6 +51,7 @@ export const Calendar = function ({
const [currentDate, setCurrentDate] = useState(defaultDate);
const [eventPopoverOptions, setEventPopoverOptions] = useState({ show: false });
const [defaultView, setDefaultValue] = useState(allowedCalendarViews[0]);
const eventPropGetter = (event) => {
const backgroundColor = event.color;
@ -88,9 +89,16 @@ export const Calendar = function ({
});
}
const defaultView = allowedCalendarViews.includes(properties.defaultView)
? properties.defaultView
: allowedCalendarViews[0];
useEffect(() => {
const view = allowedCalendarViews.includes(properties.defaultView)
? properties.defaultView
: allowedCalendarViews[0];
if (exposedVariables.currentView !== view) {
setDefaultValue(view);
setExposedVariable('currentView', view);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [properties.defaultView]);
useEffect(() => {
//check if the default date is a valid date
@ -132,7 +140,9 @@ export const Calendar = function ({
style={style}
views={allowedCalendarViews}
defaultView={defaultView}
view={defaultView}
onView={(view) => {
setDefaultValue(view);
setExposedVariable('currentView', view);
fireEvent('onCalendarViewChange');
}}