Skip to content

Commit

Permalink
feat: Disable autoscroll functionality, Add a functionality to disabl…
Browse files Browse the repository at this point in the history
…e auto-scroll on calendar render.
  • Loading branch information
dhruvgoel92 committed Mar 2, 2022
1 parent 6f000d4 commit aa8f374
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ class Calendar extends React.Component {
*/
scrollToTime: PropTypes.instanceOf(Date),

/**
* Determines whether the scroll pane is automatically scrolled down or not.
*/
enableAutoScroll: PropTypes.bool,

/**
* Specify a specific culture code for the Calendar.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Day.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Day extends React.Component {
min = localizer.startOf(new Date(), 'day'),
max = localizer.endOf(new Date(), 'day'),
scrollToTime = localizer.startOf(new Date(), 'day'),
enableAutoScroll = true,
...props
} = this.props
let range = Day.range(date, { localizer: localizer })
Expand All @@ -30,6 +31,7 @@ class Day extends React.Component {
min={min}
max={max}
scrollToTime={scrollToTime}
enableAutoScroll={enableAutoScroll}
/>
)
}
Expand All @@ -41,6 +43,7 @@ Day.propTypes = {
min: PropTypes.instanceOf(Date),
max: PropTypes.instanceOf(Date),
scrollToTime: PropTypes.instanceOf(Date),
enableAutoScroll: PropTypes.bool,
}

Day.range = (date, { localizer }) => {
Expand Down
1 change: 1 addition & 0 deletions src/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ MonthView.propTypes = {
getNow: PropTypes.func.isRequired,

scrollToTime: PropTypes.instanceOf(Date),
enableAutoScroll: PropTypes.bool,
rtl: PropTypes.bool,
resizable: PropTypes.bool,
width: PropTypes.number,
Expand Down
4 changes: 3 additions & 1 deletion src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ export default class TimeGrid extends Component {
}

applyScroll() {
if (this._scrollRatio != null) {
// If auto-scroll is disabled, we don't actually apply the scroll
if (this._scrollRatio != null && this.props.enableAutoScroll === true) {
const content = this.contentRef.current
content.scrollTop = content.scrollHeight * this._scrollRatio
// Only do this once
Expand Down Expand Up @@ -352,6 +353,7 @@ TimeGrid.propTypes = {
getNow: PropTypes.func.isRequired,

scrollToTime: PropTypes.instanceOf(Date).isRequired,
enableAutoScroll: PropTypes.bool,
showMultiDayTimes: PropTypes.bool,

rtl: PropTypes.bool,
Expand Down
3 changes: 3 additions & 0 deletions src/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Week extends React.Component {
min = localizer.startOf(new Date(), 'day'),
max = localizer.endOf(new Date(), 'day'),
scrollToTime = localizer.startOf(new Date(), 'day'),
enableAutoScroll = true,
...props
} = this.props
let range = Week.range(date, this.props)
Expand All @@ -29,6 +30,7 @@ class Week extends React.Component {
min={min}
max={max}
scrollToTime={scrollToTime}
enableAutoScroll={enableAutoScroll}
/>
)
}
Expand All @@ -40,6 +42,7 @@ Week.propTypes = {
min: PropTypes.instanceOf(Date),
max: PropTypes.instanceOf(Date),
scrollToTime: PropTypes.instanceOf(Date),
enableAutoScroll: PropTypes.bool,
}

Week.defaultProps = TimeGrid.defaultProps
Expand Down
3 changes: 3 additions & 0 deletions src/WorkWeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class WorkWeek extends React.Component {
min = localizer.startOf(new Date(), 'day'),
max = localizer.endOf(new Date(), 'day'),
scrollToTime = localizer.startOf(new Date(), 'day'),
enableAutoScroll = true,
...props
} = this.props
let range = workWeekRange(date, this.props)
Expand All @@ -35,6 +36,7 @@ class WorkWeek extends React.Component {
min={min}
max={max}
scrollToTime={scrollToTime}
enableAutoScroll={enableAutoScroll}
/>
)
}
Expand All @@ -46,6 +48,7 @@ WorkWeek.propTypes = {
min: PropTypes.instanceOf(Date),
max: PropTypes.instanceOf(Date),
scrollToTime: PropTypes.instanceOf(Date),
enableAutoScroll: PropTypes.bool,
}

WorkWeek.defaultProps = TimeGrid.defaultProps
Expand Down

0 comments on commit aa8f374

Please sign in to comment.