Skip to content

Fix FormTokenField suggestions dropdown flashing closed on click#23

Merged
flexseth merged 2 commits intofeature/form-token-fieldfrom
copilot/sub-pr-22
Feb 23, 2026
Merged

Fix FormTokenField suggestions dropdown flashing closed on click#23
flexseth merged 2 commits intofeature/form-token-fieldfrom
copilot/sub-pr-22

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 23, 2026

When the token field contained enough tags to wrap to multiple lines, clicking anywhere in the field caused the suggestions dropdown to appear briefly then immediately close.

Root Cause

A blur/focus race condition in the onBlur handler. The timer ID was discarded, so when clicking the container caused a blur→refocus cycle, the stale timer always won:

  1. Input blurs → setTimeout(() => setIsOpen(false), 150) fires (ID discarded)
  2. Input refocuses → setIsOpen(true)
  3. Stale timer fires → setIsOpen(false)

Fix

Track the timer in a blurTimerRef and cancel it on focus:

// Before
onFocus={ () => setIsOpen( true ) }
onBlur={ () => setTimeout( () => setIsOpen( false ), 150 ) }

// After
onFocus={ () => {
    if ( blurTimerRef.current ) {
        clearTimeout( blurTimerRef.current );
        blurTimerRef.current = null;
    }
    setIsOpen( true );
} }
onBlur={ () => {
    blurTimerRef.current = setTimeout( () => {
        setIsOpen( false );
        blurTimerRef.current = null;
    }, 150 );
} }

Also added a useEffect cleanup to clear any pending timer on unmount.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

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 9:42pm

…h and close

Co-authored-by: flexseth <3792502+flexseth@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address CSS and event handling feedback on FormTokenField docs Fix FormTokenField suggestions dropdown flashing closed on click Feb 23, 2026
Copilot AI requested a review from flexseth February 23, 2026 21:43
@flexseth flexseth marked this pull request as ready for review February 23, 2026 21:46
@flexseth
Copy link
Copy Markdown
Owner

Make FormTokenField more usable.. this needs to be tested in WordPress to see how it works.

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.

User experience is much more predictable.

@flexseth flexseth merged commit b7267aa into feature/form-token-field Feb 23, 2026
2 checks passed
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