Skip to content
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

fix(module: date-picker-view): add async data input support #718

Merged
merged 2 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/picker-view/picker-view.component.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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