Skip to content

Commit

Permalink
Merge branch 'main' into feat/slug-tile-ai-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Feb 2, 2024
2 parents 8a582fb + 2259364 commit e1d1ddf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ class CDSTableHeaderCell extends FocusMixin(LitElement) {
><slot name="slug" @slotchange="${this._handleSlugSlotChange}"></slot
></span> `;
}

/**
* A selector that will return the slug item.
*/
Expand Down
73 changes: 44 additions & 29 deletions packages/carbon-web-components/src/components/data-table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,42 +664,24 @@ class CDSTable extends HostListenerMixin(LitElement) {
}

if (changedProperties.has('isSelectable')) {
this._tableHeaderRow.setAttribute('selection-name', 'header');
this._tableRows.forEach((e, index) => {
if (!e.hasAttribute('selection-name')) {
e.setAttribute('selection-name', index);
}
});
if (this.isSelectable) {
this._tableHeaderRow.setAttribute('selection-name', 'header');
this._tableRows.forEach((e, index) => {
if (!e.hasAttribute('selection-name')) {
e.setAttribute('selection-name', index);
}
});
}
this.headerCount++;
}

if (changedProperties.has('locale')) {
this.collator = new Intl.Collator(this.locale);
}
if (changedProperties.has('isSortable')) {
const headerCells = this.querySelectorAll(
(this.constructor as typeof CDSTable).selectorHeaderCell
);
headerCells.forEach((e) => {
(e as CDSTableHeaderCell).isSortable = this.isSortable;
(e as CDSTableHeaderCell).isSelectable = this.isSelectable;
(e as CDSTableHeaderCell).isExpandable = this.expandable;
});
const columns = [...this._tableHeaderRow.children];
columns.forEach((column, index) => {
if (
column.hasAttribute('sort-direction') &&
column.getAttribute('sort-direction') !== 'none'
) {
const sortDirection = column.getAttribute('sort-direction');
const columnIndex = index;

columns.forEach(
(e) => e !== column && e.setAttribute('sort-direction', 'none')
);
this._handleSortAction(columnIndex, sortDirection);
}
});
if (this.isSortable) {
this._enableSortAction();
}
}

if (
Expand Down Expand Up @@ -813,6 +795,39 @@ class CDSTable extends HostListenerMixin(LitElement) {
: html`<slot></slot>`}
`;
}

/**
* Adds isSortable value for table header cells.
*/
_enableSortAction() {
const headerCells = this.querySelectorAll(
(this.constructor as typeof CDSTable).selectorHeaderCell
);
headerCells.forEach((e) => {
(e as CDSTableHeaderCell).isSortable = this.isSortable;
(e as CDSTableHeaderCell).isSelectable = this.isSelectable;
(e as CDSTableHeaderCell).isExpandable = this.expandable;
});
const columns = [...this._tableHeaderRow.children];
let sortDirection;
let columnIndex = -1;
columns.forEach((column, index) => {
if (
column.hasAttribute('sort-direction') &&
column.getAttribute('sort-direction') !== 'none'
) {
sortDirection = column.getAttribute('sort-direction');
columnIndex = index;
}
});

columns.forEach(
(e, index) =>
index !== columnIndex && e.setAttribute('sort-direction', 'none')
);
this._handleSortAction(columnIndex, sortDirection);
}

/* eslint-enable no-constant-condition */

/**
Expand Down

0 comments on commit e1d1ddf

Please sign in to comment.