Skip to content

Commit

Permalink
fix: 100% width table and button for sort (#1929)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsjolander authored Jan 21, 2025
1 parent e390b6e commit bd8f1cc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
69 changes: 52 additions & 17 deletions libs/angular/src/v-angular/table/table.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<ng-template #sortableThTemplate let-column>
<button class="sg-table-sort" *transloco="let t">
<ng-template #thButtonTemplate>
{{ t(column.label ?? '') }}
</ng-template>
<ng-container
*ngIf="
customHeaderTemplates.get(column.property) as thTemplate;
else thButtonTemplate
"
>
<ng-template
*ngTemplateOutlet="thTemplate || null; context: { $implicit: column }"
>
</ng-template>
</ng-container>
</button>
</ng-template>

<ng-template #notSortableThTemplate let-column>
<ng-template #defaultThTemplate>
<ng-container *transloco="let t">
{{ t(column.label ?? '') }}
</ng-container>
</ng-template>
<ng-container
*ngIf="
customHeaderTemplates.get(column.property) as thTemplate;
else defaultThTemplate
"
>
<ng-template
*ngTemplateOutlet="thTemplate || null; context: { $implicit: column }"
>
</ng-template>
</ng-container>
</ng-template>

<table class="gds-table" *transloco="let t">
<!-- Table header -->
<thead>
Expand Down Expand Up @@ -28,27 +66,24 @@
[attr.aria-label]="getAriaLabel(column)"
[attr.aria-sort]="column.order + 'ending'"
>
<ng-container
*ngIf="
customHeaderTemplates.get(column.property) as thTemplate;
else defaultThTemplate
"
>
<!-- Cannot infer thTemplate as TemplateRef therefore null -->
<ng-template
<ng-container *ngIf="column.sortable">
<ng-container
*ngTemplateOutlet="
thTemplate || null;
context: { $implicit: column }
sortableThTemplate;
context: { $implicit: column, column: column }
"
>
</ng-template>
</ng-container>
</ng-container>
<ng-container *ngIf="!column.sortable">
<ng-container
*ngTemplateOutlet="
notSortableThTemplate;
context: { $implicit: column, column: column }
"
>
</ng-container>
</ng-container>

<ng-template #defaultThTemplate>
<button class="sg-table-sort">
{{ t(column.label ?? '') }}
</button>
</ng-template>
</th>
</tr>
</thead>
Expand Down
3 changes: 3 additions & 0 deletions libs/angular/src/v-angular/table/table.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
--gds-ref-pallet-base500: hsl(0, 0%, 68%);
--sg-table-sort-icon-color-active: #fff;
@include table.add-table();
width: 100%;

border-bottom: none;

Expand Down Expand Up @@ -39,6 +40,8 @@
background-color: rgba(0, 0, 0, 0);
border: 0;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
padding: 0;
cursor: pointer;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/angular/src/v-angular/table/table.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export const columns: {
{
property: 'currency',
label: 'header.currency',
sortable: true,
sortable: false,
ariaLabelSortable:
'Activate to sort Currency column in {{sortOrder}} order',
},
{
property: 'bookedBalance',
label: 'header.bookedbalance',
valueType: 'numeric',
sortable: true,
sortable: false,
},
{
property: 'datedBalance',
Expand Down

0 comments on commit bd8f1cc

Please sign in to comment.