Skip to content

Commit 44debc9

Browse files
authored
feat(dropdown): improve accessibility in relation to search dropdown
in case of using the <label> element before a search dropdown to improove accessibility id of module is used to add an unique id to this very label a reference to this label is made via the attribut "labelledby" see w3.org/WAI/tutorials/forms/labels
1 parent a33107c commit 44debc9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/definitions/modules/dropdown.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ $.fn.dropdown = function(parameters) {
111111
module.error(error.noNormalize, element);
112112
}
113113

114+
module.create.id();
114115
module.setup.layout();
115116

116117
if(settings.values) {
@@ -124,7 +125,6 @@ $.fn.dropdown = function(parameters) {
124125
module.save.defaults();
125126
module.restore.selected();
126127

127-
module.create.id();
128128
module.bind.events();
129129

130130
module.observeChanges();
@@ -366,11 +366,20 @@ $.fn.dropdown = function(parameters) {
366366
}
367367
if( module.is.search() && !module.has.search() ) {
368368
module.verbose('Adding search input');
369+
var
370+
labelNode = $module.prev('label')
371+
;
369372
$search = $('<input />')
370373
.addClass(className.search)
371374
.prop('autocomplete', module.is.chrome() ? 'fomantic-search' : 'off')
372-
.insertBefore($text)
373375
;
376+
if (labelNode.length) {
377+
if (!labelNode.attr('id')) {
378+
labelNode.attr('id', module.get.id() + '_formLabel');
379+
}
380+
$search.attr('aria-labelledby', labelNode.attr('id'));
381+
}
382+
$search.insertBefore($text);
374383
}
375384
if( module.is.multiple() && module.is.searchSelection() && !module.has.sizer()) {
376385
module.create.sizer();

0 commit comments

Comments
 (0)