Skip to content

toInitials bug truncating custom initials #6276

Closed

Description

@prcdpr

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.

Activity

  1. cee-chen commented on Sep 29, 2022

    @cee-chen
    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!

  2. richardtorres314 commented on Nov 23, 2022

    @richardtorres314
    Contributor

    @constancecchen Is this issue okay to close?

  3. cee-chen commented on Nov 23, 2022

    @cee-chen
    Contributor

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

  4. richardtorres314 commented on Nov 23, 2022

    @richardtorres314
    Contributor

    Haha no worries! Thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions