Skip to content

Commit

Permalink
fix(Table): correctly set any possible column alignment
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #2066
  • Loading branch information
benjamincharity committed Mar 6, 2020
1 parent c307664 commit 954291b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion projects/library/table/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function setColumnAlignment(column: TsColumnDefDirective, renderer: Rende
+ `See "TsTableColumnAlignment" type for available options.`);
}

renderer.addClass(elementRef.nativeElement, 'ts-cell--align-right');
renderer.addClass(elementRef.nativeElement, `ts-cell--align-${column.alignment}`);
}
}

Expand Down
8 changes: 8 additions & 0 deletions projects/library/table/src/table.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
justify-content: flex-end;
}
}

&--align-left {
text-align: left;
}

&--align-center {
text-align: center;
}
}

// Body cell
Expand Down
9 changes: 6 additions & 3 deletions projects/library/table/src/table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ describe(`TsTableComponent`, function() {
});

test(`should add the text-align class`, () => {
const column = fixture.nativeElement.querySelector('.ts-cell.ts-column-column_a');

expect(column.classList).toContain('ts-cell--align-right');
const columnA = fixture.nativeElement.querySelector('.ts-cell.ts-column-column_a');
const columnB = fixture.nativeElement.querySelector('.ts-cell.ts-column-column_b');
const columnC = fixture.nativeElement.querySelector('.ts-cell.ts-column-column_c');
expect(columnA.classList).toContain('ts-cell--align-left');
expect(columnB.classList).toContain('ts-cell--align-center');
expect(columnC.classList).toContain('ts-cell--align-right');
});

test(`should NOT add the text-align style if alignment is not provided`, () => {
Expand Down
7 changes: 4 additions & 3 deletions projects/library/table/testing/src/test-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
import {
TsTableColumnsChangeEvent,
TsTableComponent,
TsTableDataSource, TsTableDensity,
TsTableDataSource,
TsTableDensity,
TsTableModule,
} from '@terminus/ui/table';

Expand Down Expand Up @@ -164,12 +165,12 @@ export class ArrayDataSourceTableApp {
<td ts-cell *tsCellDef="let row">{{ row.a }}</td>
</ng-container>
<ng-container tsColumnDef="column_b">
<ng-container tsColumnDef="column_b" alignment="center">
<th ts-header-cell *tsHeaderCellDef>Column B</th>
<td ts-cell *tsCellDef="let row">{{ row.b }}</td>
</ng-container>
<ng-container tsColumnDef="column_c">
<ng-container tsColumnDef="column_c" alignment="right">
<th ts-header-cell *tsHeaderCellDef>Column C</th>
<td ts-cell *tsCellDef="let row">{{ row.c }}</td>
</ng-container>
Expand Down

0 comments on commit 954291b

Please sign in to comment.