Skip to content

TaxonomySidebar: show existing taxonomy terms in the tag picker - #1248

Merged
ascorbic merged 2 commits into
emdash-cms:mainfrom
mvanhorn:fix/1199-taxonomy-existing-terms
Jun 1, 2026
Merged

ascorbic merged 2 commits into
emdash-cms:mainfrom
mvanhorn:fix/1199-taxonomy-existing-terms

Conversation

@mvanhorn

@mvanhorn mvanhorn commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

The taxonomy tag picker only rendered its suggestion list when the user had typed something, so existing terms were never shown on focus — a reporter saw "no existing terms" and could only create new ones.

Now the picker shows the available terms on focus (not just while typing), tracks an explicit open/close state driven by focus and blur, and uses onMouseDown preventDefault on the suggestion buttons so a click registers before blur closes the list. A stable empty-array default avoids re-render churn from new [] references on every render.

Closes #1199

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes (admin)
  • pnpm lint passes (oxlint, changed files)
  • pnpm test passes (TaxonomySidebar suite: 5 passing)
  • pnpm format has been run
  • I have added/updated tests for my changes
  • User-visible strings: existing t\...`` wrappers preserved; no new untranslated strings
  • I have added a changeset (@emdash-cms/admin: patch)
  • New features link to an approved Discussion: N/A (bug fix)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: GPT-5.5 (Codex CLI)

Screenshots / test output

packages/admin TaxonomySidebar.test.tsx
Tests  5 passed (5)

The term suggestion dropdown only rendered when the user had typed input, so
existing terms were never shown on focus. Show available terms on focus, track
open state with focus/blur (preventing the mousedown/blur race from closing
the list before a click registers), and use a stable empty-array default to
avoid re-render churn.

Closes emdash-cms#1199
@changeset-bot

changeset-bot Bot commented May 31, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 52b6bdc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet area/admin size/L labels May 31, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1248

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1248

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1248

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1248

emdash

npm i https://pkg.pr.new/emdash@1248

create-emdash

npm i https://pkg.pr.new/create-emdash@1248

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1248

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1248

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1248

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1248

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1248

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1248

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1248

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1248

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1248

commit: 52b6bdc

@emdashbot emdashbot 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 is a focused, well-executed bug fix. The approach is sound: adding explicit isOpen state to the tag picker, driving it with onFocus/onBlur, and using onMouseDown preventDefault to let clicks register before blur closes the dropdown. This directly solves the reported issue (#1199) where existing flat-taxonomy terms were invisible until the user typed something.

I checked:

  • Approach: Correct. The blur containment check (relatedTarget inside currentTarget) is the right React-safe way to keep the list open while focus moves between the input and its suggestion buttons. The stable EMPTY_TERMS default avoids re-render churn from fresh [] references.
  • AGENTS.md conventions: No violations. No new user-facing untranslated strings; RTL-safe logical Tailwind classes (start-0, end-0, text-start) are used; the changeset is present and correctly scoped.
  • Logic & edge cases: On empty input with no available terms, the dropdown correctly stays hidden (suggestions.length === 0 && showCreateOption === false). On empty input with available terms, up to 5 are shown. When all terms are already selected, nothing is suggested. Keyboard Enter behavior is unchanged. Touch/keyboard blur paths behave correctly because the container onBlur handler checks contains(nextFocused).
  • Tests: Five new vitest-browser-react tests cover focus-on-empty, filtering while preserving the create option, suppressing already-assigned terms, create-only when no terms exist, and continued hierarchical rendering. The mock shapes match the { data: ... } API envelope used by parseApiResponse.
  • Code quality: Clean, minimal diff scoped to the bug. No drive-by refactors.

I found no blocking issues. The implementation is correct and the tests are appropriate for the change.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Jun 1, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Looks good

@ascorbic
ascorbic merged commit b89e988 into emdash-cms:main Jun 1, 2026
37 of 38 checks passed
@emdashbot emdashbot Bot mentioned this pull request Jun 1, 2026
@mvanhorn

mvanhorn commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Nice to have this in, thanks @ascorbic. Showing the existing taxonomy terms in the TaxonomySidebar makes it much easier to stay consistent.

@mvanhorn

mvanhorn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Appreciate you landing the taxonomy term picker @ascorbic, surfacing existing terms kills the duplicate-tag problem.

@mvanhorn

mvanhorn commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Appreciate the merge @ascorbic, glad the tag picker now surfaces existing taxonomy terms.

@mvanhorn

mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ascorbic for merging the taxonomy picker fix. Showing existing terms on focus is a nice catch for that reporter.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Tag taxonomy term picker shows no existing terms when taxonomy is added to a custom collection

2 participants