Commit 8173fc1a authored by Dries's avatar Dries

- Patch #558928 by mgifford, brandonojc, Owen Barton, Everett Zufelt:...

- Patch #558928 by mgifford, brandonojc, Owen Barton, Everett Zufelt: follow-up on making form element labeling more accessible.
parent ba96cffd
...@@ -2986,6 +2986,9 @@ function theme_file($variables) { ...@@ -2986,6 +2986,9 @@ function theme_file($variables) {
* for radio and checkbox #type elements as set in system_element_info(). * for radio and checkbox #type elements as set in system_element_info().
* If the #title is empty but the field is #required, the label will * If the #title is empty but the field is #required, the label will
* contain only the required marker. * contain only the required marker.
* - invisible: Labels are critical for screen readers to enable them to
* properly navigate through forms but can be visually distracting. This
* property hides the label for everyone except screen readers.
* - attribute: Set the title attribute on the element to create a tooltip * - attribute: Set the title attribute on the element to create a tooltip
* but output no label element. This is supported only for checkboxes * but output no label element. This is supported only for checkboxes
* and radios in form_pre_render_conditional_form_element(). It is used * and radios in form_pre_render_conditional_form_element(). It is used
...@@ -3042,6 +3045,7 @@ function theme_form_element($variables) { ...@@ -3042,6 +3045,7 @@ function theme_form_element($variables) {
$output .= ' ' . $element['#children'] . "\n"; $output .= ' ' . $element['#children'] . "\n";
break; break;
case 'invisible':
case 'after': case 'after':
$output .= ' ' . $element['#children']; $output .= ' ' . $element['#children'];
$output .= ' ' . theme('form_element_label', $variables) . "\n"; $output .= ' ' . theme('form_element_label', $variables) . "\n";
...@@ -3128,10 +3132,15 @@ function theme_form_element_label($variables) { ...@@ -3128,10 +3132,15 @@ function theme_form_element_label($variables) {
$title = filter_xss_admin($element['#title']); $title = filter_xss_admin($element['#title']);
$attributes = array(); $attributes = array();
// Style the label as class option to display inline with the element.
if ($element['#title_display'] == 'after') { if ($element['#title_display'] == 'after') {
// Style the label as class option to display inline with the element.
$attributes['class'] = 'option'; $attributes['class'] = 'option';
} }
// Show label only to screen readers to avoid disruption in visual flows.
elseif ($element['#title_display'] == 'invisible') {
$attributes['class'] = 'element-invisible';
}
if (!empty($element['#id'])) { if (!empty($element['#id'])) {
$attributes['for'] = $element['#id']; $attributes['for'] = $element['#id'];
} }
......
...@@ -305,6 +305,9 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase { ...@@ -305,6 +305,9 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase {
$elements = $this->xpath('//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]'); $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]');
$this->assertTrue(isset($elements[0]), t("Label after field and label option class correct for text field.")); $this->assertTrue(isset($elements[0]), t("Label after field and label option class correct for text field."));
$elements = $this->xpath('//input[@id="edit-form-textfield-test-title-invisible"]/following-sibling::label[@for="edit-form-textfield-test-title-invisible" and @class="element-invisible"]');
$this->assertTrue(isset($elements[0]), t("Label after field and label class is element-invisible."));
$elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]'); $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]');
$this->assertFalse(isset($elements[0]), t("No label tag when title set not to display.")); $this->assertFalse(isset($elements[0]), t("No label tag when title set not to display."));
} }
......
...@@ -544,6 +544,11 @@ function form_label_test_form(&$form_state) { ...@@ -544,6 +544,11 @@ function form_label_test_form(&$form_state) {
'#title' => t('Textfield test for title after element'), '#title' => t('Textfield test for title after element'),
'#title_display' => 'after', '#title_display' => 'after',
); );
$form['form_textfield_test_title_invisible'] = array(
'#type' => 'textfield',
'#title' => t('Textfield test for invisible title'),
'#title_display' => 'invisible',
);
// Textfield test for title set not to display // Textfield test for title set not to display
$form['form_textfield_test_title_no_show'] = array( $form['form_textfield_test_title_no_show'] = array(
'#type' => 'textfield', '#type' => 'textfield',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment