-1

I have a ChevronUp/down icon which serves as a button to open/close the menu.

enter image description here

I want to give keyboard focus to the icon for accessibility support. I tried to add it into "a" tag <a href="#"> <i></i> </a>

It gives focus but when it's clicked, the href="#" part will make the page refresh. I am wondering what's the best way to give keyboard focus for tag?

I tried "return false" for the <a> tag, but it also doesn't work as it will disable the all onclick events.

kevinzf
  • 163
  • 12

1 Answers1

2

Use a button element to trigger some on-page interactivity. A link is for navigation, either to another page or an in-page anchor. You can always use CSS to remove default browser styling for buttons if needed.

In the case of a button like this that's just an icon with no text, you need an aria-label that tells non-visual users what it is.

<button aria-label="Open menu"> <i></i> </button>

See as well the W3 Design Pattern for dropdown menus for more info. https://www.w3.org/WAI/ARIA/apg/example-index/disclosure/disclosure-navigation-hybrid.html

jwebb
  • 1,119
  • 12
  • 23