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

toInitials bug truncating custom initials #6276

Closed
prcdpr opened this issue Sep 29, 2022 · 4 comments
Closed

toInitials bug truncating custom initials #6276

prcdpr opened this issue Sep 29, 2022 · 4 comments

Comments

@prcdpr
Copy link

prcdpr commented Sep 29, 2022

In
https://github.com/elastic/eui/blob/main/src/services/string/to_initials.ts

Custom initials in the line 32 are split by whitespace
https://github.com/elastic/eui/blob/main/src/services/string/to_initials.ts#L32
to calculate length.

So if you pass A B, length will be calculated to 2.

However, on the line 49:
https://github.com/elastic/eui/blob/main/src/services/string/to_initials.ts#L49

There is a simple substring that will return only the first character.

If you pass AB without space, it will calculate length to 1 and it will also return only first character.
So the only working way to use custom initials is to pass correct length via function args.

Solution is to split every character instead of splitting by space in line 32.

@cee-chen cee-chen added the bug label Sep 29, 2022
@cee-chen
Copy link
Contributor

After looking more closely at the code, I agree with you that line 32 should be .split('') instead of .split(' '). We'd super welcome a PR for this if you're open to a community contribution!

@richardtorres314
Copy link
Contributor

@constancecchen Is this issue okay to close?

@cee-chen
Copy link
Contributor

Ah, I didn't realize this wasn't autolinked with the PR, apologies! Closing - thanks for your work on this again! 🎉

@richardtorres314
Copy link
Contributor

Haha no worries! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants