Hey there,
I’m attempting to fix some accessibility issues with Pro theme - unfortunately there’s a ton that I’m having to edit with javascript. But that’s the nature of the beast! So, I have a mobile menu button that when clicked opens content area off canvas. My goal is to put focus on the first menu item (I’m using a shortcode to populate this flyout with a widget area).
Here’s what I’m using to add focus:
var inputs = $('#flyout-menu-off-canvas').find('select, input, textarea, button, a').filter(':visible');
var firstInput = inputs.first();
var lastInput = inputs.last();
var firstMenu = inputs.eq(3);
// When flyout is open with enter key, place focus on first item
$('#flyout-menu-anchor-toggle').on('keypress', function(e){
var key = e.which || e.keyCode;
if ( key === 32 || key === 13 ) {
firstMenu.focus().addClass("focusedIn");
}
});
2 Issues:
- “enter” (key === 13) doesn’t trigger my keypress function (maybe it’s overwritten by Pro Theme?)
- I did the “addClass” to firstMenu because I wanted to see what was actually getting focus. The correct menu actually IS getting the class added to it, but focus is not applied to this element. When I hit “tab” at this point (after opening the menu), the close button is then selected. If after clicking the button to open it, I hit shift+tab, it goes to the very bottom of my site.
I already have javascript to “trap” screen readers in the flyout until they close it (surprised this isn’t built in) but I can’t apply focus to anything. I’m thinking Pro is taking over focus.
Any help would be greatly appreciated!
Matt




Got this fixed up and working!