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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class Button
<InteractiveContainer disabled={this.disabled}>
<Tag
aria-busy={toAriaBoolean(this.loading)}
aria-expanded={this.el.ariaExpanded}
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
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
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,7 @@ export class TextArea
</footer>
<HiddenFormInputSlot component={this} />
{this.isCharacterLimitExceeded() && (
<span aria-hidden={true} aria-live="polite" class={CSS.assistiveText} id={this.guid}>
<span aria-live="polite" class={CSS.assistiveText} id={this.guid}>
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.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
Loading