mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3802] Default ascending order fix (#4070)
This commit is contained in:
committed by
Eugenio Romano
parent
b113ad83f1
commit
95260a7ca7
@@ -1,5 +1,5 @@
|
||||
<mat-form-field>
|
||||
<mat-select [(value)]="selected" (selectionChange)="onChanged($event)">
|
||||
<mat-select [(value)]="selected" (selectionChange)="onOptionChanged($event)">
|
||||
<mat-option *ngFor="let option of options" [value]="option.key">
|
||||
{{ option.label | translate }}
|
||||
</mat-option>
|
||||
|
@@ -27,23 +27,19 @@ describe('SortingPickerComponent', () => {
|
||||
|
||||
it('should raise changed event on changing value', (done) => {
|
||||
component.selected = 'key1';
|
||||
component.ascending = false;
|
||||
|
||||
component.change.subscribe((event: { key: string, ascending: boolean }) => {
|
||||
expect(event.key).toBe('key2');
|
||||
expect(event.ascending).toBeFalsy();
|
||||
component.valueChange.subscribe((key: string) => {
|
||||
expect(key).toBe('key2');
|
||||
done();
|
||||
});
|
||||
component.onChanged(<any> { value: 'key2' });
|
||||
component.onOptionChanged(<any> { value: 'key2' });
|
||||
});
|
||||
|
||||
it('should raise changed event on changing direction', (done) => {
|
||||
component.selected = 'key1';
|
||||
component.ascending = false;
|
||||
|
||||
component.change.subscribe((event: { key: string, ascending: boolean }) => {
|
||||
expect(event.key).toBe('key1');
|
||||
expect(event.ascending).toBeTruthy();
|
||||
component.sortingChange.subscribe((ascending: boolean) => {
|
||||
expect(ascending).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
component.toggleSortDirection();
|
||||
|
@@ -38,24 +38,21 @@ export class SortingPickerComponent {
|
||||
@Input()
|
||||
ascending = true;
|
||||
|
||||
/** Raised each time sorting key or direction gets changed. */
|
||||
/** Raised each time sorting key gets changed. */
|
||||
@Output()
|
||||
change = new EventEmitter<{ key: string, ascending: boolean }>();
|
||||
valueChange = new EventEmitter<string>();
|
||||
|
||||
onChanged(event: MatSelectChange) {
|
||||
/** Raised each time direction gets changed. */
|
||||
@Output()
|
||||
sortingChange = new EventEmitter<boolean>();
|
||||
|
||||
onOptionChanged(event: MatSelectChange) {
|
||||
this.selected = event.value;
|
||||
this.raiseChangedEvent();
|
||||
this.valueChange.emit(this.selected);
|
||||
}
|
||||
|
||||
toggleSortDirection() {
|
||||
this.ascending = !this.ascending;
|
||||
this.raiseChangedEvent();
|
||||
}
|
||||
|
||||
private raiseChangedEvent() {
|
||||
this.change.emit({
|
||||
key: this.selected,
|
||||
ascending: this.ascending
|
||||
});
|
||||
this.sortingChange.emit(this.ascending);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user