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
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ export const Headline: React.FC<Props> = ({ text, matchIndices, variant }) => {
return (
<>
{text.split("").map((char, index) => (
<Typography
component="span"
variant={variant}
key={`headline-character-${index}`}
sx={(theme) => ({
fontWeight: isHighlighted(index) ? FONT_WEIGHT_BOLD : "regular",
fontSize: theme.typography.body2.fontSize,
})}
>
{char}
</Typography>
<>
<Typography
component="span"
variant={variant}
key={`headline-character-${index}`}
sx={(theme) => ({
fontWeight: isHighlighted(index) ? FONT_WEIGHT_BOLD : "regular",
fontSize: theme.typography.body2.fontSize,
})}
>
{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

</>
))}
</>
);
Expand Down
Loading