-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(expansion): add accordion expand/collapse all (#6929) #7461
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
Merged
mmalerba
merged 1 commit into
angular:master
from
nine-entertainment:feature/6929-accordion-expand-collapse-all
Feb 9, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...material-examples/expansion-expand-collapse-all/expansion-expand-collapse-all-example.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.example-action-buttons { | ||
padding-bottom: 20px; | ||
} | ||
|
||
.example-headers-align .mat-expansion-panel-header-title, | ||
.example-headers-align .mat-expansion-panel-header-description { | ||
flex-basis: 0; | ||
} | ||
|
||
.example-headers-align .mat-expansion-panel-header-description { | ||
justify-content: space-between; | ||
align-items: center; | ||
} |
60 changes: 60 additions & 0 deletions
60
...aterial-examples/expansion-expand-collapse-all/expansion-expand-collapse-all-example.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<div class="example-action-buttons"> | ||
<button mat-button (click)="accordion.openAll()">Expand All</button> | ||
<button mat-button (click)="accordion.closeAll()">Collapse All</button> | ||
</div> | ||
<mat-accordion class="example-headers-align" [multi]="true"> | ||
<mat-expansion-panel> | ||
<mat-expansion-panel-header> | ||
<mat-panel-title> | ||
Personal data | ||
</mat-panel-title> | ||
<mat-panel-description> | ||
Type your name and age | ||
<mat-icon>account_circle</mat-icon> | ||
</mat-panel-description> | ||
</mat-expansion-panel-header> | ||
|
||
<mat-form-field> | ||
<input matInput placeholder="First name"> | ||
</mat-form-field> | ||
|
||
<mat-form-field> | ||
<input matInput type="number" min="1" placeholder="Age"> | ||
</mat-form-field> | ||
|
||
</mat-expansion-panel> | ||
|
||
<mat-expansion-panel [disabled]="true"> | ||
<mat-expansion-panel-header> | ||
<mat-panel-title> | ||
Destination | ||
</mat-panel-title> | ||
<mat-panel-description> | ||
Type the country name | ||
<mat-icon>map</mat-icon> | ||
</mat-panel-description> | ||
</mat-expansion-panel-header> | ||
|
||
<mat-form-field> | ||
<input matInput placeholder="Country"> | ||
</mat-form-field> | ||
</mat-expansion-panel> | ||
|
||
<mat-expansion-panel> | ||
<mat-expansion-panel-header> | ||
<mat-panel-title> | ||
Day of the trip | ||
</mat-panel-title> | ||
<mat-panel-description> | ||
Inform the date you wish to travel | ||
<mat-icon>date_range</mat-icon> | ||
</mat-panel-description> | ||
</mat-expansion-panel-header> | ||
|
||
<mat-form-field> | ||
<input matInput placeholder="Date" [matDatepicker]="picker" (focus)="picker.open()" readonly> | ||
</mat-form-field> | ||
<mat-datepicker #picker></mat-datepicker> | ||
</mat-expansion-panel> | ||
|
||
</mat-accordion> |
14 changes: 14 additions & 0 deletions
14
src/material-examples/expansion-expand-collapse-all/expansion-expand-collapse-all-example.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Component, ViewChild} from '@angular/core'; | ||
import {MatAccordion} from '@angular/material'; | ||
|
||
/** | ||
* @title Accordion with expand/collapse all toggles | ||
*/ | ||
@Component({ | ||
selector: 'expansion-toggle-all-example', | ||
templateUrl: 'expansion-expand-collapse-all-example.html', | ||
styleUrls: ['expansion-expand-collapse-all-example.css'] | ||
}) | ||
export class ExpansionExpandCollapseAllExample { | ||
@ViewChild(MatAccordion) accordion: MatAccordion; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some cases, even for
[multi]="false"
, where you don't care whichCdkAccordionItem
is open, you just want to make sure that all are closed and it would be nice to also cover that use case, but I'm not sure how this could be done without confusing developers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you could do
this.multi || !expanded
? Will have to experiment.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a solution, but we could have a "cleaner" solution, if I may use this word.
This would be a good solution for this particular case. But maybe we could find a more generic solution that could be used in other cases and not confuse people to much,
openAll()
won't work in single mode, but we could haveopen()
that works for single mode, opening the first item or in multi mode.If you look at something like the
SelectionModel
for tables, select and chips, the selection has agetMultipleValuesInSingleSelectionError
, we could use something like that. AndMatSelectionList.selectedOptions
exposes the model for anyone to use. But probably a model would be an overkill for this situation, I'm not sure in how many places we could reuse it.Also,
MatDrawerContainer
container has a similar behavior but it doesn't add theAll
suffix and it uses@ContentChildren
to keep a list of children and then call open/close on each children, instead of emitting events, here's a snippet from it:Using
ContentChildren
instead of emitting an event and rename toopen/close
in order to support "multi/single" mode, would be great.P.S. Thanks for the work you did on this PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This maybe warrants a separate issue to investigate?