Skip to content
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
1 change: 1 addition & 0 deletions src/lib/sort/sort-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<!-- Disable animations while a current animation is running -->
<div class="mat-sort-header-arrow"
*ngIf="_renderArrow()"
[@arrowOpacity]="_getArrowViewState()"
[@arrowPosition]="_getArrowViewState()"
[@allowChildren]="_getArrowDirectionState()"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/sort/sort-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@ export class MatSortHeader extends _MatSortHeaderMixinBase

return this._sort.direction == 'asc' ? 'ascending' : 'descending';
}

/** Whether the arrow inside the sort header should be rendered. */
_renderArrow() {
return !this._isDisabled() || this._isSorted();
}
}
27 changes: 26 additions & 1 deletion src/lib/sort/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {

describe('MatSort', () => {
let fixture: ComponentFixture<SimpleMatSortApp>;

let component: SimpleMatSortApp;

beforeEach(async(() => {
Expand Down Expand Up @@ -384,6 +383,32 @@ describe('MatSort', () => {
expect(button.getAttribute('aria-label')).toBe('Sort all of the things');
})
);

it('should not render the arrow if sorting is disabled for that column', fakeAsync(() => {
const sortHeaderElement = fixture.nativeElement.querySelector('#defaultA');

// Switch sorting to a different column before asserting.
component.sort('defaultB');
fixture.componentInstance.disabledColumnSort = true;
fixture.detectChanges();
tick();
fixture.detectChanges();

expect(sortHeaderElement.querySelector('.mat-sort-header-arrow')).toBeFalsy();
}));

it('should render the arrow if a disabled column is being sorted by', fakeAsync(() => {
const sortHeaderElement = fixture.nativeElement.querySelector('#defaultA');

component.sort('defaultA');
fixture.componentInstance.disabledColumnSort = true;
fixture.detectChanges();
tick();
fixture.detectChanges();

expect(sortHeaderElement.querySelector('.mat-sort-header-arrow')).toBeTruthy();
}));

});

/**
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/lib/sort.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export declare class MatSortHeader extends _MatSortHeaderMixinBase implements Ca
_handleClick(): void;
_isDisabled(): boolean;
_isSorted(): boolean;
_renderArrow(): boolean;
_setAnimationTransitionState(viewState: ArrowViewStateTransition): void;
_setIndicatorHintVisible(visible: boolean): void;
_updateArrowDirection(): void;
Expand Down