Skip to content

feat(table): Improve accessibility of interaction-mode: static Table #8754

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

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 0 additions & 2 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4769,7 +4769,6 @@ export namespace Components {
"messages": TableHeaderMessages;
"numberCell": boolean;
"parentRowIsSelected": boolean;
"parentRowPosition": number;
"parentRowType": RowType;
"positionInRow": number;
/**
Expand Down Expand Up @@ -12276,7 +12275,6 @@ declare namespace LocalJSX {
"messages"?: TableHeaderMessages;
"numberCell"?: boolean;
"parentRowIsSelected"?: boolean;
"parentRowPosition"?: number;
"parentRowType"?: RowType;
"positionInRow"?: number;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { Component, Element, h, Host, Method, Prop, State, VNode, Watch } from "@stencil/core";
import {
Component,
Element,
Fragment,
h,
Host,
Method,
Prop,
State,
VNode,
Watch,
} from "@stencil/core";
import { Alignment, Scale } from "../interfaces";
import {
componentFocusable,
Expand Down Expand Up @@ -237,18 +248,24 @@ export class TableCell
colSpan={this.colSpan}
onBlur={this.onContainerBlur}
onFocus={this.onContainerFocus}
role="gridcell"
role={this.interactionMode === "interactive" ? "gridcell" : "cell"}
rowSpan={this.rowSpan}
tabIndex={staticCell ? -1 : 0}
// eslint-disable-next-line react/jsx-sort-props -- ref should be last so node attrs/props are in sync (see https://github.com/Esri/calcite-design-system/pull/6530)
ref={(el) => (this.containerEl = el)}
>
{(this.selectionCell || this.readCellContentsToAT) && this.focused && (
<span aria-hidden={true} aria-live="polite" class={CSS.assistiveText}>
{this.selectionCell && this.selectionText}
{this.readCellContentsToAT && !this.selectionCell && this.contentsText}
</span>
)}
<span
aria-hidden={true}
aria-live={this.focused ? "polite" : "off"}
class={CSS.assistiveText}
>
{(this.selectionCell || this.readCellContentsToAT) && (
<Fragment>
{this.selectionCell && this.selectionText}
{this.readCellContentsToAT && !this.selectionCell && this.contentsText}
</Fragment>
)}
</span>
<slot onSlotchange={this.updateScreenReaderContentsText} />
</td>
</InteractiveContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
/** @internal */
@Prop() parentRowIsSelected: boolean;

/** @internal */
@Prop() parentRowPosition: number;

/** @internal */
@Prop() parentRowType: RowType;

Expand Down Expand Up @@ -146,6 +143,8 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo

@State() defaultMessages: TableHeaderMessages;

@State() focused = false;

@State() screenReaderText = "";

@State() effectiveLocale = "";
Expand Down Expand Up @@ -191,6 +190,14 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
this.screenReaderText = text;
}

private onContainerBlur = (): void => {
this.focused = false;
};

private onContainerFocus = (): void => {
this.focused = true;
};

//--------------------------------------------------------------------------
//
// Render Methods
Expand All @@ -212,7 +219,7 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
return (
<Host>
<th
aria-colindex={this.parentRowType !== "body" ? this.positionInRow : ""}
aria-colindex={this.parentRowType === "head" ? this.positionInRow : undefined}
class={{
[CSS.bodyRow]: this.parentRowType === "body",
[CSS.footerRow]: this.parentRowType === "foot",
Expand All @@ -224,7 +231,9 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
[CSS.lastCell]: this.lastCell,
}}
colSpan={this.colSpan}
role="columnheader"
onBlur={this.onContainerBlur}
onFocus={this.onContainerFocus}
role={this.parentRowType === "head" ? "columnheader" : "rowheader"}
rowSpan={this.rowSpan}
scope={scope}
tabIndex={this.selectionCell ? 0 : staticCell ? -1 : 0}
Expand All @@ -240,11 +249,13 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
scale={getIconScale(this.scale)}
/>
)}
{(this.selectionCell || this.numberCell) && (
<span aria-hidden={true} aria-live="polite" class={CSS.assistiveText}>
{this.screenReaderText}
</span>
)}
<span
aria-hidden={true}
aria-live={this.focused ? "polite" : "off"}
class={CSS.assistiveText}
>
{(this.selectionCell || this.numberCell) && this.screenReaderText}
</span>
</th>
</Host>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/calcite-components/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,10 +528,9 @@ export class Table implements LocalizedComponent, LoadableComponent, T9nComponen
<table
aria-colcount={this.colCount}
aria-multiselectable={this.selectionMode === "multiple"}
aria-readonly={true}
aria-rowcount={this.allRows?.length}
class={{ [CSS.tableFixed]: this.layout === "fixed" }}
role="grid"
role={this.interactionMode === "interactive" ? "grid" : "table"}
>
<caption class={CSS.assistiveText}>{this.caption}</caption>
{this.renderTHead()}
Expand Down
Loading