Skip to content

Commit

Permalink
user more precision when querying DOM dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Aug 7, 2019
1 parent 0605a56 commit 9443b99
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/CalendarComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ export default class CalendarComponent extends Component<CalendarComponentProps>
} else if (typeof heightInput === 'function') { // exists and is a function
this.viewHeight = heightInput() - this.queryToolbarsHeight()
} else if (heightInput === 'parent') { // set to height of parent element
this.viewHeight = (this.el.parentNode as HTMLElement).offsetHeight - this.queryToolbarsHeight()
let parentEl = this.el.parentNode as HTMLElement
this.viewHeight = parentEl.getBoundingClientRect().height - this.queryToolbarsHeight()
} else {
this.viewHeight = Math.round(
this.contentEl.offsetWidth /
this.contentEl.getBoundingClientRect().width /
Math.max(calendar.opt('aspectRatio'), .5)
)
}
Expand All @@ -274,7 +275,7 @@ export default class CalendarComponent extends Component<CalendarComponentProps>

freezeHeight() {
applyStyle(this.el, {
height: this.el.offsetHeight,
height: this.el.getBoundingClientRect().height,
overflow: 'hidden'
})
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/util/dom-geom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export function computeEdges(el, getPadding = false): EdgeInfo {
let borderRight = parseInt(computedStyle.borderRightWidth, 10) || 0
let borderTop = parseInt(computedStyle.borderTopWidth, 10) || 0
let borderBottom = parseInt(computedStyle.borderBottomWidth, 10) || 0

// must use offset(Width|Height) because compatible with client(Width|Height)
let scrollbarLeftRight = sanitizeScrollbarWidth(el.offsetWidth - el.clientWidth - borderLeft - borderRight)
let scrollbarBottom = sanitizeScrollbarWidth(el.offsetHeight - el.clientHeight - borderTop - borderBottom)

let res: EdgeInfo = {
borderLeft,
borderRight,
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/util/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function matchCellWidths(els: HTMLElement[]) {
els.forEach(function(el) {
let innerEl = el.firstChild // hopefully an element
if (innerEl instanceof HTMLElement) {
let innerWidth = innerEl.offsetWidth
let innerWidth = innerEl.getBoundingClientRect().width
if (innerWidth > maxInnerWidth) {
maxInnerWidth = innerWidth
}
Expand Down Expand Up @@ -154,7 +154,9 @@ export function subtractInnerElHeight(outerEl: HTMLElement, innerEl: HTMLElement
applyStyle(outerEl, reflowStyleProps)
applyStyle(innerEl, reflowStyleProps)

let diff = outerEl.offsetHeight - innerEl.offsetHeight // grab the dimensions
let diff = // grab the dimensions
outerEl.getBoundingClientRect().height -
innerEl.getBoundingClientRect().height

// undo hack
let resetStyleProps = { position: '', left: '' }
Expand Down
3 changes: 2 additions & 1 deletion packages/timegrid/src/AbstractTimeGridView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export default abstract class TimeGridView extends View {
)

// have the day-grid extend it's coordinate area over the <hr> dividing the two grids
this.dayGrid.bottomCoordPadding = (this.el.querySelector('.fc-divider') as HTMLElement).offsetHeight
let dividerEl = this.el.querySelector('.fc-divider') as HTMLElement
this.dayGrid.bottomCoordPadding = dividerEl.getBoundingClientRect().height
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/timegrid/src/TimeGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ export default class TimeGrid extends DateComponent<TimeGridProps> {


getTotalSlatHeight() {
return this.slatContainerEl.offsetHeight
return this.slatContainerEl.getBoundingClientRect().height
}


Expand Down

0 comments on commit 9443b99

Please sign in to comment.