fix(nav-accessibility): add aria and role attributes
Enhanced dropdown accessibility by adding `aria-labelledby` to the dropdown menu and `role="button"` to toggler links. This conforms to ARIA standards and Bootstrap 5, ensuring better support for assistive technologies.
This commit is contained in:
parent
72b54fa59e
commit
6f3351c7c4
1 changed files with 2 additions and 2 deletions
|
@ -12,7 +12,7 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu
|
||||||
function start_lvl(&$output, $depth = 0, $args = array())
|
function start_lvl(&$output, $depth = 0, $args = array())
|
||||||
{
|
{
|
||||||
$indent = str_repeat("\t", $depth);
|
$indent = str_repeat("\t", $depth);
|
||||||
$output .= "\n$indent<ul class=\"dropdown-menu\">\n";
|
$output .= "\n$indent<ul class=\"dropdown-menu\" aria-labelledby=\"navbarDropdown\">\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add main/sub classes to li's and links
|
// Add main/sub classes to li's and links
|
||||||
|
@ -44,7 +44,7 @@ class WP_Bootstrap_Navwalker extends Walker_Nav_Menu
|
||||||
$attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
|
$attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
|
||||||
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
|
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
|
||||||
|
|
||||||
$attributes .= (isset($args->walker) && $args->walker->has_children) ? ' class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"' : ' class="nav-link"';
|
$attributes .= (isset($args->walker) && $args->walker->has_children) ? ' class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"' : ' class="nav-link"';
|
||||||
|
|
||||||
$item_output = isset($args->before) ? $args->before : '';
|
$item_output = isset($args->before) ? $args->before : '';
|
||||||
$item_output .= '<a' . $attributes . '>';
|
$item_output .= '<a' . $attributes . '>';
|
||||||
|
|
Loading…
Reference in a new issue