Keyboard a11y for a multi-level navigation menu with buttons as top level items












0















I have a <nav> element with 2 levels. The top-level items are marked up with <button> tags and the child items with <a> tags, such as:



<nav role="navigation">
<ul>
<li>
<button type="button">Category 1</button>

<ul class="submenu">
<li>
<a href="/cat1/subcat1">Subcategory 1</a>
</li>
<!-- ... other links -->
</ul> <!-- /.submenu -->
</li>
<li>
<button type="button">Category 2</button>

<ul class="submenu">
<li>
<a href="/cat2/subcat1">Subcategory 1</a>
</li>
<!-- ... other links -->
</ul> <!-- /.submenu -->
</li>
</ul>
</nav>


The top-level items are intended to act as containers only and do not have pages of their own to link to.



How should I add keyboard accessibility to this markup?



Options I've thought about at the moment are:



Option 1



Open the menu when top-level items (<button> tags) are focused.

Keep the menu open as the user tabs through the child items.

Close the menu when the focus moves to another top-level item or the rest of the page.

Also, allow closing the menu via the Escape key and transfer focus.



Option 2



Use the focus semantics that a role="menu" would get, namely:

Enter, Space or Down arrow on the top-level item open the menu;

Down arrow on a child item moves focus to the next item;

Up arrow on a child item moves focus to the previous item;

Up arrow on the top-level item closes the menu, and;

Escape key while on a child item, closes the menu and transfers focus to the top-level item.



This would allow the Tab key to be reserved for moving to the next top-level item.



Personally, I prefer Option 2, but I do wonder if it blurs the lines between what's expected and what's shown.










