Skip to content

Commit b39fef7

Browse files
committed
added defaultView Property
1 parent b0846da commit b39fef7

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/controls/calendar/Calendar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export const Calendar: React.FC<ICalendarControlProps> = ({
127127
onWeekChange,
128128
onViewChange,
129129
onDaySlotClick,
130+
defaultView,
130131
}: ICalendarControlProps) => {
131132
const { styles } = useCalendarStyles();
132133
const calendarRef = useRef<HTMLDivElement>(null);
@@ -140,7 +141,7 @@ export const Calendar: React.FC<ICalendarControlProps> = ({
140141
);
141142
// Default view
142143
const [selectedView, setSelectedView] = useState<ECalendarViews>(
143-
ECalendarViews.Month
144+
defaultView ?? ECalendarViews.Month
144145
);
145146
const { getMonthCalendar } = useCalendar(
146147
Intl.DateTimeFormat().resolvedOptions().timeZone
@@ -246,6 +247,10 @@ export const Calendar: React.FC<ICalendarControlProps> = ({
246247
};
247248
}, [styles.calendarWrapper]);
248249

250+
useEffect(() => {
251+
setSelectedView(defaultView ?? ECalendarViews.Month);
252+
}, [defaultView]);
253+
249254
const RenderContent = React.useCallback(() => {
250255
switch (selectedView) {
251256
case ECalendarViews.Month:

src/controls/calendar/models/ICalendarControlProps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ECalendarViews } from "./ECalendarViews";
12
import { IEvent } from "./IEvents";
23
import { Theme } from "@fluentui/react-components";
34

@@ -12,4 +13,5 @@ export interface ICalendarControlProps {
1213
onPrev?: (date:Date) => void;
1314
onViewChange?: (view: string) => void;
1415
onDaySlotClick?: (date: Date) => void;
16+
defaultView? :ECalendarViews | undefined
1517
}

0 commit comments

Comments
 (0)