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(search): Add word break after special characters in search cards #3741

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Sep 30, 2024

What does this PR do?

Adds a <wbr/> element (docs) after a headline character if it's a special character.

Why?

The headline element is split into a series of spans (one per character), so applying a regular word break css rule to the parent won't work. By inserting a <wbr/> each time we hit a non-alphanumeric character, we allow the browser to break where it sees fit.

Before After
image image

@DafyddLlyr DafyddLlyr changed the title feat: Add wordbreak after special characters feat(search): Add word break after special characters in search cards Sep 30, 2024
@DafyddLlyr DafyddLlyr requested a review from a team September 30, 2024 16:36
Copy link

github-actions bot commented Sep 30, 2024

Removed vultr server and associated DNS entries

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Fundamentally works/looks better but one quick question about the code here!

{char}
</Typography>
{/* Add wordbreak after special characters */}
{char.match(/\W/) && <wbr />}
Copy link
Member

Choose a reason for hiding this comment

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

I don't fully understand why this is outside of the <Typography> block and only within the fragment? Don't we want all characters to share the styles above (eg indexed/matching characters after a special character should still have bold highlighting?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! This is a little unexpected as the headline breaks each word into characters and inserts a "word" break after them. The <wbr/> is just a non-visual element so that it splits in the right place.

The reason there's only one word highlighted is that the search is configured to just return the first match from a string, not all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@DafyddLlyr DafyddLlyr merged commit 45c295e into main Oct 1, 2024
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/search-card-wordbreak branch October 1, 2024 07:37
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