Skip to content

Commit

Permalink
fix(module: date-picker-view): add async data input support (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuonuoge committed Jul 1, 2020
1 parent 364d368 commit f2748f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions components/picker-view/picker-view.component.spec.ts
Expand Up @@ -38,6 +38,22 @@ describe('PickerViewComponent', () => {
expect(component).toBeTruthy();
});

it('should cols work', () => {
component.cols = 1;
component.seasons = [
{
label: '2013',
children: []
},
{
label: '2014',
children: []
}
];
fixture.detectChanges();
expect(pickerEle.nativeElement.querySelector('.am-picker').children.length).toBe(1);
});

it('should seasons work', () => {
expect(pickerEle.nativeElement.querySelector('.am-picker').children.length).toBeGreaterThan(0, 'seasons has value');
});
Expand Down Expand Up @@ -76,6 +92,7 @@ describe('PickerViewComponent', () => {
[data]="seasons"
[cascade]="cascade"
[ngModel]="value"
[cols] = [cols]
[itemStyle]="itemStyle"
[indicatorStyle]="indicatorStyle"
(ngModelChange)="onChange($event)"
Expand All @@ -86,6 +103,7 @@ export class TestPickerViewBasicComponent {
cascade = false;
itemStyle = { color: 'red' };
indicatorStyle = { background: 'red' };
cols = 2;
seasons = [
{
label: '2013',
Expand Down
16 changes: 14 additions & 2 deletions components/picker-view/picker-view.component.ts
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewEncapsulation, AfterViewInit, Input, EventEmitter, forwardRef } from '@angular/core';
import { Component, OnInit, ViewEncapsulation, AfterViewInit, Input, forwardRef, OnChanges, SimpleChanges } from '@angular/core';
import { PickerComponent } from '../picker/picker.component';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
@Component({
Expand All @@ -13,7 +13,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
}
]
})
export class PickerViewComponent extends PickerComponent implements OnInit, AfterViewInit, ControlValueAccessor {
export class PickerViewComponent extends PickerComponent implements OnInit, AfterViewInit, ControlValueAccessor, OnChanges {
options;
@Input()
data: Array<any> = [];
Expand Down Expand Up @@ -45,6 +45,9 @@ export class PickerViewComponent extends PickerComponent implements OnInit, Afte
this.selectedTarget.push({ targetId: `${index}`, currentY: 0 });
}
}
setTimeout(() => {
this.reloadPicker();
});
}

writeValue(value: any[]): void {
Expand All @@ -64,6 +67,15 @@ export class PickerViewComponent extends PickerComponent implements OnInit, Afte
this.pickerViewInit();
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.cols) {
this.dataForRender = [];
}
if (changes.data || changes.cols) {
this.pickerViewInit();
}
}

ngAfterViewInit() {
this.currentPicker = this.elementRef.nativeElement;
this.reloadPicker();
Expand Down

0 comments on commit f2748f0

Please sign in to comment.