Skip to content

Commit 524b23a

Browse files
committed
checkboxes and radio: fieldset and legend
1 parent 094cab6 commit 524b23a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

a11y-add-on-for-facetwp.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
7171

7272
case 'checkboxes':
7373
// Note: The trick to this working was moving the facetwp-checkbox class and data-value attribute to the `input`. Clicking the label works because the input element still emits a click event when the label is clicked. Leaving that class and attribute on the wrapping list item resulted in two events being fired when the label was clicked.
74-
$output = '';
75-
$output .= '<ul>';
74+
$output = '<fieldset>';
7675
foreach( $params['values'] as $value ) {
7776
if( $value['counter'] > 0 || ! $params['facet']['preserve_ghosts'] === 'no' ) {
7877
$output .= sprintf(
79-
'<li>
78+
'<div>
8079
<input type="checkbox" id="%3$s"%1$s value="%2$s" class="facetwp-checkbox%1$s" data-value="%2$s">
8180
<label for="%3$s">
8281
<span class="facetwp-display-value">%4$s</span>
8382
<span class="facetwp-counter">(%5$d)</span>
8483
</label>
85-
</li>',
84+
</div>',
8685
in_array( $value['facet_value'], $params['selected_values'] ) ? ' checked' : '',
8786
esc_attr( $value['facet_value'] ),
8887
'checkbox-' . esc_attr( $value['term_id'] ),
@@ -91,7 +90,7 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
9190
);
9291
}
9392
}
94-
$output .= '</ul>';
93+
$output .= '</fieldset>';
9594
break;
9695

9796
case 'search':
@@ -118,7 +117,7 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
118117
$output = str_replace('class=', $id_string, $output);
119118

120119
case 'radio':
121-
$output = '<div class="facetwp-facet facet-wrap facetwp-type-radio" role="radiogroup" id="'.esc_attr( $params['facet']['name'] ).'">';
120+
$output = '<fieldset><div class="facetwp-facet facet-wrap facetwp-type-radio" role="radiogroup" id="'.esc_attr( $params['facet']['name'] ).'">';
122121
foreach( $params['values'] as $value ) {
123122
$output .= sprintf(
124123
'<input type="radio" id="%1$s" name="%3$s" value="%2$s">
@@ -129,7 +128,7 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
129128
);
130129
}
131130

132-
$output .= '</div>';
131+
$output .= '</div></fieldset>';
133132
break;
134133

135134
default:
@@ -226,11 +225,12 @@ function remove_underscores( name ) {
226225
var facet_label = FWP.settings.labels[facet_name];
227226

228227
if ($facet.closest('.facet-wrap').length < 1 && $facet.closest('.facetwp-flyout').length < 1) {
228+
229229
$facet.wrap(`<div class="facet-wrap facet-wrap-${facet_name}"></div>`);
230230

231231
if ( facet_type.match(/checkboxes/g) || facet_type.match(/radio/g) ){
232232
// Checkboxes & radio buttons don't need a <label> element, facetWP adds aria-label to them.
233-
$facet.before('<div class="facet-label" aria-hidden="true">' + facet_label + '</div>');
233+
$facet.before('<legend class="facet-label">' + facet_label + '</legend>');
234234
} else {
235235
$facet.before('<label class="facet-label" for="'+facet_name.replace(/\s/g, '')+'">' + facet_label + '</label>');
236236
}

0 commit comments

Comments
 (0)