Skip to content

Commit

Permalink
Merge pull request #172 from springload/chore/rename-hidebodyclassnam…
Browse files Browse the repository at this point in the history
…e-prop

Chore/rename hidebodyclassname prop
  • Loading branch information
catepalmer committed Jan 27, 2019
2 parents cb2e723 + 2a8a282 commit de12074
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 89 deletions.
52 changes: 27 additions & 25 deletions README.md
Expand Up @@ -86,10 +86,18 @@ We recommend that you copy them into your own app and modify them to suit your n
</thead>
<tbody>
<tr>
<td>accordion</td>
<td>allowMultipleExpanded</td>
<td>Boolean</td>
<td>false</td>
<td>Don't close all the others when expanding an
AccordionItem</td>
</tr>
<tr>
<td>allowZeroExpanded</td>
<td>Boolean</td>
<td>true</td>
<td>Open only one item at a time or not</td>
<td>false</td>
<td>Close an AccordionItem when it's the only
one expanded</td>
</tr>
<tr>
<td>onChange</td>
Expand Down Expand Up @@ -133,10 +141,10 @@ We recommend that you copy them into your own app and modify them to suit your n
<td>CSS class(es) applied to the component</td>
</tr>
<tr>
<td>hideBodyClassName</td>
<td>expandedClassName</td>
<td>String</td>
<td>null</td>
<td>Class name for hidden body state</td>
<td>Class name for expanded panel state</td>
</tr>
<tr>
<td>uuid</td>
Expand Down Expand Up @@ -168,10 +176,10 @@ We recommend that you copy them into your own app and modify them to suit your n
<td>CSS class(es) applied to the component</td>
</tr>
<tr>
<td>hideBodyClassName</td>
<td>expandedClassName</td>
<td>String</td>
<td>null</td>
<td>Class name for hidden body state</td>
<td>Class name for expanded panel state</td>
</tr>
</tbody>
</table>
Expand All @@ -197,10 +205,10 @@ We recommend that you copy them into your own app and modify them to suit your n
<td>CSS class(es) applied to the component</td>
</tr>
<tr>
<td>hideBodyClassName</td>
<td>expandedClassName</td>
<td>String</td>
<td>accordion__panel--hidden</td>
<td>Class name for hidden body state</td>
<td>accordion__panel--expanded</td>
<td>Class name for expanded panel state</td>
</tr>
</tbody>
</table>
Expand All @@ -222,29 +230,23 @@ We recommend that you copy them into your own app and modify them to suit your n

### What this project is doing accessibility-wise?

This project manages two types of Accordions, with single or multiple items open.
This project manages Accordions with several options available for allowing/not allowing multiple items to be open at once, and allowing/not allowing all items to be closed.

#### Single item
#### Single item open

> Use this with with props `accordion` set to `true` on `Accordion`.
> Use this with with props `allowMultipleExpanded` set to `false` on `Accordion`.
For this type of Accordion, you will get the following `role` set up on your elements:
#### Multiple items open

- Accordion: `tablist`
- AccordionItem: no specific role
- AccordionItemHeading: `tab`
- AccordionItemPanel: `tabpanel`
> Use this with with props `allowMultipleExpanded` set to `true` on `Accordion`.
#### Multiple items
#### One item must remain open

For this type of Accordion, you will get the following `role` set up on your elements:
> Use this with with props `allowZeroExpanded` set to `false` on `Accordion`.
> Use this with with props `accordion` set to `false` on `Accordion`.
#### All items can be closed

- Accordion: no specific role
- AccordionItem: no specific role
- AccordionItemHeading: `button`
- AccordionItemPanel: no specific role
> Use this with with props `allowZeroExpanded` set to `true` on `Accordion`.
# Browser support

