Skip to content

Fix ID collision in FormTokenField suggestions list#24

Draft
Copilot wants to merge 2 commits intofeature/form-token-fieldfrom
copilot/sub-pr-22-again
Draft

Fix ID collision in FormTokenField suggestions list#24
Copilot wants to merge 2 commits intofeature/form-token-fieldfrom
copilot/sub-pr-22-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 23, 2026

Hardcoded id="ftf-suggestions" breaks ARIA associations and violates HTML uniqueness when multiple FormTokenField instances exist on the same page.

Changes

  • Dynamic suggestionsId — derived from label prop using the codebase-standard pattern; sanitizes to [a-z0-9-_] to produce valid HTML IDs
  • useId() fallback — uses React 18's useId() when no label is provided, guaranteeing per-instance uniqueness
  • Applied consistently to both aria-controls on <input> and id on the suggestions <ul>
const generatedId = useId();
const suggestionsId = label
    ? `formtoken-${ label.toLowerCase().replace( /\s+/g, '-' ).replace( /[^a-z0-9-_]/g, '' ) }`
    : `formtoken-${ generatedId }`;

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI mentioned this pull request Feb 23, 2026
8 tasks
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 23, 2026

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

Project Deployment Actions Updated (UTC)
gutendocs Ready Ready Preview, Comment Feb 23, 2026 10:34pm

Co-authored-by: flexseth <3792502+flexseth@users.noreply.github.com>
Copilot AI changed the title [WIP] Update FormTokenField documentation based on feedback Fix ID collision in FormTokenField suggestions list Feb 23, 2026
Copilot AI requested a review from flexseth February 23, 2026 22:35
@flexseth
Copy link
Copy Markdown
Owner

@copilot has this been merged?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot has this been merged?

Not yet — PR #24 is still open and marked as a draft. It's targeting the feature/form-token-field branch (PR #22) as its base. Once #22 is ready and merged, this PR can be reviewed and merged on top of it.

@flexseth
Copy link
Copy Markdown
Owner

The hardcoded id="ftf-suggestions" violated HTML uniqueness requirements and broke ARIA associations when multiple FormTokenField instances appeared on the same page.

Can we make a standard for components, such that if there is more than one on a page, they will not collide?

I will approve this PR, and merge.

@copilot - Please make a new PR to add the anti-collision method to all other components, can you do that?

Copy link
Copy Markdown
Owner

@flexseth flexseth left a comment

Choose a reason for hiding this comment

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

This is a feature fix when trying to create a single post or page with multiple components of the same type on it. Should extend beyond just this component, we will address the PR in the future as the plugin UI starts working better.

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.

2 participants