ARIA for Elements Without Focus












0















I'm struggling to enable proper ARIA support for this case. I have a input field which works like a filter, and a set of elements which will be filtered by this input field. The focus is always on the input field, and with arrow up and down you can navigate through the result set. The input needs constant focus because whenever I start typing again, the input should be updated and filter the result set.



Now I want that my screen reader reads the name of the elements when I navigate through the result set. But if I press arrow down (or up) the reader repeats the full part of the input field.



Hint: The result set contains images and text and will open the element in a new view when it is clicked.



<input ng-change="$ctrl.doFilter()" ng-keydown="$ctrl.handleKeydown($event)">    

<div class="filter-results" role="list">
<div ng-repeat="item in $ctrl.results track by $index"
ng-class="($index == $ctrl.selectedItem ? 'item-selected' : '')"
ng-click="$ctrl.navigateToSelected()"
ng-mouseover="$ctrl.selectItem($index)"
role="listitem"
<div ng-bind-html="$ctrl.displayName(item)"></div>
</div>
</div>


(shortened example)



HandleKeypress just sets the id of selected item, which will be highlighted by using the proper class.



Is there any solution that screen readers read the name (displayName) of the selected item?










share|improve this question



























    0















    I'm struggling to enable proper ARIA support for this case. I have a input field which works like a filter, and a set of elements which will be filtered by this input field. The focus is always on the input field, and with arrow up and down you can navigate through the result set. The input needs constant focus because whenever I start typing again, the input should be updated and filter the result set.



    Now I want that my screen reader reads the name of the elements when I navigate through the result set. But if I press arrow down (or up) the reader repeats the full part of the input field.



    Hint: The result set contains images and text and will open the element in a new view when it is clicked.



    <input ng-change="$ctrl.doFilter()" ng-keydown="$ctrl.handleKeydown($event)">    

    <div class="filter-results" role="list">
    <div ng-repeat="item in $ctrl.results track by $index"
    ng-class="($index == $ctrl.selectedItem ? 'item-selected' : '')"
    ng-click="$ctrl.navigateToSelected()"
    ng-mouseover="$ctrl.selectItem($index)"
    role="listitem"
    <div ng-bind-html="$ctrl.displayName(item)"></div>
    </div>
    </div>


    (shortened example)



    HandleKeypress just sets the id of selected item, which will be highlighted by using the proper class.



    Is there any solution that screen readers read the name (displayName) of the selected item?










    share|improve this question

























      0












      0








      0








      I'm struggling to enable proper ARIA support for this case. I have a input field which works like a filter, and a set of elements which will be filtered by this input field. The focus is always on the input field, and with arrow up and down you can navigate through the result set. The input needs constant focus because whenever I start typing again, the input should be updated and filter the result set.



      Now I want that my screen reader reads the name of the elements when I navigate through the result set. But if I press arrow down (or up) the reader repeats the full part of the input field.



      Hint: The result set contains images and text and will open the element in a new view when it is clicked.



      <input ng-change="$ctrl.doFilter()" ng-keydown="$ctrl.handleKeydown($event)">    

      <div class="filter-results" role="list">
      <div ng-repeat="item in $ctrl.results track by $index"
      ng-class="($index == $ctrl.selectedItem ? 'item-selected' : '')"
      ng-click="$ctrl.navigateToSelected()"
      ng-mouseover="$ctrl.selectItem($index)"
      role="listitem"
      <div ng-bind-html="$ctrl.displayName(item)"></div>
      </div>
      </div>


      (shortened example)



      HandleKeypress just sets the id of selected item, which will be highlighted by using the proper class.



      Is there any solution that screen readers read the name (displayName) of the selected item?










      share|improve this question














      I'm struggling to enable proper ARIA support for this case. I have a input field which works like a filter, and a set of elements which will be filtered by this input field. The focus is always on the input field, and with arrow up and down you can navigate through the result set. The input needs constant focus because whenever I start typing again, the input should be updated and filter the result set.



      Now I want that my screen reader reads the name of the elements when I navigate through the result set. But if I press arrow down (or up) the reader repeats the full part of the input field.



      Hint: The result set contains images and text and will open the element in a new view when it is clicked.



      <input ng-change="$ctrl.doFilter()" ng-keydown="$ctrl.handleKeydown($event)">    

      <div class="filter-results" role="list">
      <div ng-repeat="item in $ctrl.results track by $index"
      ng-class="($index == $ctrl.selectedItem ? 'item-selected' : '')"
      ng-click="$ctrl.navigateToSelected()"
      ng-mouseover="$ctrl.selectItem($index)"
      role="listitem"
      <div ng-bind-html="$ctrl.displayName(item)"></div>
      </div>
      </div>


      (shortened example)



      HandleKeypress just sets the id of selected item, which will be highlighted by using the proper class.



      Is there any solution that screen readers read the name (displayName) of the selected item?







      html angularjs wai-aria






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '18 at 14:59









      H4rd_B4seH4rd_B4se

      111




      111
























          1 Answer
          1






          active

          oldest

          votes


















          0














          One way to do it, and I'm not advocating this is the best way, but it seems to work, is to have an onkeydown handler for your input field (which you may already have) and when the up/down arrow key is pressed (which it sounds like you're already listening for), you can update a visually hidden <span> (or <div>) that has aria-live set to "polite" and update the text within that <span> with the text of your result item. I think the screen reader will still read the contents of your input field but it should also read the aria-live text too. Maybe not the ideal solution, but you'll get your result item announced.



          Some (very) rough code:



          <span id="result" aria-live="polite" class="sr-only"></span>

          <script>
          function mykeydown(e) {
          if (e.keyCode == 40)
          document.getElementById("result").innerHTML = "whatever is the next result";
          }
          </script>


          Note: You can see the "sr-only" class here - What is sr-only in Bootstrap 3?






          share|improve this answer























            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%2f53377315%2faria-for-elements-without-focus%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









            0














            One way to do it, and I'm not advocating this is the best way, but it seems to work, is to have an onkeydown handler for your input field (which you may already have) and when the up/down arrow key is pressed (which it sounds like you're already listening for), you can update a visually hidden <span> (or <div>) that has aria-live set to "polite" and update the text within that <span> with the text of your result item. I think the screen reader will still read the contents of your input field but it should also read the aria-live text too. Maybe not the ideal solution, but you'll get your result item announced.



            Some (very) rough code:



            <span id="result" aria-live="polite" class="sr-only"></span>

            <script>
            function mykeydown(e) {
            if (e.keyCode == 40)
            document.getElementById("result").innerHTML = "whatever is the next result";
            }
            </script>


            Note: You can see the "sr-only" class here - What is sr-only in Bootstrap 3?






            share|improve this answer




























              0














              One way to do it, and I'm not advocating this is the best way, but it seems to work, is to have an onkeydown handler for your input field (which you may already have) and when the up/down arrow key is pressed (which it sounds like you're already listening for), you can update a visually hidden <span> (or <div>) that has aria-live set to "polite" and update the text within that <span> with the text of your result item. I think the screen reader will still read the contents of your input field but it should also read the aria-live text too. Maybe not the ideal solution, but you'll get your result item announced.



              Some (very) rough code:



              <span id="result" aria-live="polite" class="sr-only"></span>

              <script>
              function mykeydown(e) {
              if (e.keyCode == 40)
              document.getElementById("result").innerHTML = "whatever is the next result";
              }
              </script>


              Note: You can see the "sr-only" class here - What is sr-only in Bootstrap 3?






              share|improve this answer


























                0












                0








                0







                One way to do it, and I'm not advocating this is the best way, but it seems to work, is to have an onkeydown handler for your input field (which you may already have) and when the up/down arrow key is pressed (which it sounds like you're already listening for), you can update a visually hidden <span> (or <div>) that has aria-live set to "polite" and update the text within that <span> with the text of your result item. I think the screen reader will still read the contents of your input field but it should also read the aria-live text too. Maybe not the ideal solution, but you'll get your result item announced.



                Some (very) rough code:



                <span id="result" aria-live="polite" class="sr-only"></span>

                <script>
                function mykeydown(e) {
                if (e.keyCode == 40)
                document.getElementById("result").innerHTML = "whatever is the next result";
                }
                </script>


                Note: You can see the "sr-only" class here - What is sr-only in Bootstrap 3?






                share|improve this answer













                One way to do it, and I'm not advocating this is the best way, but it seems to work, is to have an onkeydown handler for your input field (which you may already have) and when the up/down arrow key is pressed (which it sounds like you're already listening for), you can update a visually hidden <span> (or <div>) that has aria-live set to "polite" and update the text within that <span> with the text of your result item. I think the screen reader will still read the contents of your input field but it should also read the aria-live text too. Maybe not the ideal solution, but you'll get your result item announced.



                Some (very) rough code:



                <span id="result" aria-live="polite" class="sr-only"></span>

                <script>
                function mykeydown(e) {
                if (e.keyCode == 40)
                document.getElementById("result").innerHTML = "whatever is the next result";
                }
                </script>


                Note: You can see the "sr-only" class here - What is sr-only in Bootstrap 3?







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 2:09









                slugoliciousslugolicious

                4,43811318




                4,43811318






























                    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%2f53377315%2faria-for-elements-without-focus%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

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith