Skip to content

Commit 924a148

Browse files
committed
refactor(material/sort): explicit sort direction
1 parent f466a2b commit 924a148

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/material/sort/sort-direction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
*/
88

99
export type SortDirection = 'asc' | 'desc' | '';
10+
11+
export type SortDirectionExplicit = Exclude<SortDirection, ''>;

src/material/sort/sort-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {ENTER, SPACE} from '@angular/cdk/keycodes';
2626
import {merge, Subscription} from 'rxjs';
2727
import {MatSort, MatSortable} from './sort';
2828
import {matSortAnimations} from './sort-animations';
29-
import {SortDirection} from './sort-direction';
29+
import {SortDirection, SortDirectionExplicit} from './sort-direction';
3030
import {getSortHeaderNotContainedWithinSortError} from './sort-errors';
3131
import {MatSortHeaderIntl} from './sort-header-intl';
3232

@@ -130,7 +130,7 @@ export class MatSortHeader extends _MatSortHeaderBase
130130
@Input() arrowPosition: 'before' | 'after' = 'after';
131131

132132
/** Overrides the sort start value of the containing MatSort for this MatSortable. */
133-
@Input() start: 'asc' | 'desc';
133+
@Input() start: SortDirectionExplicit;
134134

135135
/** Overrides the disable clear value of the containing MatSort for this MatSortable. */
136136
@Input()

src/material/sort/sort.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
mixinInitialized,
2727
} from '@angular/material/core';
2828
import {Subject} from 'rxjs';
29-
import {SortDirection} from './sort-direction';
29+
import {SortDirection, SortDirectionExplicit} from './sort-direction';
3030
import {
3131
getSortDuplicateSortableIdError,
3232
getSortHeaderMissingIdError,
@@ -39,7 +39,7 @@ export interface MatSortable {
3939
id: string;
4040

4141
/** Starting sort direction. */
42-
start: 'asc' | 'desc';
42+
start: SortDirectionExplicit;
4343

4444
/** Whether to disable clearing the sorting state. */
4545
disableClear: boolean;
@@ -91,7 +91,7 @@ export class MatSort extends _MatSortBase
9191
* The direction to set when an MatSortable is initially sorted.
9292
* May be overriden by the MatSortable's sort start.
9393
*/
94-
@Input('matSortStart') start: 'asc' | 'desc' = 'asc';
94+
@Input('matSortStart') start: SortDirectionExplicit = 'asc';
9595

9696
/** The sort direction of the currently active MatSortable. */
9797
@Input('matSortDirection')
@@ -192,7 +192,7 @@ export class MatSort extends _MatSortBase
192192
}
193193

194194
/** Returns the sort direction cycle to use given the provided parameters of order and clear. */
195-
function getSortDirectionCycle(start: 'asc' | 'desc',
195+
function getSortDirectionCycle(start: SortDirectionExplicit,
196196
disableClear: boolean): SortDirection[] {
197197
let sortOrder: SortDirection[] = ['asc', 'desc'];
198198
if (start == 'desc') { sortOrder.reverse(); }

tools/public_api_guard/material/sort.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class MatSort extends _MatSortBase implements CanDisable, HasInitialized,
7373
sort(sortable: MatSortable): void;
7474
sortables: Map<string, MatSortable>;
7575
readonly sortChange: EventEmitter<Sort>;
76-
start: 'asc' | 'desc';
76+
start: SortDirectionExplicit;
7777
readonly _stateChanges: Subject<void>;
7878
// (undocumented)
7979
static ɵdir: i0.ɵɵDirectiveDeclaration<MatSort, "[matSort]", ["matSort"], { "disabled": "matSortDisabled"; "active": "matSortActive"; "start": "matSortStart"; "direction": "matSortDirection"; "disableClear": "matSortDisableClear"; }, { "sortChange": "matSortChange"; }, never>;
@@ -85,7 +85,7 @@ export class MatSort extends _MatSortBase implements CanDisable, HasInitialized,
8585
export interface MatSortable {
8686
disableClear: boolean;
8787
id: string;
88-
start: 'asc' | 'desc';
88+
start: SortDirectionExplicit;
8989
}
9090

9191
// @public
@@ -143,7 +143,7 @@ export class MatSortHeader extends _MatSortHeaderBase implements CanDisable, Mat
143143
_showIndicatorHint: boolean;
144144
// (undocumented)
145145
_sort: MatSort;
146-
start: 'asc' | 'desc';
146+
start: SortDirectionExplicit;
147147
_toggleOnInteraction(): void;
148148
_updateArrowDirection(): void;
149149
_viewState: ArrowViewStateTransition;
@@ -181,6 +181,9 @@ export interface Sort {
181181
// @public
182182
export type SortDirection = 'asc' | 'desc' | '';
183183

184+
// @public (undocumented)
185+
export type SortDirectionExplicit = Exclude<SortDirection, ''>;
186+
184187
// (No @packageDocumentation comment for this package)
185188

186189
```

0 commit comments

Comments
 (0)