Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form token field suggestion list reopening after blurring the input #57002

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Bug Fix

- `Button`: Fix logic of `has-text` class addition ([#56949](https://github.com/WordPress/gutenberg/pull/56949)).
- `FormTokenField`: Fix a regression where the suggestion list would re-open after clicking away from the input ([#57002](https://github.com/WordPress/gutenberg/pull/57002)).

## 25.14.0 (2023-12-13)

Expand Down
18 changes: 11 additions & 7 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,17 @@ export function FormTokenField( props: FormTokenFieldProps ) {
setInputOffsetFromEnd( 0 );
setIsActive( false );

// If `__experimentalExpandOnFocus` is true, don't close the suggestions list when
// the user clicks on it (`tokensAndInput` will be the element that caused the blur).
const shouldKeepSuggestionsExpanded =
! __experimentalExpandOnFocus ||
( __experimentalExpandOnFocus &&
event.relatedTarget === tokensAndInput.current );
setIsExpanded( shouldKeepSuggestionsExpanded );
if ( __experimentalExpandOnFocus ) {
// If `__experimentalExpandOnFocus` is true, don't close the suggestions list when
// the user clicks on it (`tokensAndInput` will be the element that caused the blur).
const hasFocusWithin =
event.relatedTarget === tokensAndInput.current;
setIsExpanded( hasFocusWithin );
} else {
// Else collapse the suggestion list. This will result in the suggestion list closing
// after a suggestion has been submitted since that causes a blur.
setIsExpanded( false );
}

setSelectedSuggestionIndex( -1 );
setSelectedSuggestionScroll( false );
Expand Down
Loading