Skip to content

Commit

Permalink
Issue691 (#692)
Browse files Browse the repository at this point in the history
* fixes #691 现在tabs的高度随内容改变,要改成固定高度,内容随高度出滚动条

Change-Id: Idcee13235e600ece8c18d616359b3028847ab437

* optimize

Change-Id: I28ea232489d2dc3d39a5b83224d9ed206800a48e
  • Loading branch information
hpyou authored Aug 16, 2018
1 parent 5ad8424 commit d042acf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/app/demo/tab/basic/demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<!-- start to learn the demo from here -->
<div class="container">
<jigsaw-tabs (selectChange)="testEvent($event)" [selectedIndex]="2">
<jigsaw-tabs (selectChange)="testEvent($event)" [selectedIndex]="2" height="200">
<jigsaw-tab-pane [lazy]="false">
<div jigsaw-title><span class="fa fa-gift"></span>tab 1</div>
<ng-template>tab content 1</ng-template>
Expand Down
3 changes: 2 additions & 1 deletion src/jigsaw/component/tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {JigsawTab} from './tab';
import {JigsawTabPane} from "./tab-pane";
import {CommonModule} from "@angular/common";
import {JigsawTabContent, JigsawTabLabel} from "./tab-item";
import {PerfectScrollbarModule} from "ngx-perfect-scrollbar";

@NgModule({
imports: [CommonModule],
imports: [CommonModule, PerfectScrollbarModule],
exports: [JigsawTab, JigsawTabPane],
declarations: [JigsawTab, JigsawTabPane, JigsawTabLabel, JigsawTabContent],
providers: [],
Expand Down
3 changes: 2 additions & 1 deletion src/jigsaw/component/tabs/tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
</div>
</div>
</div>
<div class="jigsaw-tabs-content" *ngIf="_$tabPanes && _$tabPanes.length > 0">
<div class="jigsaw-tabs-content" [perfectScrollbar]="{wheelSpeed: 0.5, wheelPropagation: true}"
[style.height]="_$contentHeight">
<jigsaw-tab-content
*ngFor="let tab of _$tabPanes; let i = index;"
[key]="i"
Expand Down
1 change: 1 addition & 0 deletions src/jigsaw/component/tabs/tab.scss
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ $tab-prefix: #{$jigsaw-prefix}-tabs;
display: block;
flex-shrink: 0;
width: 100%;
height: 100%;
transition: transform 0.5s;
opacity: 1;

Expand Down
18 changes: 17 additions & 1 deletion src/jigsaw/component/tabs/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import {AbstractJigsawComponent, IDynamicInstantiatable} from "../common";
host: {
'[class.jigsaw-tabs-host]': 'true',
'[style.width]': 'width',
'[style.height]': 'height'
}
})
export class JigsawTab extends AbstractJigsawComponent implements AfterViewInit, AfterViewChecked {

constructor(private _cfr: ComponentFactoryResolver,
private _changeDetector: ChangeDetectorRef,
private _viewContainer: ViewContainerRef) {
private _viewContainer: ViewContainerRef,
private _elementRef: ElementRef) {
super()
}

Expand Down Expand Up @@ -214,6 +216,20 @@ export class JigsawTab extends AbstractJigsawComponent implements AfterViewInit,
this.remove.emit(index);
}

/**
* @internal
*/
public _$contentHeight: string = 'auto';

ngOnInit() {
if(this.height) {
setTimeout(() => {
// 等待dom渲染
this._$contentHeight = this._elementRef.nativeElement.offsetHeight - 46 + 'px';
})
}
}

ngAfterViewInit() {
if (this.selectedIndex != null) {
this._handleSelectChange(this.selectedIndex)
Expand Down

0 comments on commit d042acf

Please sign in to comment.