Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
fix(core): skip state change on onClick if URL
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Apr 1, 2020
1 parent fc57770 commit 53f634d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/autocomplete-core/src/propGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ export function getPropGetters<TItem, TEvent, TMouseEvent, TKeyboardEvent>({
((event as unknown) as MouseEvent).preventDefault();
},
onClick(event) {
// If `getSuggestionUrl` is provided, it means that the suggestion
// is a link, not plain text that aims at updating the query.
// We can therefore skip the state change because it will update
// the `highlightedIndex`, resulting in a UI flash, especially
// noticeable on mobile.
if (
source.getSuggestionUrl({
suggestion: item,
state: store.getState(),
}) !== undefined
) {
return;
}

// We ignore all modified clicks to support default browsers' behavior.
if (isSpecialClick((event as unknown) as MouseEvent)) {
return;
Expand Down

0 comments on commit 53f634d

Please sign in to comment.