share|improve this question



























    0















    I have a <nav> element with 2 levels. The top-level items are marked up with <button> tags and the child items with <a> tags, such as:



    <nav role="navigation">
    <ul>
    <li>
    <button type="button">Category 1</button>

    <ul class="submenu">
    <li>
    <a href="/cat1/subcat1">Subcategory 1</a>
    </li>
    <!-- ... other links -->
    </ul> <!-- /.submenu -->
    </li>
    <li>
    <button type="button">Category 2</button>

    <ul class="submenu">
    <li>
    <a href="/cat2/subcat1">Subcategory 1</a>
    </li>
    <!-- ... other links -->
    </ul> <!-- /.submenu -->
    </li>
    </ul>
    </nav>


    The top-level items are intended to act as containers only and do not have pages of their own to link to.



    How should I add keyboard accessibility to this markup?



    Options I've thought about at the moment are:



    Option 1



    Open the menu when top-level items (<button> tags) are focused.

    Keep the menu open as the user tabs through the child items.

    Close the menu when the focus moves to another top-level item or the rest of the page.

    Also, allow closing the menu via the Escape key and transfer focus.



    Option 2



    Use the focus semantics that a role="menu" would get, namely:

    Enter, Space or Down arrow on the top-level item open the menu;

    Down arrow on a child item moves focus to the next item;

    Up arrow on a child item moves focus to the previous item;

    Up arrow on the top-level item closes the menu, and;

    Escape key while on a child item, closes the menu and transfers focus to the top-level item.



    This would allow the Tab key to be reserved for moving to the next top-level item.



    Personally, I prefer Option 2, but I do wonder if it blurs the lines between what's expected and what's shown.










    share|improve this question

























      0












      0








      0








      I have a <nav> element with 2 levels. The top-level items are marked up with <button> tags and the child items with <a> tags, such as:



      <nav role="navigation">
      <ul>
      <li>
      <button type="button">Category 1</button>

      <ul class="submenu">
      <li>
      <a href="/cat1/subcat1">Subcategory 1</a>
      </li>
      <!-- ... other links -->
      </ul> <!-- /.submenu -->
      </li>
      <li>
      <button type="button">Category 2</button>

      <ul class="submenu">
      <li>
      <a href="/cat2/subcat1">Subcategory 1</a>
      </li>
      <!-- ... other links -->
      </ul> <!-- /.submenu -->
      </li>
      </ul>
      </nav>


      The top-level items are intended to act as containers only and do not have pages of their own to link to.



      How should I add keyboard accessibility to this markup?



      Options I've thought about at the moment are:



      Option 1



      Open the menu when top-level items (<button> tags) are focused.

      Keep the menu open as the user tabs through the child items.

      Close the menu when the focus moves to another top-level item or the rest of the page.

      Also, allow closing the menu via the Escape key and transfer focus.



      Option 2



      Use the focus semantics that a role="menu" would get, namely:

      Enter, Space or Down arrow on the top-level item open the menu;

      Down arrow on a child item moves focus to the next item;

      Up arrow on a child item moves focus to the previous item;

      Up arrow on the top-level item closes the menu, and;

      Escape key while on a child item, closes the menu and transfers focus to the top-level item.



      This would allow the Tab key to be reserved for moving to the next top-level item.



      Personally, I prefer Option 2, but I do wonder if it blurs the lines between what's expected and what's shown.










      share|improve this question














      I have a <nav> element with 2 levels. The top-level items are marked up with <button> tags and the child items with <a> tags, such as:



      <nav role="navigation">
      <ul>
      <li>
      <button type="button">Category 1</button>

      <ul class="submenu">
      <li>
      <a href="/cat1/subcat1">Subcategory 1</a>
      </li>
      <!-- ... other links -->
      </ul> <!-- /.submenu -->
      </li>
      <li>
      <button type="button">Category 2</button>

      <ul class="submenu">
      <li>
      <a href="/cat2/subcat1">Subcategory 1</a>
      </li>
      <!-- ... other links -->
      </ul> <!-- /.submenu -->
      </li>
      </ul>
      </nav>


      The top-level items are intended to act as containers only and do not have pages of their own to link to.



      How should I add keyboard accessibility to this markup?



      Options I've thought about at the moment are:



      Option 1



      Open the menu when top-level items (<button> tags) are focused.

      Keep the menu open as the user tabs through the child items.

      Close the menu when the focus moves to another top-level item or the rest of the page.

      Also, allow closing the menu via the Escape key and transfer focus.



      Option 2



      Use the focus semantics that a role="menu" would get, namely:

      Enter, Space or Down arrow on the top-level item open the menu;

      Down arrow on a child item moves focus to the next item;

      Up arrow on a child item moves focus to the previous item;

      Up arrow on the top-level item closes the menu, and;

      Escape key while on a child item, closes the menu and transfers focus to the top-level item.



      This would allow the Tab key to be reserved for moving to the next top-level item.



      Personally, I prefer Option 2, but I do wonder if it blurs the lines between what's expected and what's shown.







      javascript html accessibility






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 11:32









      Adam TaylorAdam Taylor

      305




      305
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Option 2 initially feels like the right keyboard semantics but that behavior should be reserved for "true" menus in the classic sense of the word. That is, menus such as "File, Edit, View..." that have immediate actions listed under them (such as File > Open or Edit > Preferences). Option 2 also means that your menu would have to be one tab stop and the user would use left/right arrows to move from "Category 1" to "Category 2". I don't think you want that.



          For navigation "menus", they're not really menus in the classic sense. They're just a grouped list of links to navigate to other pages.



          There's an excellent tutorial on menus on W3C - https://www.w3.org/WAI/tutorials/menus/. (There's a section on "application menus" in that tutorial that talk about the "classic" menus such as "file, edit, view", as mentioned above.)



          I almost always recommend using buttons for immediate action things and links for navigating to another page, but with navigation menus, links are often used even if they only control the dropdown list of further menu items (which is usually a button's job). Whether you use buttons or links for your top level items is up to you. Personally, I would use links so that all the elements in the <nav> are links, but that's just personal preference.



          In any event, whether you use a button or a link for the top level items, the element should have aria-expanded set to "false" initially. When the user selects the top level link, change aria-expanded to "true".



          Here's the keyboard behavior I would expect:




          • I should be able to tab across the top level items. Tab from "Category 1" to "Category 2". (The visual appearance of the top level items should have a "down triangle" or some icon that indicates there is something in that menu.) Do not open the submenu when a top level item receives focus. That makes it very difficult for keyboard users to get to the last top level item because they'd have to navigate through every submenu.

          • As I tab across the top level items, I should be able to hit enter to expand the dropdown menu. The focus should not be moved to the first submenu item. It should remain on the top level item. Pressing tab should take me to the first submenu item. (If your DOM has the submenu items immediately after the top level items, you will get this tabbing behavior "for free". Your sample code is a good example.) I can then tab through all the submenu items.

          • If I press esc while tabbing through the submenu, the submenu should dismiss and the focus should be moved to the top level item that opened the submenu (and aria-expanded should be set to "false" for the top level item).

          • If I tab off the last submenu item, the submenu should close and the focus should go to the next top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).

          • If I shift+tab off the first submenu item, the focus should naturally go to the top level item that opened the submenu. The submenu should still remain visible. If I shift+tab again, then the submenu should close and the focus should go to the previous top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).


          It sounds a little complicated at first but is actually quite simple and elegant. The nice thing is that most of the tabbing behavior you'll get for free. You just have to implement enter to open the submenu, esc to close the submenu, and some onblur() handlers to close the submenus.



          As a side note, you don't have to specify a role for native html elements that already have a default role assigned. For example



          <nav role="navigation">


          should just be



          <nav>


          and



          <button type="button">Category 1</button>


          should just be



          <button>Category 1</button>


          The html5 spec for <nav> and <button> shows you the default role and specifically says




          (default - _do not set_)




          (Also, your <nav> should also have an aria-label or aria-labelledby. This is mentioned in the "Label menus" section of the tutorial mentioned above.)






          share|improve this answer
























          • Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

            – Adam Taylor
            Jan 4 at 16:09











          • Ah, apologies. I misread that. The <nav> comment still applies :-)

            – slugolicious
            Jan 5 at 7:24













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021459%2fkeyboard-a11y-for-a-multi-level-navigation-menu-with-buttons-as-top-level-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Option 2 initially feels like the right keyboard semantics but that behavior should be reserved for "true" menus in the classic sense of the word. That is, menus such as "File, Edit, View..." that have immediate actions listed under them (such as File > Open or Edit > Preferences). Option 2 also means that your menu would have to be one tab stop and the user would use left/right arrows to move from "Category 1" to "Category 2". I don't think you want that.



          For navigation "menus", they're not really menus in the classic sense. They're just a grouped list of links to navigate to other pages.



          There's an excellent tutorial on menus on W3C - https://www.w3.org/WAI/tutorials/menus/. (There's a section on "application menus" in that tutorial that talk about the "classic" menus such as "file, edit, view", as mentioned above.)



          I almost always recommend using buttons for immediate action things and links for navigating to another page, but with navigation menus, links are often used even if they only control the dropdown list of further menu items (which is usually a button's job). Whether you use buttons or links for your top level items is up to you. Personally, I would use links so that all the elements in the <nav> are links, but that's just personal preference.



          In any event, whether you use a button or a link for the top level items, the element should have aria-expanded set to "false" initially. When the user selects the top level link, change aria-expanded to "true".



          Here's the keyboard behavior I would expect:




          • I should be able to tab across the top level items. Tab from "Category 1" to "Category 2". (The visual appearance of the top level items should have a "down triangle" or some icon that indicates there is something in that menu.) Do not open the submenu when a top level item receives focus. That makes it very difficult for keyboard users to get to the last top level item because they'd have to navigate through every submenu.

          • As I tab across the top level items, I should be able to hit enter to expand the dropdown menu. The focus should not be moved to the first submenu item. It should remain on the top level item. Pressing tab should take me to the first submenu item. (If your DOM has the submenu items immediately after the top level items, you will get this tabbing behavior "for free". Your sample code is a good example.) I can then tab through all the submenu items.

          • If I press esc while tabbing through the submenu, the submenu should dismiss and the focus should be moved to the top level item that opened the submenu (and aria-expanded should be set to "false" for the top level item).

          • If I tab off the last submenu item, the submenu should close and the focus should go to the next top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).

          • If I shift+tab off the first submenu item, the focus should naturally go to the top level item that opened the submenu. The submenu should still remain visible. If I shift+tab again, then the submenu should close and the focus should go to the previous top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).


          It sounds a little complicated at first but is actually quite simple and elegant. The nice thing is that most of the tabbing behavior you'll get for free. You just have to implement enter to open the submenu, esc to close the submenu, and some onblur() handlers to close the submenus.



          As a side note, you don't have to specify a role for native html elements that already have a default role assigned. For example



          <nav role="navigation">


          should just be



          <nav>


          and



          <button type="button">Category 1</button>


          should just be



          <button>Category 1</button>


          The html5 spec for <nav> and <button> shows you the default role and specifically says




          (default - _do not set_)




          (Also, your <nav> should also have an aria-label or aria-labelledby. This is mentioned in the "Label menus" section of the tutorial mentioned above.)






          share|improve this answer
























          • Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

            – Adam Taylor
            Jan 4 at 16:09











          • Ah, apologies. I misread that. The <nav> comment still applies :-)

            – slugolicious
            Jan 5 at 7:24


















          1














          Option 2 initially feels like the right keyboard semantics but that behavior should be reserved for "true" menus in the classic sense of the word. That is, menus such as "File, Edit, View..." that have immediate actions listed under them (such as File > Open or Edit > Preferences). Option 2 also means that your menu would have to be one tab stop and the user would use left/right arrows to move from "Category 1" to "Category 2". I don't think you want that.



          For navigation "menus", they're not really menus in the classic sense. They're just a grouped list of links to navigate to other pages.



          There's an excellent tutorial on menus on W3C - https://www.w3.org/WAI/tutorials/menus/. (There's a section on "application menus" in that tutorial that talk about the "classic" menus such as "file, edit, view", as mentioned above.)



          I almost always recommend using buttons for immediate action things and links for navigating to another page, but with navigation menus, links are often used even if they only control the dropdown list of further menu items (which is usually a button's job). Whether you use buttons or links for your top level items is up to you. Personally, I would use links so that all the elements in the <nav> are links, but that's just personal preference.



          In any event, whether you use a button or a link for the top level items, the element should have aria-expanded set to "false" initially. When the user selects the top level link, change aria-expanded to "true".



          Here's the keyboard behavior I would expect:




          • I should be able to tab across the top level items. Tab from "Category 1" to "Category 2". (The visual appearance of the top level items should have a "down triangle" or some icon that indicates there is something in that menu.) Do not open the submenu when a top level item receives focus. That makes it very difficult for keyboard users to get to the last top level item because they'd have to navigate through every submenu.

          • As I tab across the top level items, I should be able to hit enter to expand the dropdown menu. The focus should not be moved to the first submenu item. It should remain on the top level item. Pressing tab should take me to the first submenu item. (If your DOM has the submenu items immediately after the top level items, you will get this tabbing behavior "for free". Your sample code is a good example.) I can then tab through all the submenu items.

          • If I press esc while tabbing through the submenu, the submenu should dismiss and the focus should be moved to the top level item that opened the submenu (and aria-expanded should be set to "false" for the top level item).

          • If I tab off the last submenu item, the submenu should close and the focus should go to the next top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).

          • If I shift+tab off the first submenu item, the focus should naturally go to the top level item that opened the submenu. The submenu should still remain visible. If I shift+tab again, then the submenu should close and the focus should go to the previous top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).


          It sounds a little complicated at first but is actually quite simple and elegant. The nice thing is that most of the tabbing behavior you'll get for free. You just have to implement enter to open the submenu, esc to close the submenu, and some onblur() handlers to close the submenus.



          As a side note, you don't have to specify a role for native html elements that already have a default role assigned. For example



          <nav role="navigation">


          should just be



          <nav>


          and



          <button type="button">Category 1</button>


          should just be



          <button>Category 1</button>


          The html5 spec for <nav> and <button> shows you the default role and specifically says




          (default - _do not set_)




          (Also, your <nav> should also have an aria-label or aria-labelledby. This is mentioned in the "Label menus" section of the tutorial mentioned above.)






          share|improve this answer
























          • Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

            – Adam Taylor
            Jan 4 at 16:09











          • Ah, apologies. I misread that. The <nav> comment still applies :-)

            – slugolicious
            Jan 5 at 7:24
















          1












          1








          1







          Option 2 initially feels like the right keyboard semantics but that behavior should be reserved for "true" menus in the classic sense of the word. That is, menus such as "File, Edit, View..." that have immediate actions listed under them (such as File > Open or Edit > Preferences). Option 2 also means that your menu would have to be one tab stop and the user would use left/right arrows to move from "Category 1" to "Category 2". I don't think you want that.



          For navigation "menus", they're not really menus in the classic sense. They're just a grouped list of links to navigate to other pages.



          There's an excellent tutorial on menus on W3C - https://www.w3.org/WAI/tutorials/menus/. (There's a section on "application menus" in that tutorial that talk about the "classic" menus such as "file, edit, view", as mentioned above.)



          I almost always recommend using buttons for immediate action things and links for navigating to another page, but with navigation menus, links are often used even if they only control the dropdown list of further menu items (which is usually a button's job). Whether you use buttons or links for your top level items is up to you. Personally, I would use links so that all the elements in the <nav> are links, but that's just personal preference.



          In any event, whether you use a button or a link for the top level items, the element should have aria-expanded set to "false" initially. When the user selects the top level link, change aria-expanded to "true".



          Here's the keyboard behavior I would expect:




          • I should be able to tab across the top level items. Tab from "Category 1" to "Category 2". (The visual appearance of the top level items should have a "down triangle" or some icon that indicates there is something in that menu.) Do not open the submenu when a top level item receives focus. That makes it very difficult for keyboard users to get to the last top level item because they'd have to navigate through every submenu.

          • As I tab across the top level items, I should be able to hit enter to expand the dropdown menu. The focus should not be moved to the first submenu item. It should remain on the top level item. Pressing tab should take me to the first submenu item. (If your DOM has the submenu items immediately after the top level items, you will get this tabbing behavior "for free". Your sample code is a good example.) I can then tab through all the submenu items.

          • If I press esc while tabbing through the submenu, the submenu should dismiss and the focus should be moved to the top level item that opened the submenu (and aria-expanded should be set to "false" for the top level item).

          • If I tab off the last submenu item, the submenu should close and the focus should go to the next top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).

          • If I shift+tab off the first submenu item, the focus should naturally go to the top level item that opened the submenu. The submenu should still remain visible. If I shift+tab again, then the submenu should close and the focus should go to the previous top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).


          It sounds a little complicated at first but is actually quite simple and elegant. The nice thing is that most of the tabbing behavior you'll get for free. You just have to implement enter to open the submenu, esc to close the submenu, and some onblur() handlers to close the submenus.



          As a side note, you don't have to specify a role for native html elements that already have a default role assigned. For example



          <nav role="navigation">


          should just be



          <nav>


          and



          <button type="button">Category 1</button>


          should just be



          <button>Category 1</button>


          The html5 spec for <nav> and <button> shows you the default role and specifically says




          (default - _do not set_)




          (Also, your <nav> should also have an aria-label or aria-labelledby. This is mentioned in the "Label menus" section of the tutorial mentioned above.)






          share|improve this answer













          Option 2 initially feels like the right keyboard semantics but that behavior should be reserved for "true" menus in the classic sense of the word. That is, menus such as "File, Edit, View..." that have immediate actions listed under them (such as File > Open or Edit > Preferences). Option 2 also means that your menu would have to be one tab stop and the user would use left/right arrows to move from "Category 1" to "Category 2". I don't think you want that.



          For navigation "menus", they're not really menus in the classic sense. They're just a grouped list of links to navigate to other pages.



          There's an excellent tutorial on menus on W3C - https://www.w3.org/WAI/tutorials/menus/. (There's a section on "application menus" in that tutorial that talk about the "classic" menus such as "file, edit, view", as mentioned above.)



          I almost always recommend using buttons for immediate action things and links for navigating to another page, but with navigation menus, links are often used even if they only control the dropdown list of further menu items (which is usually a button's job). Whether you use buttons or links for your top level items is up to you. Personally, I would use links so that all the elements in the <nav> are links, but that's just personal preference.



          In any event, whether you use a button or a link for the top level items, the element should have aria-expanded set to "false" initially. When the user selects the top level link, change aria-expanded to "true".



          Here's the keyboard behavior I would expect:




          • I should be able to tab across the top level items. Tab from "Category 1" to "Category 2". (The visual appearance of the top level items should have a "down triangle" or some icon that indicates there is something in that menu.) Do not open the submenu when a top level item receives focus. That makes it very difficult for keyboard users to get to the last top level item because they'd have to navigate through every submenu.

          • As I tab across the top level items, I should be able to hit enter to expand the dropdown menu. The focus should not be moved to the first submenu item. It should remain on the top level item. Pressing tab should take me to the first submenu item. (If your DOM has the submenu items immediately after the top level items, you will get this tabbing behavior "for free". Your sample code is a good example.) I can then tab through all the submenu items.

          • If I press esc while tabbing through the submenu, the submenu should dismiss and the focus should be moved to the top level item that opened the submenu (and aria-expanded should be set to "false" for the top level item).

          • If I tab off the last submenu item, the submenu should close and the focus should go to the next top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).

          • If I shift+tab off the first submenu item, the focus should naturally go to the top level item that opened the submenu. The submenu should still remain visible. If I shift+tab again, then the submenu should close and the focus should go to the previous top level item (and aria-expanded should be set to "false" for the top level item that opened the submenu).


          It sounds a little complicated at first but is actually quite simple and elegant. The nice thing is that most of the tabbing behavior you'll get for free. You just have to implement enter to open the submenu, esc to close the submenu, and some onblur() handlers to close the submenus.



          As a side note, you don't have to specify a role for native html elements that already have a default role assigned. For example



          <nav role="navigation">


          should just be



          <nav>


          and



          <button type="button">Category 1</button>


          should just be



          <button>Category 1</button>


          The html5 spec for <nav> and <button> shows you the default role and specifically says




          (default - _do not set_)




          (Also, your <nav> should also have an aria-label or aria-labelledby. This is mentioned in the "Label menus" section of the tutorial mentioned above.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 18:20









          slugoliciousslugolicious

          5,96611422




          5,96611422













          • Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

            – Adam Taylor
            Jan 4 at 16:09











          • Ah, apologies. I misread that. The <nav> comment still applies :-)

            – slugolicious
            Jan 5 at 7:24





















          • Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

            – Adam Taylor
            Jan 4 at 16:09











          • Ah, apologies. I misread that. The <nav> comment still applies :-)

            – slugolicious
            Jan 5 at 7:24



















          Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

          – Adam Taylor
          Jan 4 at 16:09





          Thanks for the very detailed answer! Regarding your note about the <button type="button"> I'm setting the type not the role attribute, as the default type for buttons is submit and I want to make it explicit that this is a user-defined button.

          – Adam Taylor
          Jan 4 at 16:09













          Ah, apologies. I misread that. The <nav> comment still applies :-)

          – slugolicious
          Jan 5 at 7:24







          Ah, apologies. I misread that. The <nav> comment still applies :-)

          – slugolicious
          Jan 5 at 7:24






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021459%2fkeyboard-a11y-for-a-multi-level-navigation-menu-with-buttons-as-top-level-items%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas