Skip to content

Commit

Permalink
Fixed #3137
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Jun 19, 2017
1 parent 525c3bd commit cf3346d
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/app/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class Accordion implements BlockableUI {

@Input() lazy: boolean;

private _activeIndex: any;

public tabs: AccordionTab[] = [];

constructor(public el: ElementRef) {}
Expand All @@ -37,6 +39,28 @@ export class Accordion implements BlockableUI {
getBlockableElement(): HTMLElement {
return this.el.nativeElement.children[0];
}

@Input() get activeIndex(): any {
return this._activeIndex;
}

set activeIndex(val: any) {
this._activeIndex = val;

if(this.tabs && this.tabs.length && this._activeIndex != null) {
for(let i = 0; i < this.tabs.length; i++) {
let selected = this.multiple ? this._activeIndex.includes(i) : (i === this._activeIndex);
let changed = selected !== this.tabs[i].selected;

if(changed) {
this.tabs[i].animating = true;
}

this.tabs[i].selected = selected;
this.tabs[i].selectedChange.emit(selected);
}
}
}
}

@Component({
Expand Down
106 changes: 105 additions & 1 deletion src/app/showcase/components/accordion/accordiondemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ <h3>Tab Change Event</h3>
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
</p-accordionTab>
</p-accordion>

<h3>Programmatic Change</h3>
<div style="margin-bottom: 1em">
<button type="button" pButton icon="fa fa-chevron-up" (click)="openPrev()"></button>
<button type="button" pButton icon="fa fa-chevron-down" (click)="openNext()"></button>
</div>

<p-accordion [activeIndex]="index">
<p-accordionTab header="Godfather I">
The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
</p-accordionTab>
<p-accordionTab header="Godfather II">
Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows.
</p-accordionTab>
<p-accordionTab header="Godfather III">
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
</p-accordionTab>
<p-accordionTab header="Godfather IV">
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
</p-accordionTab>
</p-accordion>
</div>

<div class="content-section documentation">
Expand Down Expand Up @@ -152,6 +173,45 @@ <h3>Custom Content at Headers</h3>
Body Content
&lt;/p-accordionTab&gt;
</code>
</pre>

<h3>Programmatic Control</h3>
<p>Tabs can be controlled programmatically using activeIndex property, in single mode it should be a number and in multiple mode an array of numbers
that define the indexes of active tabs.</p>
<pre>
<code class="language-markup" pCode ngNonBindable>
&lt;button type="button" pButton icon="fa fa-chevron-up" (click)="openPrev()"&gt;&lt;/button&gt;
&lt;button type="button" pButton icon="fa fa-chevron-down" (click)="openNext()"&gt;&lt;/button&gt;

&lt;p-accordion [activeIndex]="index"&gt;
&lt;p-accordionTab header="Header 1"&gt;
Content 1
&lt;/p-accordionTab&gt;
&lt;p-accordionTab header="Header 2"&gt;
Content 2
&lt;/p-accordionTab&gt;
&lt;p-accordionTab header="Header 3"&gt;
Content 3
&lt;/p-accordionTab&gt;
&lt;/p-accordion&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
export class AccordionDemo &#123;

index: number = 0;

openNext() &#123;
this.index = (this.index === 2) ? 0 : this.index + 1;
&#125;

openPrev() &#123;
this.index = (this.index === 0) ? 2 : this.index - 1;
&#125;
&#125;
</code>
</pre>

<h3>Properties</h3>
Expand Down Expand Up @@ -190,6 +250,12 @@ <h3>Properties</h3>
<td>false</td>
<td>Defines whether the elements of an inactive panel are created on load or on demand when the panel gets selected.</td>
</tr>
<tr>
<td>activeIndex</td>
<td>any</td>
<td>null</td>
<td>Index of the active tab or an array of indexes to change selected tab programmatically.</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -229,7 +295,8 @@ <h3>Events</h3>
&lt;p-accordion (onOpen)="onTabOpen($event)"&gt;
</code>
</pre>
<pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
onTabOpen(e) &#123;
var index = e.index;
Expand Down Expand Up @@ -320,14 +387,43 @@ <h3>Dependencies</h3>
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
&lt;/p-accordionTab&gt;
&lt;/p-accordion&gt;

&lt;h3&gt;Programmatic Change&lt;/h3&gt;
&lt;div style="margin-bottom: 1em"&gt;
&lt;button type="button" pButton icon="fa fa-chevron-up" (click)="openPrev()"&gt;&lt;/button&gt;
&lt;button type="button" pButton icon="fa fa-chevron-down" (click)="openNext()"&gt;&lt;/button&gt;
&lt;/div&gt;

&lt;p-accordion [activeIndex]="index"&gt;
&lt;p-accordionTab header="Godfather I"&gt;
The story begins as Don Vito Corleone, the head of a New York Mafia family, overseeshis daughter's wedding. His beloved son ichael has just come home from the war, but does not intend to become part of his father's business. T hrough Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family, kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
&lt;/p-accordionTab&gt;
&lt;p-accordionTab header="Godfather II"&gt;
Francis Ford Coppola's legendary continuation and sequel to his landmark 1972 film, The_Godfather parallels the young Vito Corleone's rise with his son Michael's spiritual fall, deepening The_Godfather's depiction of the dark side of the American dream. In the early 1900s, the child Vito flees his Sicilian village for America after the local Mafia kills his family. Vito struggles to make a living, legally or illegally, for his wife and growing brood in Little Italy, killing the local Black Hand Fanucci after he demands his customary cut of the tyro's business. With Fanucci gone, Vito's communal stature grows.
&lt;/p-accordionTab&gt;
&lt;p-accordionTab header="Godfather III"&gt;
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
&lt;/p-accordionTab&gt;
&lt;p-accordionTab header="Godfather IV"&gt;
After a break of more than 15 years, director Francis Ford Coppola and writer Mario Puzo returned to the well for this third and final story of the fictional Corleone crime family. Two decades have passed, and crime kingpin Michael Corleone, now divorced from his wife Kay has nearly succeeded in keeping his promise that his family would one day be completely legitimate.
&lt;/p-accordionTab&gt;
&lt;/p-accordion&gt;
</code>
</pre>

<pre>
<code class="language-typescript" pCode ngNonBindable>
import &#123;Component&#125; from '@angular/core';
import &#123;Message&#125; from '/components/common/api';

@Component(&#123;
templateUrl: './accordiondemo.html'
&#125;)
export class AccordionDemo &#123;

msgs: Message[];

index: number = 0;

onTabClose(event) &#123;
this.msgs = [];
Expand All @@ -338,6 +434,14 @@ <h3>Dependencies</h3>
this.msgs = [];
this.msgs.push(&#123;severity:'info', summary:'Tab Expanded', detail: 'Index: ' + event.index&#125;);
&#125;

openNext() &#123;
this.index = (this.index === 3) ? 0 : this.index + 1;
&#125;

openPrev() &#123;
this.index = (this.index === 0) ? 3 : this.index - 1;
&#125;
&#125;
</code>
</pre>
Expand Down
2 changes: 2 additions & 0 deletions src/app/showcase/components/accordion/accordiondemo.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {CommonModule} from '@angular/common';
import {AccordionDemo} from './accordiondemo';
import {AccordionDemoRoutingModule} from './accordiondemo-routing.module';
import {AccordionModule} from '../../../components/accordion/accordion';
import {ButtonModule} from '../../../components/button/button';
import {TabViewModule} from '../../../components/tabview/tabview';
import {GrowlModule} from '../../../components/growl/growl';
import {CodeHighlighterModule} from '../../../components/codehighlighter/codehighlighter';
Expand All @@ -12,6 +13,7 @@ import {CodeHighlighterModule} from '../../../components/codehighlighter/codehig
CommonModule,
AccordionDemoRoutingModule,
AccordionModule,
ButtonModule,
TabViewModule,
GrowlModule,
CodeHighlighterModule
Expand Down
10 changes: 10 additions & 0 deletions src/app/showcase/components/accordion/accordiondemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {Message} from '../../../components/common/api';
export class AccordionDemo {

msgs: Message[];

index: number = 0;

onTabClose(event) {
this.msgs = [];
Expand All @@ -17,4 +19,12 @@ export class AccordionDemo {
this.msgs = [];
this.msgs.push({severity:'info', summary:'Tab Expanded', detail: 'Index: ' + event.index});
}

openNext() {
this.index = (this.index === 3) ? 0 : this.index + 1;
}

openPrev() {
this.index = (this.index === 0) ? 3 : this.index - 1;
}
}

0 comments on commit cf3346d

Please sign in to comment.