Skip to content

Commit da93cb1

Browse files
committed
jumping to 8am in the calendar on first render
1 parent 10c61bf commit da93cb1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/components/CalendarBody.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import {
2323
} from './types';
2424

2525
const BOX_POSITION_OFFSET = 26;
26-
const HOUR_TO_DECIMAL = 1.666666667;
27-
const MIN_BOX_SIZE = 40;
26+
const SCROLL_TO_ROW = 19;
2827
const TURQUOISE = '#36CFC9';
2928
const ALL_DAY_ROW = 0;
3029

@@ -81,6 +80,14 @@ function Calendar<T extends GenericEvent>({
8180
onEventClick,
8281
weekends,
8382
}: CalendarBodyProps<T>) {
83+
const rowRef = useRef<null | HTMLDivElement>(null);
84+
85+
useEffect(() => {
86+
if (rowRef.current) {
87+
rowRef.current?.scrollIntoView();
88+
}
89+
}, [rowRef]);
90+
8491
const getDayHoursEvents = (
8592
value: GetWeekDates,
8693
weekObject: WeekObject<T> | undefined
@@ -213,12 +220,17 @@ function Calendar<T extends GenericEvent>({
213220
dataIndex: 'hour',
214221
key: 'hour',
215222
width: 1,
216-
render: (hour: ColumnNode<T>) => {
223+
render: (hour: ColumnNode<T>, {}, id: number) => {
217224
return {
218225
props: {
219226
style: { width: '10%' },
220227
},
221-
children: <div>{hour}</div>,
228+
children:
229+
SCROLL_TO_ROW === id ? (
230+
<div ref={rowRef}>{hour}</div>
231+
) : (
232+
<div>{hour}</div>
233+
),
222234
};
223235
},
224236
};

0 commit comments

Comments
 (0)