Skip to content

Commit 4efb44a

Browse files
authored
fix(material/sort): animation not working correctly when activated on focus (#21339)
The sort header arrow animation wasn't working correctly when it was triggered as a result of a focus/blur.
1 parent 43081d9 commit 4efb44a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/material/sort/sort-header.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
141141
private _disableClear: boolean;
142142

143143
constructor(public _intl: MatSortHeaderIntl,
144-
changeDetectorRef: ChangeDetectorRef,
144+
private _changeDetectorRef: ChangeDetectorRef,
145145
// `MatSort` is not optionally injected, but just asserted manually w/ better error.
146146
// tslint:disable-next-line: lightweight-tokens
147147
@Optional() public _sort: MatSort,
@@ -171,7 +171,7 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
171171
this._setAnimationTransitionState({fromState: 'active', toState: this._arrowDirection});
172172
}
173173

174-
changeDetectorRef.markForCheck();
174+
_changeDetectorRef.markForCheck();
175175
});
176176
}
177177

@@ -191,8 +191,13 @@ export class MatSortHeader extends _MatSortHeaderMixinBase
191191
ngAfterViewInit() {
192192
// We use the focus monitor because we also want to style
193193
// things differently based on the focus origin.
194-
this._focusMonitor.monitor(this._elementRef, true)
195-
.subscribe(origin => this._setIndicatorHintVisible(!!origin));
194+
this._focusMonitor.monitor(this._elementRef, true).subscribe(origin => {
195+
const newState = !!origin;
196+
if (newState !== this._showIndicatorHint) {
197+
this._setIndicatorHintVisible(newState);
198+
this._changeDetectorRef.markForCheck();
199+
}
200+
});
196201
}
197202

198203
ngOnDestroy() {

tools/public_api_guard/material/sort.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export declare class MatSortHeader extends _MatSortHeaderMixinBase implements Ca
6464
set disableClear(v: boolean);
6565
id: string;
6666
start: 'asc' | 'desc';
67-
constructor(_intl: MatSortHeaderIntl, changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef, _focusMonitor: FocusMonitor, _elementRef: ElementRef<HTMLElement>);
67+
constructor(_intl: MatSortHeaderIntl, _changeDetectorRef: ChangeDetectorRef, _sort: MatSort, _columnDef: MatSortHeaderColumnDef, _focusMonitor: FocusMonitor, _elementRef: ElementRef<HTMLElement>);
6868
_getAriaSortAttribute(): "none" | "ascending" | "descending";
6969
_getArrowDirectionState(): string;
7070
_getArrowViewState(): string;

0 commit comments

Comments
 (0)