Skip to content

Commit

Permalink
fix(Accordion): fix aria-expanded value when using alwaysOpen (#6537
Browse files Browse the repository at this point in the history
)

* accordion accessibility fix #6536

* added a test for AccordionButton component #6536

Co-authored-by: mdreieva <maryna.dreieva@experian.com>
  • Loading branch information
marishkaSunrise and mdreieva committed Jan 20, 2023
1 parent 7c66098 commit 7f633bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/AccordionButton.tsx
Expand Up @@ -87,7 +87,11 @@ const AccordionButton: BsPrefixRefForwardingComponent<
ref={ref}
onClick={accordionOnClick}
{...props}
aria-expanded={eventKey === activeEventKey}
aria-expanded={
Array.isArray(activeEventKey)
? activeEventKey.includes(eventKey)
: eventKey === activeEventKey
}
className={classNames(
className,
bsPrefix,
Expand Down
12 changes: 12 additions & 0 deletions test/AccordionButtonSpec.tsx
@@ -1,6 +1,7 @@
import { fireEvent, render } from '@testing-library/react';
import sinon from 'sinon';
import AccordionButton from '../src/AccordionButton';
import Accordion from '../src/Accordion';

describe('<AccordionButton>', () => {
it('Should have button as default component', () => {
Expand Down Expand Up @@ -33,4 +34,15 @@ describe('<AccordionButton>', () => {

onClickSpy.should.be.calledOnce;
});

it('Should have toggled aria-expanded attribute in alwaysOpen accordion', () => {
const onClickSpy = sinon.spy();
const { getByTestId } = render(
<Accordion alwaysOpen>
<AccordionButton data-testid="btn" onClick={onClickSpy} />
</Accordion>,
);
fireEvent.click(getByTestId('btn'));
getByTestId('btn').getAttribute('aria-expanded').should.equal('true');
});
});

0 comments on commit 7f633bf

Please sign in to comment.