[ADF-1574] Info Drawer - Add a mechanism to know the current active tab (#2352)

* [ADF-1574] Info Drawer - Add a mechanism to know the current active tab

* Added a output event in adf-info-drawer component to get the currently active tab

* [ADF-1574] Info Drawer - Add a mechanism to know the current active tab

* Added a output event in adf-info-drawer component to get the currently active tab

* Added unit test file

* Updated info-drawer.md
This commit is contained in:
madhukar23
2017-09-21 13:53:47 +05:30
committed by Maurizio Vitale
parent a3020897ed
commit c8743dacc6
4 changed files with 85 additions and 5 deletions

View File

@@ -7,7 +7,7 @@
<ng-container info-drawer-content *ngIf="showTabLayout(); then tabLayout else singleLayout"></ng-container>
<ng-template #tabLayout>
<md-tab-group class="adf-info-drawer-tabs">
<md-tab-group class="adf-info-drawer-tabs" (selectChange)="onTabChange($event)">
<ng-container *ngFor="let contentBlock of contentBlocks">
<md-tab [label]="contentBlock.label" class="adf-info-drawer-tab">
<ng-container *ngTemplateOutlet="contentBlock.content"></ng-container>

View File

@@ -0,0 +1,72 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../material.module';
import { InfoDrawerLayoutComponent } from './info-drawer-layout.component';
import { InfoDrawerComponent } from './info-drawer.component';
declare let jasmine: any;
describe('InfoDrawerComponent', () => {
let componentHandler: any;
let debugElement: DebugElement;
let element: HTMLElement;
let component: InfoDrawerComponent;
let fixture: ComponentFixture<InfoDrawerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
InfoDrawerComponent,
InfoDrawerLayoutComponent
],
imports: [
MaterialModule
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(InfoDrawerComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
debugElement = fixture.debugElement;
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered',
'upgradeElement'
]);
window['componentHandler'] = componentHandler;
});
it('should create instance of InfoDrawerComponent', () => {
expect(fixture.componentInstance instanceof InfoDrawerComponent).toBe(true, 'should create InfoDrawerComponent');
});
it('should define InfoDrawerTabLayout', () => {
let infoDrawerTabLayout = element.querySelector('adf-info-drawer-layout');
expect(infoDrawerTabLayout).toBeDefined();
});
it('should emit when tab is changed', () => {
let tabEmitSpy = spyOn(component.currentTab, 'emit');
let event = {index: 1, tab: {textLabel: 'DETAILS'}};
component.onTabChange(event);
expect(tabEmitSpy).toHaveBeenCalled();
expect(tabEmitSpy).toHaveBeenCalledWith('DETAILS');
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, ContentChildren, Input, QueryList, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
import { Component, ContentChildren, EventEmitter, Input, Output, QueryList, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'adf-info-drawer-tab',
template: '<ng-template><ng-content></ng-content></ng-template>'
@@ -36,10 +36,18 @@ export class InfoDrawerComponent {
@Input()
title: string|null = null;
@Output()
currentTab: EventEmitter<any> = new EventEmitter<any>();
@ContentChildren(InfoDrawerTabComponent)
contentBlocks: QueryList<InfoDrawerTabComponent>;
showTabLayout(): boolean {
return this.contentBlocks.length > 0;
}
onTabChange(event: any) {
const tab = event.tab;
this.currentTab.emit(tab.textLabel);
}
}

View File

@@ -53,19 +53,19 @@ The InfoDrawerLayoutComponent (as the name says) is basically just a layout with
## InfoDrawerComponent
The InfoDrawerComponent is on top of the InfoDrawerLayoutComponent. This version of the info drawer is supposed to be used if you need tabbing behaviour. Additionally you can set a title (if it only contains a string) with the **title** input property.
This component has the same 3 regions as described above, but if you want to leverage the tabbing functionality, you have to use the **adf-info-drawer-tab** component to organize your content. The only input paramter of the adf-info-drawer-tab component is the **"label"**, with you can specify the tab label with.
The InfoDrawerComponent is on top of the InfoDrawerLayoutComponent. This version of the info drawer is supposed to be used if you need tabbing behaviour. You can set a title (if it only contains a string) with the **title** input property. Additionally, It also provides a **currentTab** output property. This component has the same 3 regions as described above, but if you want to leverage the tabbing functionality, you have to use the **adf-info-drawer-tab** component to organize your content. The only input paramter of the adf-info-drawer-tab component is the **"label"**, with you can specify the tab label with.
### Properties
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| title | string | null | The title of the info drawer component|
| currentTab | any | null | The current active tab |
### Example
```html
<adf-info-drawer title="Activities">
<adf-info-drawer title="Activities" (currentTab)="getActiveTab($event)">
<div info-drawer-buttons>
<md-icon (click)="close()">clear</md-icon>
</div>