Skip to content

Commit a7a5f85

Browse files
CopilotLiNk-NY
andcommitted
Implement accessibility improvements for screen readers on Ask a Question page
Co-authored-by: LiNk-NY <[email protected]>
1 parent 912ebcb commit a7a5f85

File tree

5 files changed

+125
-7
lines changed

5 files changed

+125
-7
lines changed

biostar/forum/forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ class PostLongForm(forms.Form):
168168
choices = informative_choices(choices=choices)
169169

170170
post_type = forms.IntegerField(label="Post Type",
171-
widget=forms.Select(choices=choices, attrs={'class': "ui dropdown"}),
171+
widget=forms.Select(choices=choices, attrs={
172+
'class': "ui dropdown",
173+
'aria-label': "Select post type",
174+
'aria-required': "true",
175+
'aria-describedby': "post_type_help"
176+
}),
172177
help_text="Select a post type.")
173178
title = forms.CharField(label="Post Title", max_length=200, min_length=2,
174179
validators=[valid_title, validate_ascii],

biostar/forum/templates/new_post.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<div class="required field">
4242
<label>{{ form.post_type.label }}</label>
4343
{{ form.post_type }}
44-
<p class="muted" style="display: contents; ">{{ form.post_type.help_text }} Click here for
44+
<p class="muted" id="post_type_help" style="display: contents; ">{{ form.post_type.help_text }} Click here for
4545
more</p> {% include 'forms/help_text.html' %}
4646
</div>
4747

@@ -51,7 +51,7 @@
5151
{% block new_tag_val %}
5252
{{ form.tag_val }}
5353
{% endblock %}
54-
<p class="muted">{{ form.tag_val.help_text }}</p>
54+
<p class="muted" id="tag_val_help">{{ form.tag_val.help_text }}</p>
5555
</div>
5656

5757

biostar/forum/templatetags/forum_tags.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,12 @@ def inplace_type_field(post=None, field_id='type'):
320320
(opt[0] in Post.TOP_LEVEL), choices)
321321

322322
post_type = forms.IntegerField(label="Post Type",
323-
widget=forms.Select(choices=choices, attrs={'class': "ui fluid dropdown",
324-
'id': field_id}),
323+
widget=forms.Select(choices=choices, attrs={
324+
'class': "ui fluid dropdown",
325+
'id': field_id,
326+
'aria-label': "Select post type",
327+
'aria-required': "true"
328+
}),
325329
help_text="Select a post type.")
326330

327331
value = post.type if post else Post.QUESTION

themes/bioconductor/static/theme.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,66 @@ body {
118118
background-color: #87B13F !important;
119119
color: white;
120120
}
121+
122+
/* ========================================
123+
Accessibility improvements for dropdowns
124+
======================================== */
125+
126+
/* Ensure native select elements are accessible when JavaScript is disabled */
127+
.ui.dropdown select {
128+
opacity: 1 !important;
129+
position: static !important;
130+
height: auto !important;
131+
width: 100% !important;
132+
visibility: visible !important;
133+
}
134+
135+
/* Style native selects to look consistent */
136+
.ui.dropdown.disabled select,
137+
noscript .ui.dropdown select {
138+
display: block !important;
139+
opacity: 1 !important;
140+
position: static !important;
141+
height: auto !important;
142+
width: 100% !important;
143+
visibility: visible !important;
144+
background: white;
145+
border: 1px solid rgba(34,36,38,.15);
146+
border-radius: .28571429rem;
147+
padding: .67857143em 1em;
148+
font-size: 1em;
149+
line-height: 1.21428571em;
150+
}
151+
152+
/* Hide the custom dropdown UI when JavaScript is disabled */
153+
noscript .ui.dropdown .text,
154+
noscript .ui.dropdown .dropdown.icon {
155+
display: none !important;
156+
}
157+
158+
/* Ensure focus is visible on all interactive elements */
159+
.ui.dropdown:focus,
160+
.ui.dropdown select:focus {
161+
outline: 2px solid #0066cc;
162+
outline-offset: 2px;
163+
}
164+
165+
/* Improve screen reader announcements */
166+
.sr-only {
167+
position: absolute;
168+
left: -10000px;
169+
width: 1px;
170+
height: 1px;
171+
overflow: hidden;
172+
}
173+
174+
/* Ensure form validation messages are accessible */
175+
.field .error.message {
176+
color: #9f3a38;
177+
font-weight: 600;
178+
}
179+
180+
.field .error.message:before {
181+
content: "Error: ";
182+
font-weight: bold;
183+
}
Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
11
<select multiple="multiple" name="{{ form_field.name }}" id="{{ form_field.id_for_label }}"
2-
class="ui search selection dropdown tags" data-placeholder="Select tags">
2+
class="ui search selection dropdown tags" data-placeholder="Select tags"
3+
aria-label="Select post tags"
4+
aria-required="true"
5+
aria-describedby="tag_val_help">
36
{% for value, is_selected in dropdown_options %}
47
<option value="{{ value }}" {% if is_selected or value == 'Bioconductor' %}selected{% endif %}>
58
{{ value }}
69
</option>
710
{% endfor %}
811
</select>
912

13+
<!-- Fallback instructions for screen readers when JavaScript is disabled -->
14+
<noscript>
15+
<p class="sr-only">JavaScript is disabled. Use the above multi-select dropdown to choose tags. Hold Ctrl (Windows) or Cmd (Mac) while clicking to select multiple tags.</p>
16+
</noscript>
17+
1018
<script>
1119
$(document).ready(function() {
1220
$('.ui.dropdown.tags').dropdown({
13-
allowAdditions: true // optional, only if you want new tags allowed
21+
allowAdditions: true, // optional, only if you want new tags allowed
22+
// Add accessibility support for keyboard navigation
23+
keys: {
24+
delimiter: 32, // spacebar
25+
deleteKey: 8, // backspace
26+
leftArrow: 37,
27+
upArrow: 38,
28+
rightArrow: 39,
29+
downArrow: 40,
30+
enter: 13,
31+
escape: 27,
32+
tab: 9
33+
},
34+
// Enable keyboard navigation
35+
allowAdditions: true,
36+
hideAdditions: false,
37+
// Ensure screen reader can access the dropdown
38+
forceSelection: false,
39+
// Add aria-live region for screen reader announcements
40+
onChange: function(value, text, $choice) {
41+
// Update aria-live region when selection changes
42+
var announcement = 'Selected: ' + text;
43+
if (!$('#tag-announcements').length) {
44+
$('body').append('<div id="tag-announcements" aria-live="polite" aria-atomic="true" style="position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden;"></div>');
45+
}
46+
$('#tag-announcements').text(announcement);
47+
}
1448
}).dropdown('set selected', ['Bioconductor']);
49+
50+
// Ensure dropdown button is properly labeled for screen readers
51+
$('.ui.dropdown.tags > .dropdown.icon').attr('aria-hidden', 'true');
52+
$('.ui.dropdown.tags').attr('role', 'combobox');
53+
$('.ui.dropdown.tags').attr('aria-expanded', 'false');
54+
55+
// Update aria-expanded when dropdown opens/closes
56+
$('.ui.dropdown.tags').on('dropdown.open', function() {
57+
$(this).attr('aria-expanded', 'true');
58+
}).on('dropdown.close', function() {
59+
$(this).attr('aria-expanded', 'false');
60+
});
1561
});
1662
</script>

0 commit comments

Comments
 (0)