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

Change width style handling #628

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
31 changes: 17 additions & 14 deletions addon/-private/column-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import { assert } from '@ember/debug';

const SCROLL_THRESHOLD = 50;

const DEFAULT_COLUMN_WIDTH = 100;
const DEFAULT_MIN_WIDTH = 50;
const DEFAULT_MAX_WIDTH = Infinity;

const LOOP_COUNT_GUARD = 500;

export const RESIZE_MODE = {
Expand Down Expand Up @@ -66,7 +62,7 @@ function divideRounded(x, n) {
class TableColumnMeta extends EmberObject {
// If no width is set on the column itself, we cache a temporary width on the
// meta object. This is set to the default width.
_width = DEFAULT_COLUMN_WIDTH;
_width = null;

@readOnly('_node.isLeaf')
isLeaf;
Expand All @@ -86,6 +82,12 @@ class TableColumnMeta extends EmberObject {
@readOnly('_node.width')
width;

@readOnly('_node.minWidth')
minWidth;

@readOnly('_node.maxWidth')
maxWidth;

@readOnly('_node.offsetLeft')
offsetLeft;

Expand Down Expand Up @@ -322,7 +324,7 @@ class ColumnTreeNode extends EmberObject {
if (get(this, 'isLeaf')) {
let columnMinWidth = get(this, 'column.minWidth');

return typeof columnMinWidth === 'number' ? columnMinWidth : DEFAULT_MIN_WIDTH;
return typeof columnMinWidth === 'number' ? columnMinWidth : null;
}

return get(this, 'subcolumnNodes').reduce((sum, subcolumn) => {
Expand All @@ -332,12 +334,12 @@ class ColumnTreeNode extends EmberObject {
}, 0);
}

@computed('column.minWidth')
@computed('column.maxWidth')
get maxWidth() {
if (get(this, 'isLeaf')) {
let columnMaxWidth = get(this, 'column.maxWidth');

return typeof columnMaxWidth === 'number' ? columnMaxWidth : DEFAULT_MAX_WIDTH;
return typeof columnMaxWidth === 'number' ? columnMaxWidth : null;
}

return get(this, 'subcolumnNodes').reduce((sum, subcolumn) => {
Expand All @@ -357,7 +359,8 @@ class ColumnTreeNode extends EmberObject {
return columnWidth;
} else {
let meta = get(this, 'tree.columnMetaCache').get(column);
return get(meta, '_width');
let metaWidth = get(meta, '_width');
return typeof metaWidth === 'number' ? metaWidth : null;
}
}

Expand Down Expand Up @@ -487,7 +490,7 @@ class ColumnTreeNode extends EmberObject {
}

let subcolumns = get(parent, 'subcolumnNodes');
let offsetLeft = get(parent, 'offsetLeft');
let offsetLeft = get(parent, 'element.offsetLeft');

for (let column of subcolumns) {
if (column === this) {
Expand Down Expand Up @@ -756,9 +759,9 @@ export default class ColumnTree extends EmberObject {
let subcolumns = get(column.parent, 'subcolumnNodes');

for (let column of subcolumns) {
let offset = get(column, 'offsetLeft');
let offset = get(column, 'element.offsetLeft');

if (left < offset + get(column, 'width')) {
if (left < offset + get(column, 'element.offsetWidth')) {
return column;
}
}
Expand All @@ -768,7 +771,7 @@ export default class ColumnTree extends EmberObject {

getClosestColumnOffset(column, left, isFixed) {
let closestColumn = this.getClosestColumn(column, left, isFixed);
let offsetLeft = get(closestColumn, 'offsetLeft');
let offsetLeft = get(closestColumn, 'element.offsetLeft');

// If the column is fixed, readjust the offset so that it's correct within
// the container
Expand Down Expand Up @@ -839,7 +842,7 @@ export default class ColumnTree extends EmberObject {

this._reorderDropIndicator.width = get(
this.getClosestColumn(node, this._reorderDropIndicator.left, get(node, 'isFixed')),
'width'
'element.offsetWidth'
);
}

Expand Down
20 changes: 16 additions & 4 deletions addon/components/-private/base-table-cell.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import Component from '@ember/component';
import { equal } from '@ember/object/computed';
import { equal, bool } from '@ember/object/computed';
import { observer } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';

export default Component.extend({
// Provided by subclasses
columnMeta: null,

classNameBindings: ['isFirstColumn', 'isFixedLeft', 'isFixedRight'],
classNameBindings: [
'isFirstColumn',
'isFixedLeft',
'isFixedRight',
'hasWidth',
'hasMinWidth',
'hasMaxWidth',
],

isFirstColumn: equal('columnMeta.index', 0),
isFixedLeft: equal('columnMeta.isFixed', 'left'),
isFixedRight: equal('columnMeta.isFixed', 'right'),
hasWidth: bool('columnMeta.width'),
hasMinWidth: bool('columnMeta.minWidth'),
hasMaxWidth: bool('columnMeta.maxWidth'),

// eslint-disable-next-line
scheduleUpdateStyles: observer(
Expand All @@ -27,10 +37,12 @@ export default Component.extend({
updateStyles() {
if (typeof FastBoot === 'undefined' && this.element) {
let width = `${this.get('columnMeta.width')}px`;
let minWidth = `${this.get('columnMeta.minWidth')}px`;
let maxWidth = `${this.get('columnMeta.maxWidth')}px`;

this.element.style.width = width;
this.element.style.minWidth = width;
this.element.style.maxWidth = width;
this.element.style.minWidth = minWidth;
this.element.style.maxWidth = maxWidth;

if (this.get('isFixedLeft')) {
this.element.style.left = `${Math.round(this.get('columnMeta.offsetLeft'))}px`;
Expand Down