Skip to content

Commit

Permalink
Merge pull request #74 from cball/only-add-scrollbar-height-if-needed
Browse files Browse the repository at this point in the history
Only add scrollbar height to tables if needed
  • Loading branch information
cball committed Apr 6, 2016
2 parents cbaf001 + 316a3a2 commit f9a4d81
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions addon/components/justa-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const {
inject: { service }
} = Ember;

const HORIZONTAL_SCROLLBAR_HEIGHT = 15;

export default Component.extend(InViewportMixin, {
layout,
classNames: ['justa-table'],
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f9a4d81

Please sign in to comment.