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

feat(combobox): highlight filter matches #9425

Merged
merged 7 commits into from
Jun 24, 2024

Conversation

jcfranco
Copy link
Member

@jcfranco jcfranco commented May 25, 2024

Related Issue: #9026

Summary

Adds highlighting to combobox for the first occurrence of an item's label that matches the filter text.

Next steps

For consistency, we can update list with similar functionality.

@github-actions github-actions bot added the enhancement Issues tied to a new feature or request. label May 25, 2024
@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label May 25, 2024
Copy link
Contributor

github-actions bot commented Jun 5, 2024

This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues or pull requests that have not had recent activity. label Jun 5, 2024
@benelan benelan changed the base branch from main to dev June 10, 2024 09:11
@github-actions github-actions bot removed the Stale Issues or pull requests that have not had recent activity. label Jun 11, 2024
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity. Please close your PR if it is no longer relevant. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues or pull requests that have not had recent activity. label Jun 18, 2024
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. visual changes Issues with visual changes that are added for consistency, but are not backwards compatible and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. Stale Issues or pull requests that have not had recent activity. visual changes Issues with visual changes that are added for consistency, but are not backwards compatible labels Jun 21, 2024
@jcfranco jcfranco marked this pull request as ready for review June 22, 2024 00:12
@jcfranco jcfranco requested a review from a team as a code owner June 22, 2024 00:12
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Jun 22, 2024
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

Looking good! 🫘

}

return parts;
}
Copy link
Member

Choose a reason for hiding this comment

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

not sure if this is helpful, but this is what we have for the maps sdk.

const regexContainsHTML = /<[a-z/][\s\S]*>/i;

const boldKeywords = (text: string, keywords: string): string => {
  const escapedKeywords = escapeRegExpString(keywords);
  const splitKeywords = escapedKeywords.split(/\s/);
  const pattern = new RegExp(`(${splitKeywords.join("|")})`, "gi");
  return text.replace(pattern, (match) => `<strong>${match}</strong>`);
};

... later

return regexContainsHTML.test(text) ? text : boldKeywords(text, searchTerm);

Copy link
Member

Choose a reason for hiding this comment

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

We may want to follow the same logic since Search widget would likely want the same bold experience.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion. Will update!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, could we discuss this in a follow-up issue? There are some differences in implementation and UI/UX that I think need to be considered first, such as:

  • combobox filtering is immediate, search has minimum chars before showing matches
  • combobox highlights the first occurrence, search highlights all matches
  • combobox items do not support HTML as content, search does

There could be others, but these are the ones I noticed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did add the regexp char escape. 🏃🔠 Thanks for the bringing that up!

Copy link
Member

Choose a reason for hiding this comment

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

combobox filtering is immediate, search has minimum chars before showing matches

I think this could be handled when we support combobox with dynamic data

combobox highlights the first occurrence, search highlights all matches

Shouldn't combobox highlight all matches? Why does it only highlight the first occurrence?

combobox items do not support HTML as content, search does

Yes, we can ignore this one. It doesn't do regex if there is HTML involved.

Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't combobox highlight all matches? Why does it only highlight the first occurrence?

This closely matches the current filtering behavior. It returns on the first match. I also did this to minimize elements updated as the user types since we don't have virtualization alternatives and showing all matches < 3 chars seems unnecessary.

FWIW, I'm fine revisiting ☝️, but I would like design to give a pass before doing so. It would be an incremental enhancement this way vs rolling it back.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah sounds good.

@jcfranco jcfranco requested a review from driskull June 24, 2024 17:32
@jcfranco
Copy link
Member Author

@driskull I think I've addressed all items besides the highlighting behavior discussion. Would you mind reviewing again?

Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

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

👍 Looks good!

@jcfranco jcfranco removed the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Jun 24, 2024
@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Jun 24, 2024
@jcfranco jcfranco merged commit 0d538c8 into dev Jun 24, 2024
12 checks passed
@jcfranco jcfranco deleted the jcfranco/9026-highlight-filter-matches branch June 24, 2024 17:47
@github-actions github-actions bot added this to the 2024-06-25 - Jun Release milestone Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues tied to a new feature or request. pr ready for visual snapshots Adding this label will run visual snapshot testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants