Skip to content

Commit 39f5add

Browse files
committed
Fix .visuallyhidden not being actually hidden (fix #106)
1 parent a47d4b5 commit 39f5add

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/typeahead/status.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@ var Status = (function () {
22
'use strict';
33

44
function Status(options) {
5-
this.el = '<span role="status" aria-live="polite" class="visuallyhidden"></span>';
6-
this.$el = $(this.el);
5+
this.$el = $('<span></span>', {
6+
'role': 'status',
7+
'aria-live': 'polite',
8+
}).css({
9+
// This `.visuallyhidden` style is inspired by HTML5 Boilerplate
10+
// https://github.com/h5bp/html5-boilerplate/blob/fea7f22/src/css/main.css#L128
11+
'position': 'absolute',
12+
'padding': '0',
13+
'border': '0',
14+
'height': '1px',
15+
'width': '1px',
16+
'margin-bottom': '-1px',
17+
'margin-right': '-1px',
18+
'overflow': 'hidden',
19+
'clip': 'rect(0 0 0 0)',
20+
'white-space': 'nowrap',
21+
});
722
options.$input.after(this.$el);
823
_.each(options.menu.datasets, _.bind(function (dataset) {
924
if (dataset.onSync) {

test/typeahead/status_spec.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,24 @@ describe('Status', function() {
2525
});
2626

2727
it('renders a status element after the input', function() {
28-
expect(status.el).toEqual('<span role="status" aria-live="polite" class="visuallyhidden"></span>');
28+
expect(status.$el.attr('role')).toEqual('status');
29+
expect(status.$el.attr('aria-live')).toEqual('polite');
2930
expect(status.$el.prev()).toEqual(this.$input);
3031
});
3132

33+
it('renders a status element that is visible to screen readers', function () {
34+
expect(status.$el.attr('aria-hidden')).not.toEqual('true');
35+
expect(status.$el.css('display')).not.toEqual('none');
36+
expect(status.$el.css('visibility')).not.toEqual('hidden');
37+
expect(status.$el.height()).not.toEqual(0);
38+
expect(status.$el.width()).not.toEqual(0);
39+
});
40+
41+
it('renders a status element that is hidden on displays', function () {
42+
expect(status.$el.outerHeight(true)).toEqual(0);
43+
expect(status.$el.outerWidth(true)).toEqual(0);
44+
});
45+
3246
describe('when rendered is triggered on the datasets', function() {
3347

3448
it('should update the status text based on number of suggestion', function() {

0 commit comments

Comments
 (0)