Skip to content

Commit

Permalink
[terra-button] Fix Aria label bug (cerner#3726)
Browse files Browse the repository at this point in the history
* [terra-button] Fix Aria label bug

* Changes

* Changelog
  • Loading branch information
saket2403 authored Feb 16, 2023
1 parent 632d9ce commit 404c3be
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
3 changes: 3 additions & 0 deletions packages/terra-button/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Fixed aria-label bug.

## 3.63.0 - (February 15, 2023)

* Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/terra-button/src/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ class Button extends React.Component {
);

// ignore aria-label for button with decorative icons.
let ariaLabel = (iconType !== IconTypes.DECORATIVE) ? customProps['aria-label'] : undefined;
if ((isIconOnly || variant === 'utility') && iconType === IconTypes.INFORMATIVE) {
ariaLabel = ariaLabel || text;
let ariaLabel = customProps['aria-label'];
if (isIconOnly || variant === 'utility') {
ariaLabel = (iconType === IconTypes.INFORMATIVE) ? ariaLabel || text : undefined;
}

let ComponentType = 'button';
Expand Down
6 changes: 3 additions & 3 deletions packages/terra-button/tests/jest/Button.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ThemeContextProvider from 'terra-theme-context/lib/ThemeContextProvider';

import Button from '../../src/Button';
import Button, { IconTypes } from '../../src/Button';

// Snapshot Tests
it('should render a neutral button', () => {
Expand Down Expand Up @@ -49,9 +49,9 @@ it('should render a button with type equal to submit', () => {
expect(button).toMatchSnapshot();
});

it('should render an icon', () => {
it('should render an informative icon button', () => {
const testElement = <img alt="icon" />;
const button = shallow(<Button icon={testElement} isIconOnly text="isIconOnly" />);
const button = shallow(<Button iconType={IconTypes.INFORMATIVE} icon={testElement} isIconOnly text="isIconOnly" />);
expect(button).toMatchSnapshot();
});

Expand Down
60 changes: 31 additions & 29 deletions packages/terra-button/tests/jest/__snapshots__/Button.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ exports[`should render a button with a title 1`] = `
exports[`should render a button with accessible label 1`] = `
<button
aria-disabled={false}
aria-label="Custom Accessible Label"
className="button neutral"
disabled={false}
onBlur={[Function]}
Expand Down Expand Up @@ -493,35 +494,6 @@ exports[`should render an action button 1`] = `
</button>
`;

exports[`should render an icon 1`] = `
<button
aria-disabled={false}
className="button neutral"
disabled={false}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
title="isIconOnly"
type="button"
>
<span
className="button-label icon-only"
>
<span
className="icon"
>
<img
alt="icon"
className="icon-svg"
/>
</span>
</span>
</button>
`;

exports[`should render an icon and a text 1`] = `
<button
aria-disabled={false}
Expand Down Expand Up @@ -635,6 +607,36 @@ exports[`should render an icon only button with text as a fallback title 1`] = `
</button>
`;

exports[`should render an informative icon button 1`] = `
<button
aria-disabled={false}
aria-label="isIconOnly"
className="button neutral"
disabled={false}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
title="isIconOnly"
type="button"
>
<span
className="button-label icon-only"
>
<span
className="icon"
>
<img
alt="icon"
className="icon-svg"
/>
</span>
</span>
</button>
`;

exports[`should render as an anchor when provided an href 1`] = `
<a
aria-disabled={false}
Expand Down

0 comments on commit 404c3be

Please sign in to comment.