Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Accessability): Add button role to table header interactive element #347

Merged
merged 7 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions coral-component-table/src/scripts/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
if (headerCell) {
// For icons (chevron up/down) styling
headerCell.setAttribute('sortabledirection', column.sortableDirection);
(table.head.sticky ? headerCell.content : headerCell).setAttribute('aria-sort', column.sortableDirection === sortableDirection.DEFAULT ? 'none' : column.sortableDirection);
headerCell.setAttribute('aria-sort', column.sortableDirection === sortableDirection.DEFAULT ? 'none' : column.sortableDirection);

if (column.sortableDirection === sortableDirection.DEFAULT) {
this._elements.liveRegion.innerText = '';
Expand Down Expand Up @@ -1713,7 +1713,7 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
// For icons (chevron up/down) styling
getSiblingsOf(colHeaderCell, 'th[is="coral-table-headercell"]').forEach((headerCell) => {
headerCell.setAttribute('sortabledirection', sortableDirection.DEFAULT);
(table.head.sticky ? headerCell.content : headerCell).setAttribute('aria-sort', 'none');
headerCell.setAttribute('aria-sort', 'none');
});
}

Expand Down Expand Up @@ -1768,7 +1768,7 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
if (colHeaderCell) {
getSiblingsOf(colHeaderCell, 'th[is="coral-table-headercell"]').forEach((headerCell) => {
headerCell.setAttribute('sortabledirection', sortableDirection.DEFAULT);
(table.head.sticky ? headerCell.content : headerCell).setAttribute('aria-sort', 'none');
headerCell.setAttribute('aria-sort', 'none');
});
}

Expand Down Expand Up @@ -2014,8 +2014,8 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
_toggleHeaderCellTabIndex(headerCell, sticky) {
const column = this._getColumn(headerCell);
const sortable = column && (column.sortable || column.orderable);
headerCell[sortable && !sticky ? 'setAttribute' : 'removeAttribute']('tabindex', '0');
headerCell.content[sortable && sticky ? 'setAttribute' : 'removeAttribute']('tabindex', '0');
headerCell.content[sortable ? 'setAttribute' : 'removeAttribute']('tabindex', '0');
headerCell.content[sortable ? 'setAttribute' : 'removeAttribute']('role', 'button');
}

/** @private */
Expand Down Expand Up @@ -2111,7 +2111,7 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {

/** @private */
_getFocusableHeaderCell() {
return this.head && this.head.querySelector('th[is="coral-table-headercell"][tabindex="0"], coral-table-headercell-label[tabindex="0"]');
return this.head && this.head.querySelector('th[is="coral-table-headercell"][tabindex="0"], th[is="coral-table-headercell"] > coral-table-headercell-content[tabindex="0"]');
}

/** @private */
Expand Down Expand Up @@ -2457,20 +2457,11 @@ const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
// Add appropriate scope depending on whether header cell is in THEAD or TBODY
const scope = tableSection.nodeName === 'THEAD' || tableSection.nodeName === 'TFOOT' ? 'col' : 'row';
if (scope === 'col') {
if (this.head && this.head.sticky) {
headerCell.setAttribute('role', 'presentation');
headerCell._elements.content.setAttribute('role', 'columnheader');
} else {
headerCell.setAttribute('role', 'columnheader');
}
headerCell.setAttribute('role', 'columnheader');
} else {
headerCell.setAttribute('role', 'rowheader');
}
headerCell.setAttribute('scope', scope);

if(headerCell.hasAttribute('sortable')){
headerCell.content.setAttribute('role', 'button');
}
}

/** @private */
Expand Down
8 changes: 4 additions & 4 deletions coral-component-table/src/tests/test.Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3089,7 +3089,7 @@ describe('Table', function () {
helpers.next(() => {
expect(col.sortableDirection).to.equal(Table.Column.sortableDirection.DEFAULT);
expect(headerCell.getAttribute('sortabledirection')).to.equal(col.sortableDirection);
expect(headerCell._elements.content.getAttribute('aria-sort')).to.equal('none');
expect(headerCell.getAttribute('aria-sort')).to.equal('none');
done();
});
});
Expand All @@ -3106,7 +3106,7 @@ describe('Table', function () {
expect(eventSpy.args[0][0].detail.column).to.equal(col);
expect(col.sortableDirection).to.equal(Table.Column.sortableDirection.ASCENDING);
expect(headerCell.getAttribute('sortabledirection')).to.equal(col.sortableDirection);
expect(headerCell._elements.content.getAttribute('aria-sort')).to.equal(col.sortableDirection);
expect(headerCell.getAttribute('aria-sort')).to.equal(col.sortableDirection);
done();
});
});
Expand All @@ -3124,7 +3124,7 @@ describe('Table', function () {
expect(eventSpy.args[0][0].detail.column).to.equal(col);
expect(col.sortableDirection).to.equal(Table.Column.sortableDirection.DESCENDING);
expect(headerCell.getAttribute('sortabledirection')).to.equal(col.sortableDirection);
expect(headerCell._elements.content.getAttribute('aria-sort')).to.equal(col.sortableDirection);
expect(headerCell.getAttribute('aria-sort')).to.equal(col.sortableDirection);
done();
});
});
Expand All @@ -3143,7 +3143,7 @@ describe('Table', function () {
expect(eventSpy.args[0][0].detail.column).to.equal(col);
expect(col.sortableDirection).to.equal(Table.Column.sortableDirection.DEFAULT);
expect(headerCell.getAttribute('sortabledirection')).to.equal(col.sortableDirection);
expect(headerCell._elements.content.getAttribute('aria-sort')).to.equal('none');
expect(headerCell.getAttribute('aria-sort')).to.equal('none');
done();
});
});
Expand Down
Loading