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: add grid & cell role for screen ready accessibility, fixes #518 #976

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
18 changes: 11 additions & 7 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
this._container.style.outline = String(0);
this._container.classList.add(this.uid);
this._container.classList.add('ui-widget');
this._container.setAttribute('role', 'grid');

const containerStyles = window.getComputedStyle(this._container);
if (!(/relative|absolute|fixed/).test(containerStyles.position)) {
Expand Down Expand Up @@ -706,8 +707,8 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
this._headerScroller.push(this._headerScrollerR);

// Append the columnn containers to the headers
this._headerL = Utils.createDomElement('div', { className: 'slick-header-columns slick-header-columns-left', style: { left: '-1000px' } }, this._headerScrollerL);
this._headerR = Utils.createDomElement('div', { className: 'slick-header-columns slick-header-columns-right', style: { left: '-1000px' } }, this._headerScrollerR);
this._headerL = Utils.createDomElement('div', { className: 'slick-header-columns slick-header-columns-left', role: 'row', style: { left: '-1000px' } }, this._headerScrollerL);
this._headerR = Utils.createDomElement('div', { className: 'slick-header-columns slick-header-columns-right', role: 'row', style: { left: '-1000px' } }, this._headerScrollerR);

// Cache the header columns
this._headers = [this._headerL, this._headerR];
Expand Down Expand Up @@ -1615,7 +1616,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
const headerTarget = this.hasFrozenColumns() ? ((i <= this._options.frozenColumn!) ? this._headerL : this._headerR) : this._headerL;
const headerRowTarget = this.hasFrozenColumns() ? ((i <= this._options.frozenColumn!) ? this._headerRowL : this._headerRowR) : this._headerRowL;

const header = Utils.createDomElement('div', { id: `${this.uid + m.id}`, dataset: { id: String(m.id) }, className: 'ui-state-default slick-state-default slick-header-column' }, headerTarget);
const header = Utils.createDomElement('div', { id: `${this.uid + m.id}`, dataset: { id: String(m.id) }, role: 'columnheader', className: 'ui-state-default slick-state-default slick-header-column' }, headerTarget);
if (m.toolTip) {
header.title = m.toolTip;
}
Expand Down Expand Up @@ -3865,7 +3866,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

const frozenRowOffset = this.getFrozenRowOffset(row);
const rowDiv = Utils.createDomElement('div', { className: `ui-widget-content ${rowCss}`, style: { top: `${this.getRowTop(row) - frozenRowOffset}px` } });
const rowDiv = Utils.createDomElement('div', { className: `ui-widget-content ${rowCss}`, role: 'row', style: { top: `${this.getRowTop(row) - frozenRowOffset}px` } });
let rowDivR: HTMLElement | undefined;
divArrayL.push(rowDiv);
if (this.hasFrozenColumns()) {
Expand Down Expand Up @@ -3956,9 +3957,12 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

const toolTipText = (formatterResult as FormatterResultObject)?.toolTip ? `${(formatterResult as FormatterResultObject).toolTip}` : '';
const cellDiv = document.createElement('div');
cellDiv.className = `${cellCss} ${addlCssClasses || ''}`.trim();
cellDiv.setAttribute('title', toolTipText);
const cellDiv = Utils.createDomElement('div', { className: `${cellCss} ${addlCssClasses || ''}`.trim(), role: 'gridcell', tabIndex: -1 });
cellDiv.setAttribute('aria-describedby', this.uid + m.id);
if (toolTipText) {
cellDiv.setAttribute('title', toolTipText);
}

if (m.hasOwnProperty('cellAttrs') && m.cellAttrs instanceof Object) {
Object.keys(m.cellAttrs).forEach(key => {
if (m.cellAttrs.hasOwnProperty(key)) {
Expand Down