Skip to content

docs(useAnnounce): add a filter result count example block - #9509

Merged
cixzhang merged 3 commits into
meta:mainfrom
MannXo:docs/9481-useannounce-example
Nov 3, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
MannXo:docs/9481-useannounce-example

Conversation

@MannXo

@MannXo MannXo commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Reader impact

A builder reading the useAnnounce docs has no runnable example of the hook. After this change the hook's page shows a product filter that announces its result count, and astryx template useAnnounceHookUsage <path> copies it.

Source of truth

  • useAnnounce and its HookDoc (packages/core/src/hooks/useAnnounce.ts, useAnnounce.doc.mjs), in particular the best practice to send a changing count through its own hasReplace instance.
  • architecture:knowledge-contracts INV28.

Correction

Adds blocks/components/Hooks/useAnnounceHookUsage (exampleFor: 'useAnnounce'). The filter calls useAnnounce({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's BaseTypeahead debounces its search, and an unmount effect clears it. The list itself is a List of the matches.

Evidence

  • Real Chromium (Playwright against the docsite dev server, /components/useAnnounce). Typing desk at 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".
  • Test (packages/cli/api/template/use-announce-hook-usage.test.tsx, outside assets/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

  • This PR changes documentation only, or names every necessary generated artifact. The generated artifacts are the new block's route in internal/shadcn-registry/routes.lock.json and its sandbox route in apps/sandbox/scripts/next-export-routes.json.
  • Runtime, API, visual, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

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, then vitest run src/__tests__/data-extraction.test.ts src/__tests__/example-coverage.test.ts: 133 passed, 0 failed. The route lock check is clean after UPDATE_SHADCN_ROUTE_LOCK=1 added the new route.
  • pnpm -F @astryxdesign/cli typecheck (template docs and strict): clean.
  • eslint (strict tier) and prettier --check on the touched files: clean.
  • node scripts/release/changeset-coverage.mjs pr --base upstream/main --head HEAD --released v0.7.5: passes. Changeset is @astryxdesign/cli patch, [docs].
  • Not run: the full pnpm test suite.

Fixes #9481

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 3, 2026 6:59pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 7:07 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Nov 2, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useAnnounce example works as described, but it needs two small fixes before it can merge.

  • Add "/templates/useAnnounceHookUsage/" to apps/sandbox/scripts/next-export-routes.json, between theme-showcase and useContainerRevealHookUsage. Without it, apps/sandbox/src/route-manifest.test.ts fails and the sandbox build inside the docsite deployment stops at verify-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, hasReplace never 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.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, replace onChange={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]

Comment on lines +34 to +46
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]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MannXo
MannXo force-pushed the docs/9481-useannounce-example branch from 5155d7c to df5e7c7 Compare November 2, 2026 20:40
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a5debfa

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded failure. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

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

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 3, 2026
@cixzhang cixzhang closed this Nov 3, 2026
@cixzhang cixzhang reopened this Nov 3, 2026
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Nov 3, 2026
@cixzhang
cixzhang merged commit dc90b50 into meta:main Nov 3, 2026
98 of 102 checks passed
cixzhang added a commit to MannXo/astryx that referenced this pull request Nov 3, 2026
Main gained meta#9509's useAnnounce example beside this one; both route
manifests keep both entries.
cixzhang added a commit that referenced this pull request Nov 3, 2026
* 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]>

This branch was successfully deployed

1 active deployment
Preview — a5debfa5 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs(useAnnounce): add a minimal live example

2 participants