Skip to content

Commit 8a920d2

Browse files
committed
Screen reader labels for inline fields
1 parent 94d29ec commit 8a920d2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

app/js/directives/form.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,13 @@ formsAngular
321321

322322
var generateLabel = function (fieldInfo, addButtonMarkup, options) {
323323
var labelHTML = '';
324-
if ((options.formstyle !== 'inline' && (fieldInfo.label !== '' || cssFrameworkService.framework() === 'bs3')) || addButtonMarkup) {
324+
if ((cssFrameworkService.framework() === 'bs3' || (options.formstyle !== 'inline' && fieldInfo.label !== '')) || addButtonMarkup) {
325325
labelHTML = '<label';
326326
if (isHorizontalStyle(options.formstyle)) {
327327
labelHTML += ' for="' + fieldInfo.id + '"';
328328
if (cssFrameworkService.framework() === 'bs3') { labelHTML += addAll('Label', 'col-sm-2', options); }
329+
} else if (options.formstyle === 'inline') {
330+
labelHTML += ' for="' + fieldInfo.id + '" class="sr-only"';
329331
}
330332
labelHTML += addAll('Label', 'control-label', options);
331333
labelHTML += '>' + fieldInfo.label + (addButtonMarkup || '') + '</label>';

test/unit/formInputSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,21 @@ describe('formInput', function () {
695695
});
696696
});
697697

698+
describe('labels in inline forms (BS2)', function () {
699+
700+
beforeEach(inject(function ($rootScope, $compile) {
701+
elm = angular.element('<div><form-input formStyle="inline" schema="formSchema"></form-input></div>');
702+
scope = $rootScope;
703+
scope.formSchema = {name: 'desc', id: 'descId', label: 'Description', type: 'text'};
704+
$compile(elm)(scope);
705+
scope.$digest();
706+
}));
707+
708+
it('should not have a label', function () {
709+
var label = elm.find('label');
710+
expect(label.length).toBe(0);
711+
});
712+
713+
});
714+
698715
});

0 commit comments

Comments
 (0)