Skip to content

Commit

Permalink
Enforce min and max width constraints before initial fill (#881)
Browse files Browse the repository at this point in the history
Ensures that min and max column widths are enforced on initial render.

Before, min and max column widths were only enforced in two cases:
* when the widthConstraint mode was violated
* when the user manually resized column

In particular, if `widthConstraint` was `none`, or the chosen `widthConstraint` was not initially violated (e.g. `lte-container` with few columns), min and max column widths would be ignored on initial render.
  • Loading branch information
ahmacleod authored Mar 16, 2021
1 parent 4a59838 commit eec0594
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addon/-private/column-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,18 @@ export default EmberObject.extend({
return;
}

let leaves = get(this, 'root.leaves');

// ensures that min and max widths are respected _before_ `applyFillMode()`
// decides if the width constraint has been violated
leaves.forEach(leaf => {
let width = get(leaf, 'width');
let minWidth = get(leaf, 'minWidth');
let maxWidth = get(leaf, 'maxWidth');
let newWidth = Math.min(Math.max(width, minWidth), maxWidth);
set(leaf, 'width', newWidth);
});

let isSlackModeEnabled = get(this, 'isSlackModeEnabled');
let initialFillMode = get(this, 'initialFillMode');

Expand Down
32 changes: 32 additions & 0 deletions tests/integration/components/headers/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ import TablePage from 'ember-table/test-support/pages/ember-table';
const table = new TablePage();

module('Integration | header | main', function() {
componentModule('initial render', function() {
test('min column widths respected', async function(assert) {
await generateTable(this, {
columnCount: 1,
columnOptions: {
width: 100,
minWidth: 200,
},
});

let header = table.headers.objectAt(0);
assert.equal(header.width, 200, 'column has min width');
});

test('max column widths respected', async function(assert) {
await generateTable(this, {
columnCount: 1,
columnOptions: {
width: 200,
maxWidth: 100,
},
});

let header = table.headers.objectAt(0);
assert.equal(header.width, 100, 'column has max width');
});
});

componentModule('widthConstraint', function() {
test('eq-container when smaller', async function(assert) {
await generateTable(this, {
Expand Down Expand Up @@ -202,6 +230,7 @@ module('Integration | header | main', function() {
columnCount: 2,
columnOptions: {
width: columnWidth,
minWidth: columnWidth,
},
});

Expand All @@ -228,6 +257,7 @@ module('Integration | header | main', function() {
columnCount: 2,
columnOptions: {
width: columnWidth,
minWidth: columnWidth,
},
});

Expand Down Expand Up @@ -255,6 +285,7 @@ module('Integration | header | main', function() {
columnCount: 3,
columnOptions: {
width: columnWidth,
minWidth: columnWidth,
},
});

Expand All @@ -277,6 +308,7 @@ module('Integration | header | main', function() {
columnCount: 3,
columnOptions: {
width: columnWidth,
minWidth: columnWidth,
},
});

Expand Down

0 comments on commit eec0594

Please sign in to comment.