Skip to content

toInitials bug truncating custom initials #6276

@prcdpr

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions