Skip to content

Commit 1a2e12c

Browse files
Merge pull request #46 from springload/chore/item-registration
Refactor - Version 2.0
2 parents 07bb1cc + a88c20a commit 1a2e12c

29 files changed

+1910
-8047
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
core/static
99
core/svg.html
1010
static
11+
yarn.lock
1112

1213
# -------------------------------------------------
1314
# OS generated files
@@ -82,4 +83,4 @@ pages
8283
# -------------------------------------------------
8384
# Visual Studio Code
8485
# -------------------------------------------------
85-
.vscode/
86+
.vscode/

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8
1+
8.9

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ language: node_js
22
cache:
33
directories:
44
- node_modules
5-
node_js:
6-
- 6
75
script:
86
- npm run test:coverage
97
after_success:

CHANGELOG.md

+44
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,50 @@ Changelog
44
> All notable changes to this project are documented in this file.
55
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [[v2.0.0]](https://github.com/springload/react-accessible-accordion/releases/tag/v2.0.0)
8+
9+
Version 2.0 represents a total refactor, with a new context-based approach which should make this library more flexible, more maintainable and more comprehensively testable.
10+
11+
As this is a major release, users should expect some breaking changes - though they should be limited to the removal of the `activeItems` prop (read more below).
12+
13+
### Added
14+
15+
- Exports `resetNextId` (https://github.com/springload/react-accessible-accordion/issues/41).
16+
17+
### Fixed
18+
19+
- Defect where controlled components' props were overridden by React.Children.map (https://github.com/springload/react-accessible-accordion/issues/33).
20+
- Defect where accordion crashed with unexpected `children` types (https://github.com/springload/react-accessible-accordion/issues/45).
21+
- Defect where React Accessible Accordion's components could not be extended.
22+
- Defect where the `children` of `Accordion` or `AccordionItem` could not be arbitrary.
23+
- Defect where `AccordionItem` had to be a child of `Accordion` (as opposed to to an arbitrary-level descendant).
24+
- Defect where `AccordionItemBody` and `AccordionItemTitle` had to be children of `AccordionItem` (as opposed to arbitrary-level descendants).
25+
26+
### Removed:
27+
28+
- 🚨 Breaking change 🚨 `activeItems` property is no longer supported.
29+
30+
Control at the `Accordion` level (via the `activeItems` prop) and `AccordionItem` level (via the `expanded` prop) fought against one another, and choosing which control mechanism to give preference to would have been an arbitrary decision - and whichever way we went, we would have had test cases which demonstrated unusual/unpredictable behaviour. The `activeItems` mechanism was the obvious one to remove - it was arguably the "less React-y way", and we considered it more of a convenience than a feature. Crucially though, it fought too hard against the new architecture of the library, and keeping it would have prevented us enabling lots of other new features or resolving some of the issues that our users had raised.
31+
32+
If you're currently using activeItems, you're upgrade path might look like this:
33+
34+
```diff
35+
const items = ['Foo', 'Bar'];
36+
const activeItems = [0];
37+
38+
return (
39+
- <Accordion activeItems={activeItems} />
40+
+ <Accordion />
41+
{activeItems.forEach((item, i) => (
42+
- <AccordionItem key={item}>{item}</AccordionItem>
43+
+ <AccordionItem key={item} expanded={activeItems.includes(i)}>{item}</AccordionItem>
44+
)}
45+
</Accordion>
46+
);
47+
```
48+
49+
Please don't hesitate to reach out to one of the maintainers (or raise an issue) if you're having trouble upgrading - we're happy to help!
50+
751
## [[v1.0.1]](https://github.com/springload/react-accessible-accordion/releases/tag/v1.0.1)
852

953
- Renders predictable `id` attributes.(https://github.com/springload/react-accessible-accordion/pull/29)

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22

3-
Copyright (c) 2017 Springload
3+
Copyright (c) 2018 Springload
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

README.md

+35-41
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> Accessible Accordion component for React. Inspired by [rc-collapse](https://github.com/react-component/collapse) and [react-sanfona](https://github.com/daviferreira/react-sanfona). :mag::ok_hand:
66
7-
This is a work in progress. Feel free to contribute. [Try a demo now](https://springload.github.io/react-accessible-accordion/).
7+
Try a demo now](https://springload.github.io/react-accessible-accordion/).
88

99
If you like accessible components, feel free to check this other repo [react-accessible-modal](https://github.com/springload/react-accessible-modal).
1010

@@ -13,14 +13,12 @@ If you like accessible components, feel free to check this other repo [react-acc
1313
First, grab the package from npm:
1414

1515
```sh
16-
npm install --save react-accessible-accordion
17-
# react-accessible-accordion's peerDependencies:
18-
npm install --save react@^15.0.0 react-dom@^15.0.0
16+
npm install --save react-accessible-accordion react react-dom
1917
```
2018

2119
Then, import the editor and use it in your code. Here is a [basic example](https://springload.github.io/react-accessible-accordion/):
2220

23-
```js
21+
```jsx
2422
import React from 'react';
2523
import ReactDOM from 'react-dom';
2624

@@ -40,9 +38,7 @@ const Example = () => (
4038
<h3>Simple title</h3>
4139
</AccordionItemTitle>
4240
<AccordionItemBody>
43-
<p>
44-
Body content
45-
</p>
41+
<p>Body content</p>
4642
</AccordionItemBody>
4743
</AccordionItem>
4844
<AccordionItem>
@@ -51,9 +47,7 @@ const Example = () => (
5147
<div>With a bit of description</div>
5248
</AccordionItemTitle>
5349
<AccordionItemBody>
54-
<p>
55-
Body content
56-
</p>
50+
<p>Body content</p>
5751
</AccordionItemBody>
5852
</AccordionItem>
5953
</Accordion>
@@ -96,12 +90,6 @@ ReactDOM.render(<Example />, document.querySelector('[data-mount]'));
9690
<td>accordion</td>
9791
<td>CSS class(es) applied to the component</td>
9892
</tr>
99-
<tr>
100-
<td>activeItems</td>
101-
<td>Array</td>
102-
<td>[]</td>
103-
<td>Indexes (or custom keys) to pre expand items. Can be changed dynamically. Doesn't have the priority against `AccordionItem - expanded` on first render.</td>
104-
</tr>
10593
</tbody>
10694
</table>
10795

@@ -137,12 +125,6 @@ ReactDOM.render(<Example />, document.querySelector('[data-mount]'));
137125
<td>null</td>
138126
<td>Class name for hidden body state</td>
139127
</tr>
140-
<tr>
141-
<td>customKey</td>
142-
<td>String</td>
143-
<td></td>
144-
<td>Custom key to be used as a reference in `Accordion - activeItems`</td>
145-
</tr>
146128
</tbody>
147129
</table>
148130

@@ -204,6 +186,19 @@ ReactDOM.render(<Example />, document.querySelector('[data-mount]'));
204186
</tbody>
205187
</table>
206188

189+
### resetNextUuid
190+
191+
<table class="table table-bordered table-striped">
192+
<tbody>
193+
<tr>
194+
<td>Function(void)</td>
195+
</tr>
196+
<tr>
197+
<td>Resets the internal counter for Accordion items' identifiers (including `id` attributes). For use in test suites and isomorphic frameworks.</td>
198+
</tr>
199+
</tbody>
200+
</table>
201+
207202
## Accessibility
208203

209204
### What this project is doing accessibility-wise?
@@ -216,21 +211,21 @@ This project manages two types of Accordions, with single or multiple items open
216211
217212
For this type of Accordion, you will get the following `role` set up on your elements:
218213

219-
- Accordion: `tablist`
220-
- AccordionItem: no specific role
221-
- AccordionItemTitle: `tab`
222-
- AccordionItemBody: `tabpanel`
214+
* Accordion: `tablist`
215+
* AccordionItem: no specific role
216+
* AccordionItemTitle: `tab`
217+
* AccordionItemBody: `tabpanel`
223218

224219
#### Multiple items
225220

226221
For this type of Accordion, you will get the following `role` set up on your elements:
227222

228223
> Use this with with props `accordion` set to `false` on `Accordion`.
229224
230-
- Accordion: no specific role
231-
- AccordionItem: no specific role
232-
- AccordionItemTitle: `button`
233-
- AccordionItemBody: no specific role
225+
* Accordion: no specific role
226+
* AccordionItem: no specific role
227+
* AccordionItemTitle: `button`
228+
* AccordionItemBody: no specific role
234229

235230
## Development
236231

@@ -284,17 +279,16 @@ git push origin master --tags
284279
npm publish
285280
```
286281

287-
288282
# Browser support
289283

290284
**Supported browser / device versions:**
291285

292-
| Browser | Device/OS | Version | Notes |
293-
|---------|-----------|---------|-------|
294-
| Mobile Safari | iOS | latest ||
295-
| Chrome | Android | latest ||
296-
| IE | Windows | 11 ||
297-
| MS Edge | Windows | latest ||
298-
| Chrome | Desktop | latest ||
299-
| Firefox | Desktop | latest ||
300-
| Safari | OSX | latest ||
286+
| Browser | Device/OS | Version | Notes |
287+
| ------------- | --------- | ------- | ----- |
288+
| Mobile Safari | iOS | latest | |
289+
| Chrome | Android | latest | |
290+
| IE | Windows | 11 | |
291+
| MS Edge | Windows | latest | |
292+
| Chrome | Desktop | latest | |
293+
| Firefox | Desktop | latest | |
294+
| Safari | OSX | latest | |

0 commit comments

Comments
 (0)