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: properly set aria attributes on components #10404

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion packages/calcite-components/src/components/block/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export class Block
<Host>
<InteractiveContainer disabled={this.disabled}>
<article
aria-busy={toAriaBoolean(loading)}
aria-busy={loading ? toAriaBoolean(loading) : null}
class={{
[CSS.container]: true,
}}
Expand Down
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export class Button
return (
<InteractiveContainer disabled={this.disabled}>
<Tag
aria-busy={toAriaBoolean(this.loading)}
aria-expanded={this.el.ariaExpanded}
aria-busy={this.loading ? toAriaBoolean(this.loading) : null}
aria-expanded={this.el.ariaExpanded ? this.el.ariaExpanded : null}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only set aria-expanded when set on host

aria-label={!this.loading ? getLabelText(this) : this.messages.loading}
aria-live="polite"
class={{
Expand Down
5 changes: 4 additions & 1 deletion packages/calcite-components/src/components/card/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ export class Card
</div>
) : null}
{thumbnailStart && this.renderThumbnail()}
<section aria-busy={toAriaBoolean(this.loading)} class={{ [CSS.container]: true }}>
<section
aria-busy={this.loading ? toAriaBoolean(this.loading) : null}
class={{ [CSS.container]: true }}
>
{this.renderHeader()}
<div
class={{
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export class List
{this.renderItemAriaLive()}
{loading ? <calcite-scrim class={CSS.scrim} loading={loading} /> : null}
<table
aria-busy={toAriaBoolean(loading)}
aria-busy={loading ? toAriaBoolean(loading) : null}
aria-label={label || ""}
class={CSS.table}
onKeyDown={this.handleListKeydown}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {
Watch,
} from "@stencil/core";
import { FlipContext } from "../interfaces";
import { Direction, getElementDir, slotChangeGetAssignedElements } from "../../utils/dom";
import {
Direction,
getElementDir,
slotChangeGetAssignedElements,
toAriaBoolean,
} from "../../utils/dom";
import {
componentFocusable,
LoadableComponent,
Expand Down Expand Up @@ -470,8 +475,8 @@ export class CalciteMenuItem implements LoadableComponent, T9nComponent, Localiz
<div class={CSS.itemContent}>
<a
aria-current={this.isFocused ? "page" : false}
aria-expanded={this.open}
aria-haspopup={this.hasSubmenu}
aria-expanded={toAriaBoolean(this.open)}
aria-haspopup={toAriaBoolean(this.hasSubmenu)}
aria-label={this.label}
class={{ [CSS.layoutVertical]: this.layout === "vertical", [CSS.content]: true }}
href={this.href}
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/panel/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ export class Panel

const panelNode = (
<article
aria-busy={toAriaBoolean(loading)}
aria-busy={loading ? toAriaBoolean(loading) : null}
class={CSS.container}
hidden={isClosed}
ref={this.setContainerRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ export class PickList<

render(): VNode {
return (
<Host aria-busy={toAriaBoolean(this.loading)} onKeyDown={this.keyDownHandler} role="menu">
<Host
aria-busy={this.loading ? toAriaBoolean(this.loading) : null}
onKeyDown={this.keyDownHandler}
role="menu"
>
<List props={this} />
</Host>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ export class TableCell
tabIndex={staticCell ? -1 : 0}
>
{(this.selectionCell || this.readCellContentsToAT) && (
<span
aria-hidden={true}
aria-live={this.focused ? "polite" : "off"}
class={CSS.assistiveText}
>
<span aria-live={this.focused ? "polite" : "off"} class={CSS.assistiveText}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen reader text shouldn't have aria-hidden.

{this.selectionCell && this.selectionText}
{this.readCellContentsToAT && !this.selectionCell && this.contentsText}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,7 @@ export class TableHeader implements LocalizedComponent, LoadableComponent, T9nCo
/>
)}
{(this.selectionCell || this.numberCell) && (
<span
aria-hidden={true}
aria-live={this.focused ? "polite" : "off"}
class={CSS.assistiveText}
>
<span aria-live={this.focused ? "polite" : "off"} class={CSS.assistiveText}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen reader text shouldn't have aria-hidden.

{this.screenReaderText}
</span>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
} from "@stencil/core";
import { LocalizedComponent } from "../../utils/locale";
import { Alignment, Scale, SelectionMode } from "../interfaces";
import { focusElementInGroup, FocusElementInGroupDestination } from "../../utils/dom";
import {
focusElementInGroup,
FocusElementInGroupDestination,
toAriaBoolean,
} from "../../utils/dom";
import { RowType, TableInteractionMode, TableRowFocusEvent } from "../table/interfaces";
import { isActivationKey } from "../../utils/key";
import {
Expand Down Expand Up @@ -410,7 +414,7 @@ export class TableRow implements InteractiveComponent, LocalizedComponent {
<InteractiveContainer disabled={this.disabled}>
<tr
aria-rowindex={this.positionAll + 1}
aria-selected={this.selected}
aria-selected={toAriaBoolean(this.selected)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't doing anything. This fixes it.

class={{ [CSS.lastVisibleRow]: this.lastVisibleRow }}
onKeyDown={this.keyDownHandler}
ref={(el) => (this.tableRowEl = el)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ export class TextArea
</footer>
<HiddenFormInputSlot component={this} />
{this.isCharacterLimitExceeded() && (
<span aria-hidden={true} aria-live="polite" class={CSS.assistiveText} id={this.guid}>
<span
aria-hidden={toAriaBoolean(true)}
aria-live="polite"
class={CSS.assistiveText}
id={this.guid}
>
{this.replacePlaceHoldersInMessages()}
</span>
)}
Expand Down
8 changes: 4 additions & 4 deletions packages/calcite-components/src/components/tree/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Prop,
VNode,
} from "@stencil/core";
import { focusElement, nodeListToArray } from "../../utils/dom";
import { focusElement, nodeListToArray, toAriaBoolean } from "../../utils/dom";
import { Scale, SelectionMode } from "../interfaces";
import { TreeItemSelectDetail } from "../tree-item/interfaces";
import { getTraversableItems, isTreeItem } from "./utils";
Expand Down Expand Up @@ -88,9 +88,9 @@ export class Tree {
aria-multiselectable={
this.child
? undefined
: (
this.selectionMode === "multiple" || this.selectionMode === "multichildren"
).toString()
: toAriaBoolean(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹

this.selectionMode === "multiple" || this.selectionMode === "multichildren",
)
}
onKeyDown={this.keyDownHandler}
role={!this.child ? "tree" : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class ValueList<
render(): VNode {
return (
<Host
aria-busy={toAriaBoolean(this.loading)}
aria-busy={this.loading ? toAriaBoolean(this.loading) : null}
onBlur={this.handleBlur}
onFocusin={this.handleFocusIn}
onKeyDown={this.keyDownHandler}
Expand Down
Loading