Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: time grid header component margin is not recalculated when the s… #2411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/TimeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import clsx from 'clsx'
import * as animationFrame from 'dom-helpers/animationFrame'
import memoize from 'memoize-one'
import scrollbarSize from 'dom-helpers/scrollbarSize'

import DayColumn from './DayColumn'
import TimeGutter from './TimeGutter'
Expand All @@ -21,7 +22,11 @@ export default class TimeGrid extends Component {
constructor(props) {
super(props)

this.state = { gutterWidth: undefined, isOverflowing: null }
this.state = {
gutterWidth: undefined,
isOverflowing: null,
scrollBarSize: scrollbarSize(),
}

this.scrollRef = React.createRef()
this.contentRef = React.createRef()
Expand All @@ -44,6 +49,12 @@ export default class TimeGrid extends Component {
this.applyScroll()

window.addEventListener('resize', this.handleResize)

const resizeObserver = new ResizeObserver(this.getScrollBarSize)

if (this.contentRef && this.contentRef.current) {
resizeObserver.observe(this.contentRef.current)
}
}

handleScroll = (e) => {
Expand Down Expand Up @@ -275,6 +286,7 @@ export default class TimeGrid extends Component {
onDrillDown={this.props.onDrillDown}
getDrilldownView={this.props.getDrilldownView}
resizable={resizable}
scrollBarSize={this.state.scrollBarSize}
/>
{this.props.popup && this.renderOverlay()}
<div
Expand Down Expand Up @@ -402,6 +414,13 @@ export default class TimeGrid extends Component {
}
}

getScrollBarSize = () => {
const scrollBarSize = scrollbarSize(true)
if (this.state.scrollBarSize !== scrollBarSize) {
this.setState({ scrollBarSize })
}
}

memoizedResources = memoize((resources, accessors) =>
Resources(resources, accessors)
)
Expand Down
5 changes: 3 additions & 2 deletions src/TimeGridHeader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import PropTypes from 'prop-types'
import clsx from 'clsx'
import scrollbarSize from 'dom-helpers/scrollbarSize'
import React from 'react'

import DateContentRow from './DateContentRow'
Expand Down Expand Up @@ -128,11 +127,12 @@ class TimeGridHeader extends React.Component {
resourceHeader: ResourceHeaderComponent = ResourceHeader,
},
resizable,
scrollBarSize,
} = this.props

let style = {}
if (isOverflowing) {
style[rtl ? 'marginLeft' : 'marginRight'] = `${scrollbarSize() - 1}px`
style[rtl ? 'marginLeft' : 'marginRight'] = `${scrollBarSize - 1}px`
}

const groupedEvents = resources.groupEvents(events)
Expand Down Expand Up @@ -212,6 +212,7 @@ TimeGridHeader.propTypes = {
rtl: PropTypes.bool,
resizable: PropTypes.bool,
width: PropTypes.number,
scrollBarSize: PropTypes.number,

localizer: PropTypes.object.isRequired,
accessors: PropTypes.object.isRequired,
Expand Down