From 316a3a208719555239ad092feffbc0529ab10467 Mon Sep 17 00:00:00 2001 From: Chris Ball Date: Wed, 6 Apr 2016 15:32:22 -0400 Subject: [PATCH] Only add scrollbar height to tables if needed Only add scrollbar height if on windows and the table actually has a horizontal scrollbar. --- addon/components/justa-table.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/addon/components/justa-table.js b/addon/components/justa-table.js index 8ab3589..582ffb1 100644 --- a/addon/components/justa-table.js +++ b/addon/components/justa-table.js @@ -19,6 +19,8 @@ const { inject: { service } } = Ember; +const HORIZONTAL_SCROLLBAR_HEIGHT = 15; + export default Component.extend(InViewportMixin, { layout, classNames: ['justa-table'], @@ -122,20 +124,28 @@ export default Component.extend(InViewportMixin, { let actualHeight = this.$('.table-columns table').outerHeight(); let totalHeight = actualHeight === 0 ? requestedHeight : Math.min(requestedHeight, actualHeight); let isWindows = this.get('isWindows'); + let shouldAddHeightBuffer = isWindows && this._hasHorizontalScroll(); - if (isWindows) { - totalHeight = totalHeight + 16; + if (shouldAddHeightBuffer) { + totalHeight = totalHeight + HORIZONTAL_SCROLLBAR_HEIGHT; } this.$().height(totalHeight); - // windows does not respect the height set, so it needs a 2px buffer - this.$('.table-columns').height(isWindows ? totalHeight + 2 : totalHeight); + // windows does not respect the height set, so it needs a 2px buffer if horizontal scrollbar + this.$('.table-columns').height(shouldAddHeightBuffer ? totalHeight + 2 : totalHeight); run.next(() => { this.set('containerSize', totalHeight); }); }, + _hasHorizontalScroll() { + let tableWidth = this.$('.standard-table-columns-wrapper table').outerWidth(); + let containerWidth = this.$('.standard-table-columns-wrapper .table-columns').outerWidth(); + + return tableWidth > containerWidth; + }, + /** Windows machines need slightly different css for scrollable containers. Returns a boolean that is applied as a classNameBinding to the justa-table