Skip to content

Commit ab48689

Browse files
committed
fix(material/sort): If there is no direction, setting active as empty
1 parent 3db90f6 commit ab48689

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/material/sort/sort.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,19 @@ function testSingleColumnSortDirectionSequence(
459459
component.matSort.direction = '';
460460

461461
// Run through the sequence to confirm the order
462-
let actualSequence = expectedSequence.map(() => {
462+
let actualSequence = expectedSequence.map((currentSequence) => {
463463
component.sort(id);
464464

465465
// Check that the sort event's active sort is consistent with the MatSort
466-
expect(component.matSort.active).toBe(id);
467-
expect(component.latestSortEvent.active).toBe(id);
466+
if (currentSequence) {
467+
expect(component.matSort.active).toBe(id);
468+
expect(component.latestSortEvent.active).toBe(id);
469+
} else {
470+
// For empty sequence the mat sort active should be empty
471+
expect(component.matSort.active).toBe('');
472+
expect(component.latestSortEvent.active).toBe('');
473+
}
474+
468475

469476
// Check that the sort event's direction is consistent with the MatSort
470477
expect(component.matSort.direction).toBe(component.latestSortEvent.direction);

src/material/sort/sort.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class MatSort extends _MatSortMixinBase
8989
readonly _stateChanges = new Subject<void>();
9090

9191
/** The id of the most recently sorted MatSortable. */
92-
@Input('matSortActive') active: string;
92+
@Input('matSortActive') active: string = '';
9393

9494
/**
9595
* The direction to set when an MatSortable is initially sorted.
@@ -160,7 +160,9 @@ export class MatSort extends _MatSortMixinBase
160160
} else {
161161
this.direction = this.getNextSortDirection(sortable);
162162
}
163-
163+
if (!this.direction) {
164+
this.active = '';
165+
}
164166
this.sortChange.emit({active: this.active, direction: this.direction});
165167
}
166168

0 commit comments

Comments
 (0)