Repository navigation
docs(useAnnounce): add a filter result count example block - #9509
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
The useAnnounce example works as described, but it needs two small fixes before it can merge.
- Add
"/templates/useAnnounceHookUsage/"toapps/sandbox/scripts/next-export-routes.json, betweentheme-showcaseanduseContainerRevealHookUsage. Without it,apps/sandbox/src/route-manifest.test.tsfails and the sandbox build inside the docsite deployment stops atverify-export.mjs, which matches the failed preview deployment. - Reword the block description and the changeset so the 500 ms pause gets the credit for announcing only the latest count: with the timer in place,
hasReplacenever has an unspoken count to replace, and the tests pass with or without it.
[Automated review]
| name: 'useAnnounce — Filter Result Count', | ||
| displayName: 'useAnnounce — Filter Result Count', | ||
| description: | ||
| 'A product filter that announces its result count with useAnnounce: once typing pauses, a screen reader hears "3 results" or "No results", and a hasReplace instance keeps only the latest count.', |
There was a problem hiding this comment.
In this block the 500 ms pause, not hasReplace, is what keeps only the latest count: only one timer exists at a time, so there is never an unspoken count for hasReplace to withdraw, and both tests pass with useAnnounce(). Suggested wording, here and in the changeset: "…once typing pauses for 500 ms, a screen reader hears "3 results" or "No results". The count has its own hasReplace instance, as the hook's docs advise for a changing value."
There was a problem hiding this comment.
The sandbox route and the reworded description are in, and the example works as described; one change remains before it can merge. Start the 500 ms announcement timer in the field's change handler instead of an Effect that reacts to query.
- In
useAnnounceHookUsage.tsx, replaceonChange={setQuery}with a handler that sets the query, clears any pending timer kept in a ref, and starts a new one with the new value's count, then keep one unmount Effect that clears the timer; both of your tests pass unchanged with that version.
[Automated review]
| useEffect(() => { | ||
| if (query === '') { | ||
| return; | ||
| } | ||
| const timer = setTimeout(() => { | ||
| announce( | ||
| count === 0 | ||
| ? 'No results' | ||
| : `${count} ${count === 1 ? 'result' : 'results'}`, | ||
| ); | ||
| }, ANNOUNCE_DELAY_MS); | ||
| return () => clearTimeout(timer); | ||
| }, [announce, count, query]); |
There was a problem hiding this comment.
Every query change comes from the TextInput onChange below (typing and the clear button), so the handler can restart this timer: set the query, clear the pending timer kept in a ref, and for a non-empty value start a new one with that value's count. Keep one unmount Effect, with a comment, that clears the timer. Core's BaseTypeahead starts its search debounce the same way, and both tests in use-announce-hook-usage.test.tsx pass with that version.
5155d7c to
df5e7c7
Compare
PR Analysis Report🔎 Preview ·
|
A product filter announces its result count through a hasReplace useAnnounce instance once typing pauses, so a screen reader hears "3 results" or "No results" rather than a count per keystroke. Fixes meta#9481
…of templates, and credit the pause
df5e7c7 to
a5debfa
Compare
There was a problem hiding this comment.
This looks ready to merge: the 500 ms timer now starts in the field's change handler, the only Effect clears it on unmount, and the example meets every point of the hook-example rule (INV28).
No changes are needed from you. The repository's test, build and lint jobs have not run on this commit yet; they start once a maintainer adds the ci:run label.
[Automated review]
Main gained meta#9509's useAnnounce example beside this one; both route manifests keep both entries.
* docs(useFocusTrap): add a quick edit panel example block A custom quick-edit panel, not built on Dialog, traps focus with useFocusTrap: focusFirst moves focus to its field on open, Tab and Shift+Tab stay inside it, Escape closes it through onEscape, and closing returns focus to the Quick edit button. Fixes #9485 * docs(useFocusTrap): list the sandbox route, move the example test out of templates, and say why focusFirst runs in an effect * Merge main into the useFocusTrap quick-edit example Main gained #9509's useAnnounce example beside this one; both route manifests keep both entries. * test(cli): the close-search golden counts the new useFocusTrap example The new example block matches `astryx search close`, so the match count goes from 46 to 47; the top 20 results are unchanged. Co-authored-by: Cindy Zhang <[email protected]>
Reader impact
A builder reading the
useAnnouncedocs has no runnable example of the hook. After this change the hook's page shows a product filter that announces its result count, andastryx template useAnnounceHookUsage <path>copies it.Source of truth
useAnnounceand its HookDoc (packages/core/src/hooks/useAnnounce.ts,useAnnounce.doc.mjs), in particular the best practice to send a changing count through its ownhasReplaceinstance.architecture:knowledge-contractsINV28.Correction
Adds
blocks/components/Hooks/useAnnounceHookUsage(exampleFor: 'useAnnounce'). The filter callsuseAnnounce({hasReplace: true})and announces "N results", "1 result" or "No results" once typing pauses for 500 ms. Core has no public debounce hook, so the pause is a plain timer that the field's change handler restarts, the way core'sBaseTypeaheaddebounces its search, and an unmount effect clears it. The list itself is aListof the matches.Evidence
/components/useAnnounce). Typingdeskat 80 ms per key leaves the polite region empty 150 ms after the last key. 600 ms after it, the region reads "3 results" and three rows show. Typing more until nothing matches announces "No results".packages/cli/api/template/use-announce-hook-usage.test.tsx, outsideassets/templates/so the template viewer does not load it as a template). Keystrokes 200 ms apart announce nothing, then the count lands after the pause, and a query with no match announces "No results". With the hook replaced by a no-op, both tests fail.Scope
internal/shadcn-registry/routes.lock.jsonand its sandbox route inapps/sandbox/scripts/next-export-routes.json.Testing
vitest run --project node packages/cli/api/template/use-announce-hook-usage.test.tsx apps/sandbox/src/route-manifest.test.ts: 8 passed, 0 failed.vitest run --project node packages/cli/foundation/discovery packages/cli/api/template packages/cli/assets/templates internal/shadcn-registry: 1104 passed, 0 failed.apps/docsite:node scripts/generate-data.mjs, thenvitest run src/__tests__/data-extraction.test.ts src/__tests__/example-coverage.test.ts: 133 passed, 0 failed. The route lock check is clean afterUPDATE_SHADCN_ROUTE_LOCK=1added the new route.pnpm -F @astryxdesign/cli typecheck(template docs and strict): clean.eslint(strict tier) andprettier --checkon the touched files: clean.node scripts/release/changeset-coverage.mjs pr --base upstream/main --head HEAD --released v0.7.5: passes. Changeset is@astryxdesign/clipatch,[docs].pnpm testsuite.Fixes #9481