Skip to content

Commit

Permalink
remove margin if no toolbar is set
Browse files Browse the repository at this point in the history
  • Loading branch information
danrot committed Mar 26, 2018
1 parent 4926ab7 commit 134a051
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
Expand Up @@ -59,17 +59,18 @@ export default class ColumnList extends React.Component<Props> {

componentWillReceiveProps(nextProps: Props) {
if (this.container && nextProps.children !== this.props.children) {
this.container.scrollLeft = this.toolbarWidth * (nextProps.children.length - 1);
this.container.scrollLeft = this.columnWidth * (nextProps.children.length - 1);
}
}

get toolbarWidth(): number {
if (!this.toolbar) {
get columnWidth(): number {
const columnWidth = parseInt(columnListStyles.columnWidth);

if (isNaN(columnWidth)) {
return 0;
}

// remove the 1px border from the toolbar to get the correct width
return this.toolbar.clientWidth - 1;
return columnWidth;
}

get containerWidth(): number {
Expand Down Expand Up @@ -124,13 +125,13 @@ export default class ColumnList extends React.Component<Props> {

render() {
const {children, toolbarItems} = this.props;
const toolbarPosition = -this.scrollPosition + this.activeColumnIndex * this.toolbarWidth;
const toolbarPosition = -this.scrollPosition + this.activeColumnIndex * this.columnWidth;

const columnListContainerClass = classNames(
columnListStyles.columnListContainer,
{
[columnListStyles.firstVisibleColumnActive]: toolbarPosition <= 0,
[columnListStyles.lastVisibleColumnActive]: toolbarPosition >= this.containerWidth - this.toolbarWidth,
[columnListStyles.lastVisibleColumnActive]: toolbarPosition >= this.containerWidth - this.columnWidth,
}
);

Expand Down
@@ -1,6 +1,10 @@
@import '../../containers/Application/colors.scss';
@import './variables.scss';

:export {
column-width: $columnWidth;
}

.column-list-toolbar-container {
height: 100%;
width: 100%;
Expand All @@ -23,7 +27,7 @@
border-top-right-radius: 0;
}

& ~ .toolbar-container {
.toolbar-container ~ & {
height: calc(100% - $toolbarHeight);
}
}
Expand Down
Expand Up @@ -5,6 +5,19 @@ import ColumnList from '../ColumnList';
import Column from '../Column';
import Item from '../Item';

jest.mock('../columnList.scss', () => new Proxy({}, {
get: function(target, key) {
if (key === '__esModule') {
return false;
}
if (key === 'columnWidth') {
return '270px';
}

return key;
},
}));

test('The ColumnList component should render in a non-scrolling container', () => {
const onItemClick = jest.fn();

Expand Down Expand Up @@ -214,9 +227,6 @@ test('Should move the toolbar container to the correct position', () => {

expect(columnList.find('Toolbar').parent().prop('style')).toEqual({marginLeft: 0});

columnList.instance().toolbar = {
clientWidth: 271,
};
columnList.instance().scrollPosition = 35;
columnList.instance().activeColumnIndex = 2;
columnList.update();
Expand All @@ -233,14 +243,13 @@ test('Should set classes if the toolbar is active on the first or last visible c
</ColumnList>
);

columnList.update();

expect(columnList.find('.columnListContainer').prop('className'))
.toEqual(expect.stringContaining('firstVisibleColumnActive'));
expect(columnList.find('.columnListContainer').prop('className'))
.toEqual(expect.stringContaining('lastVisibleColumnActive'));

columnList.instance().toolbar = {
clientWidth: 271,
};
columnList.instance().container = {
clientWidth: 500,
};
Expand Down Expand Up @@ -270,9 +279,6 @@ test('Should scroll to the last column when new column is loaded', () => {
</ColumnList>
);

columnList.instance().toolbar = {
clientWidth: 271,
};
columnList.instance().container = {
clientWidth: 500,
};
Expand Down
Expand Up @@ -436,7 +436,7 @@ exports[`The ColumnList component should render in a scrolling container 1`] = `
>
<div
class="toolbarContainer"
style="margin-left: -22px;"
style="margin-left: 520px;"
>
<div
class="toolbar"
Expand All @@ -452,7 +452,7 @@ exports[`The ColumnList component should render in a scrolling container 1`] = `
</div>
</div>
<div
class="columnListContainer firstVisibleColumnActive"
class="columnListContainer lastVisibleColumnActive"
>
<div
class="columnList"
Expand Down
1 change: 1 addition & 0 deletions stylelint.config.js
Expand Up @@ -7,6 +7,7 @@ module.exports = { // eslint-disable-line
'selector-pseudo-class-no-unknown': [ true, {
ignorePseudoClasses: [
'global',
'export',
],
}],
'indentation': 4,
Expand Down

0 comments on commit 134a051

Please sign in to comment.