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

Only add scrollbar height to tables if needed #74

Merged
merged 1 commit into from
Apr 6, 2016
Merged
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
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