Skip to content

Commit 2677f67

Browse files
Phil Saltermportuga
Phil Salter
authored andcommitted
feat: 🎸 add 'aria-expanded' to expand buttons for accessibility
1 parent 3a4a27f commit 2677f67

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

‎packages/expandable/src/templates/expandableRowHeader.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<i class="clickable"
44
ng-if="!(row.groupHeader==true || row.entity.subGridOptions.disableRowExpandable)"
55
ng-class="{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }"
6-
ng-click="grid.api.expandable.toggleRowExpansion(row.entity, $event)">
6+
ng-click="grid.api.expandable.toggleRowExpansion(row.entity, $event)"
7+
aria-expanded="{{!!row.isExpanded}}">
78
</i>
89
</div>
910
</div>

‎packages/expandable/src/templates/expandableTopRowHeader.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<button type="button" class="ui-grid-icon-button clickable"
55
ng-if="grid.options.showExpandAllButton"
66
ng-class="{ 'ui-grid-icon-plus-squared' : !grid.expandable.expandedAll, 'ui-grid-icon-minus-squared' : grid.expandable.expandedAll }"
7-
ng-click="grid.api.expandable.toggleAllRows()">
7+
ng-click="grid.api.expandable.toggleAllRows()"
8+
aria-expanded="{{grid.expandable.expandedAll}}">
89
</button>
910
</div>
1011
</div>

‎packages/expandable/test/expandable.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,36 @@ describe('ui.grid.expandable', function() {
8989
expect(element.find('.test').length).toBe(1);
9090
});
9191
});
92+
93+
it('expand row icon should set the accessibility property aria-expanded', function() {
94+
scope.gridOptions.data.push({ col1: 'row2col1', col2: 'row2col2' });
95+
scope.$apply();
96+
97+
var expandAllButton = element.find('.ui-grid-icon-button');
98+
var expandRowIcons = element.find('.ui-grid-viewport .ui-grid-expandable-buttons-cell .clickable');
99+
100+
expect(expandAllButton.attr('aria-expanded')).toBe('false');
101+
expect(expandRowIcons.eq(0).attr('aria-expanded')).toBe('false');
102+
expect(expandRowIcons.eq(1).attr('aria-expanded')).toBe('false');
103+
104+
scope.gridApi.expandable.toggleRowExpansion(scope.grid.rows[0].entity);
105+
scope.$apply();
106+
expect(expandAllButton.attr('aria-expanded')).toBe('false');
107+
expect(expandRowIcons.eq(0).attr('aria-expanded')).toBe('true');
108+
expect(expandRowIcons.eq(1).attr('aria-expanded')).toBe('false');
109+
110+
scope.gridApi.expandable.toggleRowExpansion(scope.grid.rows[1].entity);
111+
scope.$apply();
112+
expect(expandAllButton.attr('aria-expanded')).toBe('true');
113+
expect(expandRowIcons.eq(0).attr('aria-expanded')).toBe('true');
114+
expect(expandRowIcons.eq(1).attr('aria-expanded')).toBe('true');
115+
116+
scope.gridApi.expandable.toggleAllRows();
117+
scope.$apply();
118+
expect(expandAllButton.attr('aria-expanded')).toBe('false');
119+
expect(expandRowIcons.eq(0).attr('aria-expanded')).toBe('false');
120+
expect(expandRowIcons.eq(1).attr('aria-expanded')).toBe('false');
121+
});
92122
});
93123

94124
describe('uiGridExpandableService', function() {

0 commit comments

Comments
 (0)