Skip to content

Commit

Permalink
[EuiAccordion] Fixed a bug in aria-expanded for axe-core. (#6694)
Browse files Browse the repository at this point in the history
* Fixed a bug in `EuiAccordion` aria-expanded for axe.

* Added logic check for EuiAccordion aria-expanded attr.
* Adding comment for new logic reasoning.

* Revising logic to only omit aria-expanded if second element is not a button.

* Adding a changelog entry.

* Update upcoming_changelogs/6694.md

Co-authored-by: Cee Chen <549407+cee-chen@users.noreply.github.com>

* Update upcoming_changelogs/6694.md

Co-authored-by: Cee Chen <549407+cee-chen@users.noreply.github.com>

* Update src/components/accordion/accordion.tsx

Co-authored-by: Cee Chen <549407+cee-chen@users.noreply.github.com>

* Refactoring logic inline for better readability.

---------

Co-authored-by: Cee Chen <549407+cee-chen@users.noreply.github.com>
  • Loading branch information
1Copenut and cee-chen committed Apr 6, 2023
1 parent d6c8e10 commit 35b6a27
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ exports[`EuiAccordion props buttonElement is rendered 1`] = `
</button>
<div
aria-controls="5"
aria-expanded="false"
class="euiAccordion__button emotion-euiAccordion__button"
id="generated-id"
>
Expand Down Expand Up @@ -688,7 +687,6 @@ exports[`EuiAccordion props element is rendered 1`] = `
</button>
<legend
aria-controls="1"
aria-expanded="false"
class="euiAccordion__button emotion-euiAccordion__button"
id="generated-id"
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/accordion/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ export class EuiAccordionClass extends Component<
id={buttonId}
className={buttonClasses}
aria-controls={id}
aria-expanded={isOpen}
// `aria-expanded` is only a valid attribute on interactive controls - axe-core throws a violation otherwise
aria-expanded={ButtonElement === 'button' ? isOpen : undefined}
onClick={isDisabled ? undefined : this.onToggle}
type={ButtonElement === 'button' ? 'button' : undefined}
disabled={ButtonElement === 'button' ? isDisabled : undefined}
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6694.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed `EuiAccordion` to not set an `aria-expanded` attribute on non-interactive `buttonElement`s

0 comments on commit 35b6a27

Please sign in to comment.