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): add methods to expand/collapse/collapseAll panels #1978

Closed
wants to merge 2 commits into from

Conversation

Thorski
Copy link

@Thorski Thorski commented Nov 20, 2017

feat(accordion): add methods to expand/collapse/collapseAll panels

Added
expand, collapse, collapseAll, and isExpanded methods.

#1970

@pkozlowski-opensource pkozlowski-opensource added this to the 1.0.0-beta.7 milestone Nov 24, 2017
@pkozlowski-opensource pkozlowski-opensource removed this from the 1.0.0-beta.8 milestone Dec 22, 2017
@Thorski
Copy link
Author

Thorski commented Jan 15, 2018

What needs to be done to get this into a build?

Thanks.

@christarczon
Copy link

Hopefully this is accepted. Can you add expandAll() as well?

@Thorski
Copy link
Author

Thorski commented Jan 22, 2018

@christarczon I don't know if I have missed a step or why this has not been accepted. I wish someone would please advise, I would like to use this from an official release. An expandAll could be added easily.

@pkozlowski-opensource pkozlowski-opensource added this to the 1.1.0 milestone Mar 9, 2018
const panel = this.panels.find(p => p.id === panelId);

if (panel && !panel.disabled && !panel.isOpen) {
this.toggle(panelId);

Choose a reason for hiding this comment

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

IMO we should it differently - the logic of expanding should be in this method and toggle should call it based on the state. In other words - the toggle method should make use of the new expand / collapse and not the other way around.

*/
isExpanded(panelId): boolean {
const panel = this.panels.find(p => p.id === panelId);
return panel.isOpen;

Choose a reason for hiding this comment

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

This will crash if there is no panel with a given panelId if I'm not mistaken? Could you please add a test for this case and fix the code if needed?

* Programmatically collapse all panels.
*/
collapseAll() {
this.panels.forEach(panel => { panel.isOpen = false; });

Choose a reason for hiding this comment

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

This should rather delegate to the collapse call - otherwise we are not taking the disabled flag into account. Please add a test for the case assuring that we are not collapsing an open, disabled panel.

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure if the disabled flag should take effect here or not, because the 'closeOtherPanels' option I believe takes effect even when a panel is disabled (see toggle and _closeOthers).

Copy link
Author

Choose a reason for hiding this comment

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

Also, I am not sure how to make a panel in the state of 'open and disabled'. Is it possible? If I set disabled on a panel, it closes. How do I do this?

/**
* Programmatically collapse all panels.
*/
collapseAll() {
Copy link
Member

Choose a reason for hiding this comment

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

We should also add expandAll (+ tests) for symmetry.

@pkozlowski-opensource
Copy link
Member

@Thorski sorry for the delay reviewing this PR - I've finally got to it and left few comments. Generally speaking:

  • the implementation is "light" on tests and might be missing some use-cases;
  • I would approach implementation differently to make it simpler and make sure that we are not missing corner cases.

Additionally I would like to propose that we do the following renaming:

  • expand => open
  • expandAll => openAll
  • collapse => close
  • collapseAll => closeAll
  • isExpanded => isOpen

This would align names with other directives in this library. WDYT?

@pkozlowski-opensource
Copy link
Member

This PR doesn't merge cleanly, is very light on tests and has several review comments not addressed so we are going to work towards merging #2595 instead.

pkozlowski-opensource added a commit that referenced this pull request Aug 16, 2018
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.

None yet

4 participants