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

[core] fix: Set aria-hidden for purely decorative icons #5158

Merged
merged 1 commit into from
Mar 7, 2022
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
6 changes: 4 additions & 2 deletions packages/core/src/components/button/abstractButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ export abstract class AbstractButton<E extends HTMLButtonElement | HTMLAnchorEle

protected renderChildren(): React.ReactNode {
const { children, icon, loading, rightIcon, text } = this.props;
const maybeHasText = !Utils.isReactNodeEmpty(text) || !Utils.isReactNodeEmpty(children);
return [
loading && <Spinner key="loading" className={Classes.BUTTON_SPINNER} size={IconSize.LARGE} />,
<Icon key="leftIcon" icon={icon} />,
(!Utils.isReactNodeEmpty(text) || !Utils.isReactNodeEmpty(children)) && (
// The icon is purely decorative if text is provided
<Icon key="leftIcon" icon={icon} aria-hidden={maybeHasText} tabIndex={maybeHasText ? -1 : 0} />,
maybeHasText && (
<span key="text" className={Classes.BUTTON_TEXT}>
{text}
{children}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/callout/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Callout extends AbstractPureComponent2<CalloutProps> {

return (
<div className={classes} {...htmlProps}>
{iconName && <Icon icon={iconName} size={IconSize.LARGE} />}
{iconName && <Icon icon={iconName} size={IconSize.LARGE} aria-hidden={true} tabIndex={-1} />}
{title && <H4>{title}</H4>}
{children}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class Dialog extends AbstractPureComponent2<DialogProps> {
}
return (
<div className={Classes.DIALOG_HEADER}>
<Icon icon={icon} size={IconSize.LARGE} />
<Icon icon={icon} size={IconSize.LARGE} aria-hidden={true} tabIndex={-1} />
<H4 id={this.titleId}>{title}</H4>
{this.maybeRenderCloseButton()}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/forms/inputGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class InputGroup extends AbstractPureComponent2<InputGroupProps2, IInputG
</span>
);
} else if (leftIcon != null) {
return <Icon icon={leftIcon} />;
return <Icon icon={leftIcon} aria-hidden={true} tabIndex={-1} />;
}

return undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/menu/menuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class MenuItem extends AbstractPureComponent2<MenuItemProps & React.Ancho
...(disabled ? DISABLED_PROPS : {}),
className: anchorClasses,
},
<Icon icon={icon} />,
<Icon icon={icon} aria-hidden={true} tabIndex={-1} />,
<Text className={classNames(Classes.FILL, textClassName)} ellipsize={!multiline} title={htmlTitle}>
{text}
</Text>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class NonIdealState extends AbstractPureComponent2<NonIdealStateProps> {
} else {
return (
<div className={Classes.NON_IDEAL_STATE_VISUAL}>
<Icon icon={icon} size={IconSize.LARGE * 3} />
<Icon icon={icon} size={IconSize.LARGE * 3} aria-hidden={true} tabIndex={-1} />
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/tree/treeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class TreeNode<T = {}> extends React.Component<ITreeNodeProps<T>> {
<li className={classes}>
<div className={contentClasses} ref={this.handleContentRef} {...eventHandlers}>
{this.maybeRenderCaret()}
<Icon className={Classes.TREE_NODE_ICON} icon={icon} />
<Icon className={Classes.TREE_NODE_ICON} icon={icon} aria-hidden={true} tabIndex={-1} />
<span className={Classes.TREE_NODE_LABEL}>{label}</span>
{this.maybeRenderSecondaryLabel()}
</div>
Expand Down