Skip to content

Commit fb73a5b

Browse files
authored
Correct behavior when isFixed is mutated (#981)
1 parent f1b88fa commit fb73a5b

File tree

2 files changed

+106
-10
lines changed

2 files changed

+106
-10
lines changed

addon/components/-private/base-table-cell.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ export default Component.extend({
6262
this.element.style.minWidth = width;
6363
this.element.style.maxWidth = width;
6464

65-
if (this.get('isFixedLeft')) {
66-
this.element.style.left = `${Math.round(this.get('columnMeta.offsetLeft'))}px`;
67-
} else if (this.get('isFixedRight')) {
68-
this.element.style.right = `${Math.round(this.get('columnMeta.offsetRight'))}px`;
69-
}
65+
this.element.style.left = this.get('isFixedLeft')
66+
? `${Math.round(this.get('columnMeta.offsetLeft'))}px`
67+
: null;
68+
this.element.style.right = this.get('isFixedRight')
69+
? `${Math.round(this.get('columnMeta.offsetRight'))}px`
70+
: null;
7071

7172
if (this.get('isSlack')) {
7273
this.element.style.paddingLeft = 0;

tests/integration/components/basic-test.js

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { module, test } from 'qunit';
22
import hbs from 'htmlbars-inline-precompile';
33
import a11yAudit from 'ember-a11y-testing/test-support/audit';
4+
import { set } from '@ember/object';
45

56
import { generateTable, generateColumns, generateRows } from '../../helpers/generate-table';
67
import { componentModule } from '../../helpers/module';
@@ -118,11 +119,6 @@ module('Integration | basic', function() {
118119
let rect = element.getBoundingClientRect();
119120
let diff = Math.abs(container[measurement] - rect[measurement]);
120121

121-
// Travis reports pretty wide differences for some reason, possibly
122-
// their Chrome version. It does validate that the elements are moving
123-
// and that should be enough to know if we messed something up majorly.
124-
//
125-
// TODO(sticky): Try to lower the tolerance as sticky becomes more prevalent
126122
assert.ok(diff < 10, `${diff} is with tolerance`);
127123
}
128124
}
@@ -139,33 +135,132 @@ module('Integration | basic', function() {
139135

140136
let tableContainerRect = find('.ember-table').getBoundingClientRect();
141137

138+
/**
139+
* No scroll.
140+
*
141+
* Assert the special cases:
142+
*
143+
* - Horizontally, the last column is stuck at the edge of the
144+
* container.
145+
* - Vertically, the footer is stuck at the edge of the container.
146+
*/
142147
validateElements(tableContainerRect, findAll('thead th'), 'top');
143148
validateElements(tableContainerRect, findAll('tr > *:first-child'), 'left');
144149
validateElements(tableContainerRect, findAll('tr > *:last-child'), 'right');
145150
validateElements(tableContainerRect, findAll('tfoot td'), 'bottom');
146151

147152
await scrollTo('[data-test-ember-table-overflow]', 10000, 0);
148153

154+
/**
155+
* Scrolled to the far right.
156+
*
157+
* Assert the special cases:
158+
*
159+
* - Horizontally, the first column is stuck at the edge of the
160+
* container.
161+
* - Vertically, the footer is stuck at the edge of the container.
162+
*/
149163
validateElements(tableContainerRect, findAll('thead th'), 'top');
150164
validateElements(tableContainerRect, findAll('tr > *:first-child'), 'left');
151165
validateElements(tableContainerRect, findAll('tr > *:last-child'), 'right');
152166
validateElements(tableContainerRect, findAll('tfoot td'), 'bottom');
153167

154168
await scrollTo('[data-test-ember-table-overflow]', 10000, 10000);
155169

170+
/**
171+
* Scrolled to the far bottom and far right.
172+
*
173+
* Assert the special cases:
174+
*
175+
* - Horizontally, the first column is stuck at the edge of the
176+
* container.
177+
* - Vertically, the header is stuck at the edge of the container.
178+
*/
156179
validateElements(tableContainerRect, findAll('thead th'), 'top');
157180
validateElements(tableContainerRect, findAll('tr > *:first-child'), 'left');
158181
validateElements(tableContainerRect, findAll('tr > *:last-child'), 'right');
159182
validateElements(tableContainerRect, findAll('tfoot td'), 'bottom');
160183

161184
await scrollTo('[data-test-ember-table-overflow]', 0, 10000);
162185

186+
/**
187+
* Scrolled to the far bottom.
188+
*
189+
* Assert the special cases:
190+
*
191+
* - Horizontally, the last column is stuck at the edge of the
192+
* container.
193+
* - Vertically, the header is stuck at the edge of the container.
194+
*/
163195
validateElements(tableContainerRect, findAll('thead th'), 'top');
164196
validateElements(tableContainerRect, findAll('tr > *:first-child'), 'left');
165197
validateElements(tableContainerRect, findAll('tr > *:last-child'), 'right');
166198
validateElements(tableContainerRect, findAll('tfoot td'), 'bottom');
167199
});
168200

201+
test('mutating fixed cells work', async function(assert) {
202+
await generateTable(this, {
203+
rowCount: 100,
204+
columnCount: 30,
205+
footerRowCount: 1,
206+
columnOptions: {
207+
fixedLeftCount: 1,
208+
fixedRightCount: 1,
209+
},
210+
});
211+
212+
let tableContainerRect = find('.ember-table').getBoundingClientRect();
213+
214+
/**
215+
* Just scroll around. See the prior test for assertions that the
216+
* behaviors after these actions are performed are correct.
217+
*/
218+
await scrollTo('[data-test-ember-table-overflow]', 10000, 10000);
219+
await scrollTo('[data-test-ember-table-overflow]', 0, 0);
220+
221+
/**
222+
* Mutate the fixed state of the first and last column
223+
*/
224+
set(this.columns[0], 'isFixed', null);
225+
set(this.columns[this.columns.length - 1], 'isFixed', null);
226+
227+
await settled();
228+
229+
/**
230+
* No scroll.
231+
*
232+
* Assert the special cases:
233+
*
234+
* - Horizontally, the last column is no longer stuck at the edge of
235+
* the container.
236+
*/
237+
let lastColumnRight = this.element.querySelector('tr > *:last-child').getBoundingClientRect()
238+
.right;
239+
let tableContainerRight = tableContainerRect.right;
240+
assert.true(
241+
lastColumnRight > tableContainerRight + 20,
242+
`last column right (${lastColumnRight}) is safely greater than the container's right (${tableContainerRight} + 20)`
243+
);
244+
245+
await scrollTo('[data-test-ember-table-overflow]', 10000, 0);
246+
247+
/**
248+
* Scrolled to far right.
249+
*
250+
* Assert the special cases:
251+
*
252+
* - Horizontally, the first column is no longer stuck at the edge of
253+
* the container.
254+
*/
255+
let firstColumnLeft = this.element.querySelector('tr > *:first-child').getBoundingClientRect()
256+
.left;
257+
let tableContainerLeft = tableContainerRect.left;
258+
assert.true(
259+
firstColumnLeft < tableContainerLeft - 20,
260+
`first column left (${firstColumnLeft}) is safely less than the container's left (${tableContainerLeft} - 20)`
261+
);
262+
});
263+
169264
test('Accessibility test', async function(assert) {
170265
await generateTable(this, { hasFixedColumn: true });
171266

0 commit comments

Comments
 (0)