Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aria attributes to improve facet accessibility. #2607

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions includes/classes/Feature/Facets/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,36 @@ protected function get_facet_term_html( $term, $url, $selected = false ) {
*/
$label = apply_filters( 'ep_facet_widget_term_label', $term->name, $term, $selected );

/**
* Filter the accessible label for an individual facet term link.
*
* Used as the aria-label attribute for filter links. The accessible
* label should include additional context around what action will be
* performed by visiting the link, such as whether the filter will be
* added or removed.
*
* @since 4.0.0
* @hook ep_facet_widget_term_accessible_label
* @param {string} $label Facet term accessible label.
* @param {WP_Term} $term Term object.
* @param {boolean} $selected Whether the term is selected.
* @return {string} Individual facet term accessible label.
*/
$accessible_label = apply_filters(
'ep_facet_widget_term_accessible_label',
$selected
/* translators: %s: Filter term name. */
? sprintf( __( 'Remove filter: %s', 'elasticpress' ), $term->name )
/* translators: %s: Filter term name. */
: sprintf( __( 'Apply filter: %s', 'elasticpress' ), $term->name ),
$term,
$selected
);

$link = sprintf(
'<a %1$s rel="nofollow"><div class="ep-checkbox %2$s" role="presentation"></div>%3$s</a>',
$term->count ? $href : '',
'<a aria-label="%1$s" %2$s rel="nofollow"><div class="ep-checkbox %3$s" role="presentation"></div>%4$s</a>',
esc_attr( $accessible_label ),
$term->count ? $href : 'aria-role="link" aria-disabled="true"',
$selected ? 'checked' : '',
wp_kses_post( $label )
);
Expand Down