Skip to content

Combination of FocusJumps and Shortcuts #38

Closed

Description

@Hydhen

Hello,

I'm developing an autocomplete system for an input, in basic shape I have something like this:

<div>
  <input type="text" />
  <i class="clear-history"></i>
  <button (click)="search()"></button>
</div>

<div popover>
  <ul role="listbox">
    <li role="option" tabindex="0"><a role="button" aria-keyshortcuts="enter">Suggestion 1</a></li>
    <li role="option" tabindex="0"><a role="button" aria-keyshortcuts="enter">Suggestion 2</a></li>
    <li role="option" tabindex="0"><a role="button" aria-keyshortcuts="enter">Suggestion 3</a></li>
  </ul>
</div>

The list part works like a charm, and I can correctly tab through input > clear > search > listbox, then navigate with arrows.

My problem is when I try to set the focus through code, my goal here is the allow the user to navigate from the input to the list of suggestion by pressing the down arrow key.

I tried getting ElementRef of the list or the first element in the list and .focus() but it doesn't work, am I missing something?

I though about a "scoped" shortcut like:

<div scope-shortcut="downarrow" scope-target="suggestions">
  <input type="text" />
  <i class="clear-history"></i>
  <button (click)="search()"></button>
</div>

<div id="suggestions" popover>
  <ul role="listbox">
    <li role="option" tabindex="0"><a role="button" aria-keyshortcuts="enter">Suggestion 1</a></li>
    ...
  </ul>
</div>

Thanks in advance!

Activity

  1. Repository owner locked and limited conversation to collaborators on Sep 21, 2024
  2. converted this issue into a discussion #39 on Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions