Skip to content

Search when typing pauses - #79

Open
s3rgiosan wants to merge 1 commit into
humanmade:mainfrom
s3rgiosan:78/search-debounce
Open

s3rgiosan wants to merge 1 commit into
humanmade:mainfrom
s3rgiosan:78/search-debounce

Conversation

@s3rgiosan

Copy link
Copy Markdown

Fixes #78.

Changes

  1. JS: actions.search in src/taxonomy/view.js waits 300 ms after an input event. It navigates only when no newer keystroke or submission arrived in that time. A submission searches at once and cancels a search that still waits. Clearing the field clears the search after the same pause.
  2. JS: getContext() moves after the wait. The generator restores the directive scope after each yield, so the call reads the context of the search block.
  3. Test: tests/e2e/search-filter.spec.js types a word key by key and checks that the page requests only the full word. Without the fix, the test fails with one request for each character. A second test checks that a submission starts its request before the pause ends.

Testing

  • npx playwright test: 54 passed.
  • npx wp-scripts lint-js src/taxonomy/view.js tests/e2e/search-filter.spec.js: no errors.

Debounce input-driven searches by 300 ms. A submission searches at once and cancels a search that still waits.
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.

Typing in a search field starts one navigation for each keystroke

1 participant