Repository navigation
TaxonomySidebar: show existing taxonomy terms in the tag picker - #1248
Conversation
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 detectedLatest commit: 52b6bdc The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
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 |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
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 (
relatedTargetinsidecurrentTarget) is the right React-safe way to keep the list open while focus moves between the input and its suggestion buttons. The stableEMPTY_TERMSdefault 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. KeyboardEnterbehavior is unchanged. Touch/keyboard blur paths behave correctly because the containeronBlurhandler checkscontains(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 byparseApiResponse. - 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.
|
Nice to have this in, thanks @ascorbic. Showing the existing taxonomy terms in the TaxonomySidebar makes it much easier to stay consistent. |
|
Appreciate you landing the taxonomy term picker @ascorbic, surfacing existing terms kills the duplicate-tag problem. |
|
Appreciate the merge @ascorbic, glad the tag picker now surfaces existing taxonomy terms. |
|
Thanks @ascorbic for merging the taxonomy picker fix. Showing existing terms on focus is a nice catch for that reporter. |
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 preventDefaulton 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
Checklist
pnpm typecheckpasses (admin)pnpm lintpasses (oxlint, changed files)pnpm testpasses (TaxonomySidebar suite: 5 passing)pnpm formathas been runt\...`` wrappers preserved; no new untranslated strings@emdash-cms/admin: patch)AI-generated code disclosure
Screenshots / test output