Skip to content

Commit 4d08be4

Browse files
committed
Merge branch 'radiobuttons'
2 parents feb466a + d950a13 commit 4d08be4

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ A11y Add-on for FacetWP adds accessibility enhancements for FacetWP's form eleme
99
FacetWP must be installed and activated.
1010

1111
- Wraps all facets in a div with class=facet-wrap
12-
- Adds a label to each facet with text=facet_label, for=facet_name
12+
- Adds a label to some facets with text=facet_label, for=facet_name
13+
- Adds fieldset and legend to checkboxes and radio buttons
1314
- Adds an id to each facet with id=facet_name
1415
- FacetWP default checkbox markup replaced with semantic HTML checkboxes
15-
- Search field uses <search> landmark and real <button>
16+
- Search field uses <search> landmark, icon is removed
1617
- Always hides counts in dropdowns
1718
- Disables auto-refresh
1819
- Customizes icon for prev/next pagination links
1920
- Scroll back to top of results when pager is clicked
2021

22+
## Search button
23+
We add the Submit button as a Custom HTML block:
24+
````
25+
<button id="search" onclick="FWP.refresh()" class="facetsubmit" type="submit">Filter</button>
26+
```
27+
2128
Semantic HTML checkboxes courtesy of Mark Root-Wiley, [MRW Web Design](https://mrwweb.com/) [Accessibility Addon for FacetWP](https://github.com/mrwweb/accessibility-addon-for-facetwp)

a11y-add-on-for-facetwp.php

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ 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 = sprintf('<fieldset><legend>%1$s</legend>',
75+
$params['facet']['label'] );
7676
foreach( $params['values'] as $value ) {
7777
if( $value['counter'] > 0 || ! $params['facet']['preserve_ghosts'] === 'no' ) {
7878
$output .= sprintf(
79-
'<li>
79+
'<div>
8080
<input type="checkbox" id="%3$s"%1$s value="%2$s" class="facetwp-checkbox%1$s" data-value="%2$s">
8181
<label for="%3$s">
8282
<span class="facetwp-display-value">%4$s</span>
8383
<span class="facetwp-counter">(%5$d)</span>
8484
</label>
85-
</li>',
85+
</div>',
8686
in_array( $value['facet_value'], $params['selected_values'] ) ? ' checked' : '',
8787
esc_attr( $value['facet_value'] ),
8888
'checkbox-' . esc_attr( $value['term_id'] ),
@@ -91,7 +91,7 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
9191
);
9292
}
9393
}
94-
$output .= '</ul>';
94+
$output .= '</fieldset>';
9595
break;
9696

9797
case 'search':
@@ -103,8 +103,7 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
103103
$id = $params['facet']['name'];
104104
$output = str_replace(
105105
'<input', '<div class="trec-facetwp-search-wrapper"><input id="' . esc_attr( $id ) . '"', $output );
106-
// facetwp-icon class is important to retain event handling
107-
$output = str_replace( '</span>', '<button class="facetwp-icon"><span class="ally-addon-search-submit-text">Submit</span></button></div></span>', $output );
106+
108107
// placeholders are bad for UX
109108
$output = str_replace( 'placeholder="Enter keywords"', '', $output );
110109
break;
@@ -117,25 +116,36 @@ function a11y_addon_transform_facet_markup( $output, $params ) {
117116

118117
$output = str_replace('class=', $id_string, $output);
119118

119+
break;
120+
121+
case 'radio':
122+
$output = sprintf('<fieldset><legend>%1$s</legend>',
123+
$params['facet']['label'] );
124+
foreach( $params['values'] as $value ) {
125+
$output .= sprintf(
126+
'<div><input type="radio" id="%1$s" name="%3$s" value="%2$s">
127+
<label for="%1$s">%2$s</label></div>',
128+
esc_attr( 'radio-'.$value['facet_value'] ),
129+
esc_html( $value['facet_display_value'] ),
130+
esc_attr( $params['facet']['name'] )
131+
);
132+
}
133+
134+
$output .= '</fieldset>';
135+
break;
136+
137+
case 'reset':
138+
139+
$output = str_replace('button','button type="reset"',$output);
140+
141+
break;
142+
120143
default:
121144

122145
$id_string = 'id="'.$params['facet']['name'].'" class=';
123146

124147
$output = str_replace('class=', $id_string, $output);
125148

126-
/*
127-
//do we want this?
128-
case 'pager':
129-
// put links in a list with nav element
130-
$output = str_replace( '<div', '<nav aria-labelledby="resource-paging-heading"><h3 class="screen-reader-text" id="resource-paging-heading">' . esc_html__( 'Results Pages', 'afwp' ) . '</h3><ul', $output );
131-
$output = str_replace( '</div>', '</ul></nav>', $output );
132-
$output = str_replace( '<a', '<li><a', $output );
133-
$output = str_replace( '</a>', '</a></li>', $output );
134-
// add tabindex to valid links only for keyboard accessibility
135-
$output = str_replace( 'data-page', 'tabindex="0" data-page', $output );
136-
break;
137-
*/
138-
139149
}
140150

141151
return $output;
@@ -201,24 +211,21 @@ function remove_underscores( name ) {
201211
var facet_type = $facet.attr('data-type');
202212

203213
if ( facet_name && facet_type ) {
204-
// Don't label the pagination or reset
205-
if ( facet_name.match(/pagination/g) ||
206-
facet_name.match(/reset/g) ||
207-
facet_name.match(/results_count/g) ) {
214+
// Don't label some facets
215+
if ( facet_type.match(/checkboxes|radio|pagination|reset|results_count/g) ) {
208216
return;
209217
}
210218

211219
var facet_label = FWP.settings.labels[facet_name];
212220

213221
if ($facet.closest('.facet-wrap').length < 1 && $facet.closest('.facetwp-flyout').length < 1) {
214-
$facet.wrap(`<div class="facet-wrap facet-wrap-${facet_name}"></div>`);
215222

216-
if ( facet_type.match(/checkboxes/g) || facet_type.match(/radio/g) ){
217-
// Checkboxes & radio buttons don't need a <label> element, facetWP adds aria-label to them.
218-
$facet.before('<div class="facet-label" aria-hidden="true">' + facet_label + '</div>');
219-
} else {
223+
//wrapper div
224+
$facet.wrap(`<div class="facet-wrap facet-wrap-${facet_name}"></div>`);
225+
226+
//label
220227
$facet.before('<label class="facet-label" for="'+facet_name.replace(/\s/g, '')+'">' + facet_label + '</label>');
221-
}
228+
222229
}
223230
}
224231
});

readme.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ A11y Add-on for FacetWP adds accessibility enhancements for FacetWP's form eleme
1717
FacetWP must be installed and activated.
1818

1919
- Wraps all facets in a div with class=facet-wrap
20-
- Adds a label to each facet with text=facet_label, for=facet_name
20+
- Adds a label to some facets with text=facet_label, for=facet_name
21+
- Adds fieldset and legend to checkboxes and radio buttons
2122
- Adds an id to each facet with id=facet_name
2223
- FacetWP default checkbox markup replaced with semantic HTML checkboxes
23-
- Search field uses &lt;search&gt; landmark and real &lt;button&gt;
24+
- Search field uses &lt;search&gt; landmark, icon is removed
2425
- Always hides counts in dropdowns
2526
- Disables auto-refresh
2627
- Customizes icon for prev/next pagination links
2728
- Scroll back to top of results when pager is clicked
2829

30+
31+
We add the Submit button as a Custom HTML block:
32+
<button id="search" onclick="FWP.refresh()" class="facetsubmit" type="submit">Filter</button>
33+
34+
2935
Semantic HTML checkboxes courtesy of Mark Root-Wiley, [MRW Web Design](https://mrwweb.com/) [Accessibility Addon for FacetWP](https://github.com/mrwweb/accessibility-addon-for-facetwp)
3036

3137
=== Changelog ===

0 commit comments

Comments
 (0)