Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessible <select> elem solution #2013

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Chosen extends AbstractChosen
'class': container_classes.join ' '
'style': "width: #{this.container_width()};"
'title': @form_field.title
'aria-hidden': true

container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length

Expand All @@ -44,7 +45,7 @@ class Chosen extends AbstractChosen
else
@container.html '<a class="chosen-single chosen-default" tabindex="-1"><span>' + @default_text + '</span><div><b></b></div></a><div class="chosen-drop"><div class="chosen-search"><input type="text" autocomplete="off" /></div><ul class="chosen-results"></ul></div>'

@form_field_jq.hide().after @container
@form_field_jq.addClass('chosen-sr-only').after @container
@dropdown = @container.find('div.chosen-drop').first()

@search_field = @container.find('input').first()
Expand Down
3 changes: 2 additions & 1 deletion coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class @Chosen extends AbstractChosen
'class': container_classes.join ' '
'style': "width: #{this.container_width()};"
'title': @form_field.title
'aria-hidden': true

container_props.id = @form_field.id.replace(/[^\w]/g, '_') + "_chosen" if @form_field.id.length

@container = if @is_multiple then new Element('div', container_props).update( @multi_temp.evaluate({ "default": @default_text}) ) else new Element('div', container_props).update( @single_temp.evaluate({ "default":@default_text }) )

@form_field.hide().insert({ after: @container })
@form_field.addClassName('chosen-sr-only').insert({ after: @container })
@dropdown = @container.down('div.chosen-drop')

@search_field = @container.down('input')
Expand Down
12 changes: 12 additions & 0 deletions sass/chosen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,15 @@ $chosen-sprite-retina: image-url('chosen-sprite@2x.png') !default;
}
}
/* @end */

/* @group Accessibility helpers */
.chosen-sr-only {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
border: 0;
}