Skip to content

fix(cc-search-bar): virtually focus the first result so Enter opens it - #1802

Open
clara-layus-cc wants to merge 1 commit into
masterfrom
fix/search-bar-select-first-result
Open

fix(cc-search-bar): virtually focus the first result so Enter opens it#1802
clara-layus-cc wants to merge 1 commit into
masterfrom
fix/search-bar-select-first-result

Conversation

@clara-layus-cc

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Virtually focus the first filtered item instead of the input, so Enter opens a result right away — pasting a resource id and hitting Enter now jumps to its single result,
  • Reset that virtual focus from willUpdate(), right after the filtered list is rebuilt, so it follows value and sections instead of being cleared on every keystroke by the input handler,
  • Reset it on dialog close too, so reopening with the same query starts over from the first item rather than from wherever the arrow keys left the selection,
  • Drop the stale-index guard in updated(), now that the index is derived from the filtered items every time they change.

How to review?

  • Check the commits,
  • Check the preview
  • 1 reviewer should be enough.

Pasting a resource id into the search bar yields a single result, but pressing `Enter`
did nothing: the virtual focus started on the input (`_activeItemIndex` at `-1`) and
was sent back there on every keystroke, while `Enter` only activates an item when the
index is `0` or more. Reaching the only result took an `ArrowDown` first.

The virtual focus now rests on the first filtered item instead of the input, which is
what a command palette does and what the `↵` footer hint has been promising all along.
It is reset by `willUpdate()` right after the filtered list is rebuilt, so it follows
`value` and `sections` rather than being cleared by the input handler, and on close so
that reopening with the same query starts over from the first item rather than from
wherever the arrow keys left the selection.

`updated()` no longer needs to catch an index pointing past the end of the list: the
index is now derived from the filtered items every time they change, so it can no
longer outlive them.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 A preview has been automatically published : https://clever-components-preview.cellar-c2.services.clever-cloud.com/fix/search-bar-select-first-result/index.html.

This preview will be deleted once this PR is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant