Skip to content

Commit

Permalink
Allow avatar name to be composed entirely of whitespace (#1231)
Browse files Browse the repository at this point in the history
* allow avatar name to be composed entirely of whitespace

* changelog
  • Loading branch information
legrego authored Oct 3, 2018
1 parent 876e1cb commit 2bec11b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Bug fixes**

- Fix EuiToolTip to show tooltips on disabled elements ([#1222](https://github.com/elastic/eui/pull/1222))
- Fix EuiAvatar when name is composed entirely of whitespace ([#1231](https://github.com/elastic/eui/pull/1231))

## [`4.3.0`](https://github.com/elastic/eui/tree/v4.3.0)

Expand Down
16 changes: 16 additions & 0 deletions src/components/avatar/__snapshots__/avatar.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiAvatar allows a name composed entirely of whitespace 1`] = `
<div
aria-label="aria-label"
class="euiAvatar euiAvatar--m euiAvatar--user testClass1 testClass2"
data-test-subj="test subject string"
style="background-image:none;background-color:#DB1374;color:#FFFFFF"
title=" "
>
<span
aria-hidden="true"
>
</span>
</div>
`;

exports[`EuiAvatar is rendered 1`] = `
<div
aria-label="aria-label"
Expand Down
2 changes: 1 addition & 1 deletion src/components/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const EuiAvatar = ({
if (initials) {
calculatedInitials = initials.substring(0, calculatedInitialsLength);
} else {
if (name.split(' ').length > 1) {
if (name.trim() && name.split(' ').length > 1) {
// B. If there are any spaces in the name, set to first letter of each word
calculatedInitials = name.match(/\b(\w)/g).join('').substring(0, calculatedInitialsLength);
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/components/avatar/avatar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe('EuiAvatar', () => {
.toMatchSnapshot();
});

test('allows a name composed entirely of whitespace', () => {
const component = render(
<EuiAvatar
name=" "
{...requiredProps}
/>
);

expect(component)
.toMatchSnapshot();
});

describe('props', () => {
describe('imageUrl', () => {
it('is rendered', () => {
Expand Down

0 comments on commit 2bec11b

Please sign in to comment.