Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(modal): improve ARIA support
Browse files Browse the repository at this point in the history
- Add aria-labelledby and aria-described by support

Closes #4772
  • Loading branch information
NickHeiner authored and wesleycho committed Aug 18, 2016
1 parent af6c2aa commit 4a5e6a7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/modal/docs/demo.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
<h3 class="modal-title" id="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<div class="modal-body" id="modal-body">
<ul>
<li ng-repeat="item in items">
<a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
Expand All @@ -22,4 +22,4 @@ <h3 class="modal-title">I'm a modal!</h3>
<button type="button" class="btn btn-default" ng-click="open('sm')">Small modal</button>
<button type="button" class="btn btn-default" ng-click="toggleAnimation()">Toggle Animation ({{ animationsEnabled }})</button>
<div ng-show="selected">Selection from a modal: {{ selected }}</div>
</div>
</div>
2 changes: 2 additions & 0 deletions src/modal/docs/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope

var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
Expand Down
8 changes: 8 additions & 0 deletions src/modal/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ The `$uibModal` service has only one method: `open(options)`.
* `appendTo`
_(Type: `angular.element`, Default: `body`: Example: `$document.find('aside').eq(0)`)_ -
Appends the modal to a specific element.

* `ariaDescribedBy`
_(Type: `string`, `my-modal-description`)_ -
Sets the [`aria-describedby`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-describedby) property on the modal. The value should be an id (without the leading `#`) pointing to the element that describes your modal. Typically, this will be the text on your modal, but does not include something the user would interact with, like buttons or a form. Omitting this option will not impact sighted users but will weaken your accessibility support.

* `ariaLabelledBy`
_(Type: `string`, `my-modal-title`)_ -
Sets the [`aria-labelledby`](https://www.w3.org/TR/wai-aria/states_and_properties#aria-labelledby) property on the modal. The value should be an id (without the leading `#`) pointing to the element that labels your modal. Typically, this will be a header element. Omitting this option will not impact sighted users but will weaken your accessibility support.

* `backdrop`
_(Type: `boolean|string`, Default: `true`)_ -
Expand Down
4 changes: 4 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
'template-url': modal.windowTemplateUrl,
'window-top-class': modal.windowTopClass,
'role': 'dialog',
'aria-labelledby': modal.ariaLabelledBy,
'aria-describedby': modal.ariaDescribedBy,
'size': modal.size,
'index': topModalIndex,
'animate': 'animate',
Expand Down Expand Up @@ -755,6 +757,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
windowTopClass: modalOptions.windowTopClass,
windowClass: modalOptions.windowClass,
windowTemplateUrl: modalOptions.windowTemplateUrl,
ariaLabelledBy: modalOptions.ariaLabelledBy,
ariaDescribedBy: modalOptions.ariaDescribedBy,
size: modalOptions.size,
openedClass: modalOptions.openedClass,
appendTo: modalOptions.appendTo
Expand Down
22 changes: 22 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,28 @@ describe('$uibModal', function() {
expect(body).not.toHaveClass('modal-open');
});
});

describe('ariaLabelledBy', function() {
it('should add the aria-labelledby property to the modal', function() {
open({
template: '<div><h3 id="modal-label">Modal Label</h3><p id="modal-description">Modal description</p></div>',
ariaLabelledBy: 'modal-label'
});

expect($document.find('.modal').attr('aria-labelledby')).toEqual('modal-label');
});
});

describe('ariaDescribedBy', function() {
it('should add the aria-describedby property to the modal', function() {
open({
template: '<div><h3 id="modal-label">Modal Label</h3><p id="modal-description">Modal description</p></div>',
ariaDescribedBy: 'modal-description'
});

expect($document.find('.modal').attr('aria-describedby')).toEqual('modal-description');
});
});
});

describe('modal window', function() {
Expand Down

0 comments on commit 4a5e6a7

Please sign in to comment.