Skip to content

Commit ef7bf11

Browse files
committed
moved legend inside switch statement
1 parent 524b23a commit ef7bf11

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

a11y-add-on-for-facetwp.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ 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 = '<fieldset>';
74+
$output = sprintf('<fieldset><legend>%1$s</legend>',
75+
$params['facet']['label'] );
7576
foreach( $params['values'] as $value ) {
7677
if( $value['counter'] > 0 || ! $params['facet']['preserve_ghosts'] === 'no' ) {
7778
$output .= sprintf(
@@ -117,18 +118,19 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
117118
$output = str_replace('class=', $id_string, $output);
118119

119120
case 'radio':
120-
$output = '<fieldset><div class="facetwp-facet facet-wrap facetwp-type-radio" role="radiogroup" id="'.esc_attr( $params['facet']['name'] ).'">';
121+
$output = sprintf('<fieldset><legend>%1$s</legend>',
122+
$params['facet']['label'] );
121123
foreach( $params['values'] as $value ) {
122124
$output .= sprintf(
123-
'<input type="radio" id="%1$s" name="%3$s" value="%2$s">
124-
<label for="%1$s">%2$s</label><br/>',
125+
'<div><input type="radio" id="%1$s" name="%3$s" value="%2$s">
126+
<label for="%1$s">%2$s</label></div>',
125127
esc_attr( 'radio-'.$value['facet_value'] ),
126128
esc_html( $value['facet_display_value'] ),
127129
esc_attr( $params['facet']['name'] )
128130
);
129131
}
130132

131-
$output .= '</div></fieldset>';
133+
$output .= '</fieldset>';
132134
break;
133135

134136
default:
@@ -215,8 +217,10 @@ function remove_underscores( name ) {
215217
var facet_type = $facet.attr('data-type');
216218

217219
if ( facet_name && facet_type ) {
218-
// Don't label the pagination or reset
219-
if ( facet_name.match(/pagination/g) ||
220+
// Don't label the pagination or reset XXX clean this up
221+
if ( facet_type.match(/checkboxes/g) ||
222+
facet_type.match(/radio/g)
223+
facet_name.match(/pagination/g) ||
220224
facet_name.match(/reset/g) ||
221225
facet_name.match(/results_count/g) ) {
222226
return;
@@ -226,14 +230,12 @@ function remove_underscores( name ) {
226230

227231
if ($facet.closest('.facet-wrap').length < 1 && $facet.closest('.facetwp-flyout').length < 1) {
228232

229-
$facet.wrap(`<div class="facet-wrap facet-wrap-${facet_name}"></div>`);
233+
//wrapper div
234+
$facet.wrap(`<div class="facet-wrap facet-wrap-${facet_name}"></div>`);
230235

231-
if ( facet_type.match(/checkboxes/g) || facet_type.match(/radio/g) ){
232-
// Checkboxes & radio buttons don't need a <label> element, facetWP adds aria-label to them.
233-
$facet.before('<legend class="facet-label">' + facet_label + '</legend>');
234-
} else {
236+
//label
235237
$facet.before('<label class="facet-label" for="'+facet_name.replace(/\s/g, '')+'">' + facet_label + '</label>');
236-
}
238+
237239
}
238240
}
239241
});

0 commit comments

Comments
 (0)