Skip to content

Commit

Permalink
fix(table): prevent jumping headers when sorting (#2265)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-ico authored Feb 15, 2024
1 parent b953a37 commit 94f0cd4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/components/src/components/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ scale-table {
--border-bottom-tfoot-td: var(--telekom-spacing-composition-space-01) solid
var(--telekom-color-ui-extra-strong);

--spacing-th-sortable: 0 var(--telekom-spacing-composition-space-04) 0 0;
--spacing-th-sortable: 0 0 0 0;
--background-th-sortable-hover: var(--telekom-color-ui-subtle);
--background-th-sortable-active: var(--telekom-color-ui-faint);
--box-shadow-th-sortable-focus: inset 0 0 0
Expand Down Expand Up @@ -100,6 +100,7 @@ scale-table {
.table--sortable th {
cursor: pointer;
padding: var(--spacing-th-sortable);
padding-right: 0;
}
.table--sortable th:hover {
padding: var(--spacing-th-sortable);
Expand All @@ -121,9 +122,11 @@ scale-table {
}
.table--sortable th:not([aria-sort]) {
padding: var(--padding);
padding-right: var(--telekom-spacing-composition-space-07);
}
.table--sortable th[aria-sort='none'] {
padding: var(--padding);
padding-right: var(--telekom-spacing-composition-space-05);
}
.table--sortable th[aria-sort='ascending'] .scale-sort-indicator .up {
color: var(--color);
Expand Down Expand Up @@ -188,7 +191,7 @@ scale-table {
color: transparent;
}
.table--sortable th[aria-sort='none']:hover {
padding: 0 8px 0 0;
padding: 0 0 0 0;
}
.table--sortable th[aria-sort='none'] .scale-sort-indicator {
display: none;
Expand Down
24 changes: 21 additions & 3 deletions packages/components/src/components/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ describe('Table', () => {
<table>
<thead>
<tr>
<th>Title</th>
<th>Time</th>
<th>Euros</th>
<th>
<span aria-hidden="true" class="scale-sort-indicator">
<scale-icon-content-sort-indicator-up class="scale-sort-indicator-icon up" size="16"></scale-icon-content-sort-indicator-up>
<scale-icon-content-sort-indicator-down class="down scale-sort-indicator-icon" size="16"></scale-icon-content-sort-indicator-down>
</span>
Title
</th>
<th>
<span aria-hidden="true" class="scale-sort-indicator">
<scale-icon-content-sort-indicator-up class="scale-sort-indicator-icon up" size="16"></scale-icon-content-sort-indicator-up>
<scale-icon-content-sort-indicator-down class="down scale-sort-indicator-icon" size="16"></scale-icon-content-sort-indicator-down>
</span>
Time
</th>
<th>
<span aria-hidden="true" class="scale-sort-indicator">
<scale-icon-content-sort-indicator-up class="scale-sort-indicator-icon up" size="16"></scale-icon-content-sort-indicator-up>
<scale-icon-content-sort-indicator-down class="down scale-sort-indicator-icon" size="16"></scale-icon-content-sort-indicator-down>
</span>
Euros
</th>
</tr>
</thead>
<tbody>
Expand Down
12 changes: 8 additions & 4 deletions packages/components/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export class Table {
}

componentWillLoad() {
this.hostElement.querySelectorAll('th').forEach((th) => {
this.addSortIndicator(th);
});
if (this.showSort) {
this.hostElement.querySelectorAll('th').forEach((th) => {
this.addSortIndicator(th);
});
}
}

componentWillUpdate() {
Expand All @@ -58,7 +60,9 @@ export class Table {
if (th.children.length === 0) {
// this may not be needed
th.classList.add('dynamically-added');
this.addSortIndicator(th);
if (this.showSort) {
this.addSortIndicator(th);
}
}
});
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 94f0cd4

Please sign in to comment.