File tree Expand file tree Collapse file tree 4 files changed +30
-9
lines changed Expand file tree Collapse file tree 4 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -26,9 +26,4 @@ export class MdSortHeaderIntl {
26
26
sortButtonLabel = ( id : string ) => {
27
27
return `Change sorting for ${ id } ` ;
28
28
}
29
-
30
- /** A label to describe the current sort (visible only to screenreaders). */
31
- sortDescriptionLabel = ( id : string , direction : SortDirection ) => {
32
- return `Sorted by ${ id } ${ direction == 'asc' ? 'ascending' : 'descending' } ` ;
33
- }
34
29
}
Original file line number Diff line number Diff line change 13
13
< div class ="mat-sort-header-pointer-right "> </ div >
14
14
</ div >
15
15
</ div >
16
-
17
- < span class ="cdk-visually-hidden " *ngIf ="_isSorted() ">
18
- {{_intl.sortDescriptionLabel(id, _sort.direction)}}
19
- </ span >
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ import {getMdSortHeaderNotContainedWithinMdSortError} from './sort-errors';
46
46
styleUrls : [ 'sort-header.css' ] ,
47
47
host : {
48
48
'(click)' : '_sort.sort(this)' ,
49
+ '[attr.aria-sort]' : '_getAriaSortAttribute()' ,
49
50
'[class.mat-sort-header-sorted]' : '_isSorted()' ,
50
51
} ,
51
52
encapsulation : ViewEncapsulation . None ,
@@ -113,4 +114,16 @@ export class MdSortHeader implements MdSortable {
113
114
_isSorted ( ) {
114
115
return this . _sort . active == this . id && this . _sort . direction ;
115
116
}
117
+
118
+ /**
119
+ * Returns the aria-sort attribute that should be applied to this sort header. If this header
120
+ * is not sorted, returns null so that the attribute is removed from the host element. Aria spec
121
+ * says that the aria-sort property should only be present on one header at a time, so removing
122
+ * ensures this is true.
123
+ */
124
+ _getAriaSortAttribute ( ) {
125
+ if ( ! this . _isSorted ( ) ) { return null ; }
126
+
127
+ return this . _sort . direction == 'asc' ? 'ascending' : 'descending' ;
128
+ }
116
129
}
Original file line number Diff line number Diff line change @@ -144,6 +144,23 @@ describe('MdSort', () => {
144
144
expect ( button . getAttribute ( 'aria-label' ) ) . toBe ( 'Change sorting for defaultSortHeaderA' ) ;
145
145
} ) ;
146
146
147
+ it ( 'should apply the aria-sort label to the header when sorted' , ( ) => {
148
+ const sortHeaderElement = fixture . nativeElement . querySelector ( '#defaultSortHeaderA' ) ;
149
+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( null ) ;
150
+
151
+ component . sort ( 'defaultSortHeaderA' ) ;
152
+ fixture . detectChanges ( ) ;
153
+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( 'ascending' ) ;
154
+
155
+ component . sort ( 'defaultSortHeaderA' ) ;
156
+ fixture . detectChanges ( ) ;
157
+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( 'descending' ) ;
158
+
159
+ component . sort ( 'defaultSortHeaderA' ) ;
160
+ fixture . detectChanges ( ) ;
161
+ expect ( sortHeaderElement . getAttribute ( 'aria-sort' ) ) . toBe ( null ) ;
162
+ } ) ;
163
+
147
164
it ( 'should re-render when the i18n labels have changed' ,
148
165
inject ( [ MdSortHeaderIntl ] , ( intl : MdSortHeaderIntl ) => {
149
166
const header = fixture . debugElement . query ( By . directive ( MdSortHeader ) ) . nativeElement ;
You can’t perform that action at this time.
0 commit comments