Skip to content

Commit fd11ee2

Browse files
Merge pull request #403 from JLG-WOCFR-DEV/codex/prioritize-code-recommendations
Improve accessibility of inline help tooltips
2 parents 51b9446 + b0af4d0 commit fd11ee2

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

liens-morts-detector-jlg/assets/js/blc-admin-scripts.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,12 @@ jQuery(document).ready(function($) {
44834483
$button.removeClass('is-active').attr('aria-expanded', 'false');
44844484
}
44854485

4486+
var $bubble = $wrapper.find('.blc-field-help__bubble');
4487+
if ($bubble.length) {
4488+
$bubble.attr('aria-hidden', 'true');
4489+
$bubble.attr('hidden', 'hidden');
4490+
}
4491+
44864492
$openWrapper = null;
44874493
}
44884494

@@ -4500,6 +4506,8 @@ jQuery(document).ready(function($) {
45004506

45014507
var $bubble = $wrapper.find('.blc-field-help__bubble');
45024508
if ($bubble.length) {
4509+
$bubble.attr('aria-hidden', 'false');
4510+
$bubble.removeAttr('hidden');
45034511
var announcement = ($bubble.text() || '').trim();
45044512
if (announcement) {
45054513
speak(announcement, 'polite');
@@ -4577,33 +4585,23 @@ jQuery(document).ready(function($) {
45774585
}
45784586
});
45794587

4580-
$(document).on('focusout', '.blc-field-help', function(event) {
4581-
if (!$openWrapper || !$openWrapper.length) {
4582-
return;
4583-
}
4584-
4585-
var nextTarget = event.relatedTarget || document.activeElement || null;
4586-
4587-
if (isElementAssociatedWithWrapper(nextTarget, $openWrapper)) {
4588+
$(document).on('focusout', '.blc-field-help', function() {
4589+
var $wrapper = $(this).closest('.blc-field-help-wrapper');
4590+
if (!$wrapper.length) {
45884591
return;
45894592
}
45904593

4591-
if (!nextTarget) {
4592-
window.setTimeout(function() {
4593-
if (!$openWrapper || !$openWrapper.length) {
4594-
return;
4595-
}
4596-
4597-
if (isElementAssociatedWithWrapper(document.activeElement, $openWrapper)) {
4594+
window.setTimeout(function() {
4595+
var activeElement = document.activeElement || null;
4596+
if (activeElement) {
4597+
var $active = $(activeElement);
4598+
if ($active.closest('.blc-field-help-wrapper').get(0) === $wrapper.get(0)) {
45984599
return;
45994600
}
4601+
}
46004602

4601-
closeWrapper($openWrapper);
4602-
}, 0);
4603-
return;
4604-
}
4605-
4606-
closeWrapper($openWrapper);
4603+
closeWrapper($wrapper);
4604+
}, 0);
46074605
});
46084606

46094607
$(document).on('focusin', function(event) {

liens-morts-detector-jlg/includes/blc-settings-fields.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,36 @@ function blc_render_field_help($field_id, $tooltip, $field_label = '') {
4343
? sprintf(__('Aide : %s', 'liens-morts-detector-jlg'), $field_label)
4444
: __('Afficher l’aide', 'liens-morts-detector-jlg');
4545

46-
echo '<span class="blc-field-help-wrapper">';
47-
echo '<button type="button" class="blc-field-help" aria-label="' . esc_attr($button_label) . '" aria-expanded="false" aria-controls="' . esc_attr($tooltip_id) . '">';
46+
$wrapper_attributes = array('class="blc-field-help-wrapper"');
47+
48+
if ($field_id !== '') {
49+
$wrapper_attributes[] = 'data-field-id="' . esc_attr($field_id) . '"';
50+
}
51+
52+
echo '<span ' . implode(' ', $wrapper_attributes) . '>';
53+
54+
$button_attributes = array(
55+
'type="button"',
56+
'class="blc-field-help"',
57+
'aria-label="' . esc_attr($button_label) . '"',
58+
'aria-expanded="false"',
59+
'aria-controls="' . esc_attr($tooltip_id) . '"',
60+
'aria-describedby="' . esc_attr($tooltip_id) . '"'
61+
);
62+
63+
echo '<button ' . implode(' ', $button_attributes) . '>';
4864
echo '<span class="dashicons dashicons-editor-help" aria-hidden="true"></span>';
4965
echo '</button>';
50-
echo '<span id="' . esc_attr($tooltip_id) . '" class="blc-field-help__bubble" role="tooltip">' . esc_html($tooltip) . '</span>';
66+
$bubble_attributes = array(
67+
'id="' . esc_attr($tooltip_id) . '"',
68+
'class="blc-field-help__bubble"',
69+
'role="tooltip"',
70+
'hidden',
71+
'aria-hidden="true"',
72+
'aria-live="polite"'
73+
);
74+
75+
echo '<span ' . implode(' ', $bubble_attributes) . '>' . esc_html($tooltip) . '</span>';
5176
echo '</span>';
5277
}
5378

0 commit comments

Comments
 (0)