Expand Down
17 changes: 9 additions & 8 deletions demo/src/index.tsx
Expand Up @@ -212,10 +212,10 @@ const Example = (): JSX.Element => (
<td>CSS class(es) applied to the component</td>
</tr>
<tr>
<td>hideBody ClassName</td>
<td>expandedClassName</td>
<td>String</td>
<td>accordion__panel--hidden</td>
<td>Class name for hidden body state</td>
<td>accordion__panel--expanded</td>
<td>Class name for expanded panel state</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -261,8 +261,8 @@ const Example = (): JSX.Element => (
<td>Boolean</td>
<td>false</td>
<td>
Open only one item at a time or
not
Don't close all the others when
expanding an AccordionItem
</td>
</tr>
<tr>
Expand Down Expand Up @@ -395,11 +395,12 @@ const Example = (): JSX.Element => (
</td>
</tr>
<tr>
<td>hideBody ClassName</td>
<td>expandedClassName</td>
<td>String</td>
<td>accordion__panel--hidden</td>
<td>accordion__panel--expanded</td>
<td>
Class name for hidden body state
Class name for expanded panel
state
</td>
</tr>
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -49,6 +49,10 @@
},
{
"name": "Thibaud Colas"
},
{
"name": "Cate Palmer",
"url": "https://github.com/catepalmer"
}
],
"license": "MIT",
Expand Down
8 changes: 4 additions & 4 deletions src/Accordion/Accordion.spec.tsx
Expand Up @@ -80,18 +80,18 @@ describe('Accordion', () => {
});

it('works with multiple pre expanded accordion. Extra expands are just ignored.', () => {
const hideBodyClassName = 'HIDE';
const expandedClassName = 'EXPANDED';
const wrapper = mount(
<Accordion allowMultipleExpanded={false}>
<AccordionItem
expanded={true}
hideBodyClassName={hideBodyClassName}
expandedClassName={expandedClassName}
>
Fake Child
</AccordionItem>
<AccordionItem
expanded={true}
hideBodyClassName={hideBodyClassName}
expandedClassName={expandedClassName}
>
Fake Child
</AccordionItem>
Expand All @@ -106,7 +106,7 @@ describe('Accordion', () => {
).toEqual(1);
expect(
wrapper.findWhere((item: ReactWrapper) =>
item.hasClass(hideBodyClassName),
item.hasClass(expandedClassName),
).length,
).toEqual(1);
});
Expand Down
8 changes: 4 additions & 4 deletions src/AccordionItem/AccordionItem.spec.tsx
Expand Up @@ -140,19 +140,19 @@ describe('AccordionItem', () => {
expect(wrapper.find('div').prop('className')).toBe('testCSSClass');
});

it('renders with different hideBodyClassName', () => {
it('renders with different expandedClassName', () => {
const wrapper = mount(
<AccordionProvider>
<AccordionItem
expanded={false}
expanded={true}
className="AccordionItem"
hideBodyClassName="AccordionItem--hidden"
expandedClassName="AccordionItem--expanded"
/>
</AccordionProvider>,
);

expect(wrapper.find('div').prop('className')).toEqual(
'AccordionItem AccordionItem--hidden',
'AccordionItem AccordionItem--expanded',
);
});

Expand Down
8 changes: 4 additions & 4 deletions src/AccordionItem/AccordionItem.tsx
Expand Up @@ -8,7 +8,7 @@ import { UUID } from '../ItemContainer/ItemContainer';

type AccordionItemProps = React.HTMLAttributes<HTMLDivElement> & {
uuid: UUID;
hideBodyClassName?: string;
expandedClassName?: string;
expanded?: boolean;
accordionStore: AccordionContainer;
};
Expand Down Expand Up @@ -39,7 +39,7 @@ class AccordionItem extends React.Component<AccordionItemProps> {
const {
uuid,
className,
hideBodyClassName,
expandedClassName,
accordionStore,
expanded,
...rest
Expand All @@ -57,8 +57,8 @@ class AccordionItem extends React.Component<AccordionItemProps> {
return (
<div
className={classnames(className, {
[String(hideBodyClassName)]:
!currentItem.expanded && hideBodyClassName,
[String(expandedClassName)]:
currentItem.expanded && expandedClassName,
})}
{...rest}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/AccordionItem/AccordionItem.wrapper.tsx
Expand Up @@ -10,7 +10,7 @@ import { Provider as ItemProvider } from '../ItemContainer/ItemContainer';
import AccordionItem from './AccordionItem';

type AccordionItemWrapperProps = React.HTMLAttributes<HTMLDivElement> & {
hideBodyClassName?: string;
expandedClassName?: string;
expanded?: boolean;
uuid?: string;
};
Expand All @@ -32,7 +32,7 @@ export default class AccordionItemWrapper extends React.Component<

static defaultProps: AccordionItemWrapperProps = {
className: 'accordion__item',
hideBodyClassName: '',
expandedClassName: '',
expanded: false,
uuid: undefined,
};
Expand Down
12 changes: 6 additions & 6 deletions src/AccordionItem/__snapshots__/AccordionItem.spec.tsx.snap
Expand Up @@ -22,7 +22,7 @@ exports[`AccordionItem renders correctly with allowMultipleExpanded false 1`] =
<div
aria-hidden={null}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role="region"
>
Expand Down Expand Up @@ -55,7 +55,7 @@ exports[`AccordionItem renders correctly with allowMultipleExpanded true 1`] = `
<div
aria-hidden={true}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role={null}
>
Expand Down Expand Up @@ -88,7 +88,7 @@ exports[`AccordionItem renders correctly with allowZeroExpanded false 1`] = `
<div
aria-hidden={null}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role="region"
>
Expand Down Expand Up @@ -121,7 +121,7 @@ exports[`AccordionItem renders correctly with allowZeroExpanded true 1`] = `
<div
aria-hidden={null}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role="region"
>
Expand Down Expand Up @@ -157,7 +157,7 @@ exports[`AccordionItem renders correctly with other blocks inside 1`] = `
<div
aria-hidden={null}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role="region"
>
Expand Down Expand Up @@ -190,7 +190,7 @@ exports[`AccordionItem renders correctly with other blocks inside 2 1`] = `
<div
aria-hidden={null}
aria-labelledby="accordion__heading-0"
className="accordion__panel accordion__panel--hidden"
className="accordion__panel"
id="accordion__panel-0"
role="region"
>
Expand Down
23 changes: 11 additions & 12 deletions src/AccordionItemHeading/AccordionItemHeading.spec.tsx
Expand Up @@ -70,20 +70,19 @@ describe('AccordionItemHeading', () => {
expect(wrapper.find('div').hasClass(className)).toEqual(true);
});

it('renders with different hideBodyClassName', () => {
const hideBodyClassName = 'hideBodyClassName';
const wrapper = mountItem(
<AccordionItemHeading hideBodyClassName={hideBodyClassName} />,
);
expect(wrapper.find('div').hasClass(hideBodyClassName)).toEqual(true);
});
it('renders with different expandedClassName when item is expanded', () => {
const expandedClassName = 'expandedClassName';

it("doesn't present hideBodyClassName when collapsed", () => {
const hideBodyClassName = 'hideBodyClassName';
const wrapper = mountItem(
<AccordionItemHeading hideBodyClassName={hideBodyClassName} />,
const wrapper = mount(
<AccordionProvider items={[{ uuid: 0, expanded: true }]}>
<ItemProvider uuid={0}>
<AccordionItemHeading
expandedClassName={expandedClassName}
/>
</ItemProvider>
</AccordionProvider>,
);
expect(wrapper.find('div').hasClass(hideBodyClassName)).toEqual(true);
expect(wrapper.find('div').hasClass(expandedClassName)).toEqual(true);
});

it('toggles state when clicked', async () => {
Expand Down
7 changes: 4 additions & 3 deletions src/AccordionItemHeading/AccordionItemHeading.tsx
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { UUID } from '../ItemContainer/ItemContainer';

type AccordionItemHeadingProps = React.HTMLAttributes<HTMLDivElement> & {
hideBodyClassName: string;
expandedClassName: string;
expanded: boolean;
uuid: UUID;
disabled: boolean;
Expand Down Expand Up @@ -32,7 +32,7 @@ export default class AccordionItemHeading extends React.Component<
render(): JSX.Element {
const {
className,
hideBodyClassName,
expandedClassName,
setExpanded,
expanded,
uuid,
Expand All @@ -42,8 +42,9 @@ export default class AccordionItemHeading extends React.Component<

const id = `accordion__heading-${uuid}`;
const ariaControls = `accordion__panel-${uuid}`;

const headingClassName = classnames(className, {
[hideBodyClassName]: hideBodyClassName && !expanded,
[expandedClassName]: expandedClassName && expanded,
});

return (
Expand Down
4 changes: 2 additions & 2 deletions src/AccordionItemHeading/AccordionItemHeading.wrapper.tsx
Expand Up @@ -12,7 +12,7 @@ import {
import { default as AccordionItemHeading } from './AccordionItemHeading';

type AccordionItemHeadingWrapperProps = React.HTMLAttributes<HTMLDivElement> & {
hideBodyClassName: string;
expandedClassName: string;
};

type AccordionItemHeadingWrapperState = {};
Expand All @@ -32,7 +32,7 @@ export default class AccordionItemHeadingWrapper extends React.Component<

static defaultProps: AccordionItemHeadingWrapperProps = {
className: 'accordion__heading',
hideBodyClassName: '',
expandedClassName: '',
};

render(): JSX.Element {
Expand Down

0 comments on commit de12074

Please sign in to comment.