Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Accordion): ability to open multiple items #976

Closed
wants to merge 2 commits into from
Closed

feat(Accordion): ability to open multiple items #976

wants to merge 2 commits into from

Conversation

UnbrandedTech
Copy link
Contributor

@UnbrandedTech UnbrandedTech commented Dec 2, 2016

Add ability for activeIndex in Accordions to be an array.

Allowing multiple open panels at once, need help with transforming
activeIndex prop to an array.

Allowing multiple open panels at once, need help with transforming
activeIndex prop to an array.
activeIndex: PropTypes.number,
activeIndex: PropTypes.oneOfType([
PropTypes.number,
PropTypes.array,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's beef this up a bit, PropTypes.arrayOf(PropTypes.number).

@@ -38,6 +45,9 @@ export default class Accordion extends Component {
/** Initial activeIndex value. */
defaultActiveIndex: PropTypes.number,

/** Allow only one index */
exclusive: PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to stick very close to SUI core descriptions. Here's the description from the Accordion settings page:

/** Only allow one section open at a time */

Since we currently have a deviation in terms, panels vs sections, let's keep consistent with panels. Suggest we go with:

/** Only allow one panel open at a time */

@levithomason
Copy link
Member

I have left a couple minor comments for now. If you can describe the issue you are having in full detail, I can take a look and offer some help. Thanks for the PR!

//TODO: Can not accept an activeIndex and be inclusive at the same time
// if(this.props.exclusive == false && _.isNumber(this.props.activeIndex)){
// this.trySetState({ activeIndex: [ this.props.activeIndex ] })
// }
Copy link
Contributor Author

@UnbrandedTech UnbrandedTech Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levithomason My Issue is when exclusive={false} and activeIndex={1}, I can't transform the activeIndex to an array.
I tried this but to no avail. i'm not sure how the internals are working, but i think the props is overwriting my state change.

Copy link
Member

@levithomason levithomason Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, this is an AutoControlledComponent which means, if the user passes a prop then they are in control of the state but when there is no prop the Component is in control of the state.

this.trySetState will only set state if there is no prop defined. In this regard, the component "auto controls" state for the user but also backs off if the user controls it with props.

It is up to the user to pass the correct combination of activeIndex and exclusive. The alternative is to pass defaultActiveIndex which is only applied on the first render, then the component can update theactiveIndex on subsequent renders.

Copy link
Contributor Author

@UnbrandedTech UnbrandedTech Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you I understand correctly defaultActiveIndex should be allowed to a number or array from props? And if defaultActiveIndex={0} and exclusive={false} are set add it to the activeIndex array, i.e. activeIndex=[0].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, except, most of that happens automatically. The ACC (AutoControlledComponent) handles copying props and default props to their regular prop name on state.

@codecov-io
Copy link

codecov-io commented Dec 3, 2016

Current coverage is 99.78% (diff: 80.00%)

Merging #976 into master will decrease coverage by 0.21%

@@           master       #976   diff @@
========================================
  Files         137        137          
  Lines        2284       2303    +19   
  Methods         0          0          
  Messages        0          0          
  Branches        0          0          
========================================
+ Hits         2284       2298    +14   
- Misses          0          5     +5   
  Partials        0          0          

Powered by Codecov. Last update c113cf5...b98d46f

@UnbrandedTech
Copy link
Contributor Author

@levithomason let me know if i got anything wrong

@levithomason
Copy link
Member

Sounds good, I've marked this for review and will get to it soon as I am able. Thanks!

@levithomason
Copy link
Member

levithomason commented Dec 5, 2016

I made some cleanup and minor fixes to this PR, however, I cannot push them since it is pointing to your master branch. I've opened #988 branching off of your fork and including my updates. I'll close this PR and merge the other. Let's move all future convo over there 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants