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

Fixed EuiI8n hasPropName utility errors on null values #3303

Merged
merged 3 commits into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ No public interface changes since `22.5.0`.

**Bug Fixes**

- Fixed EuiI8n hasPropName utility errors on null values ([#3303](https://github.com/elastic/eui/pull/3303))
- Fixed the inline styles being overwritten by consumer-passed inline styles in EuiBadge ([#3284](https://github.com/elastic/eui/pull/3284))

## [`22.4.0`](https://github.com/elastic/eui/tree/v22.4.0)
Expand Down
16 changes: 16 additions & 0 deletions src/components/i18n/__snapshots__/i18n.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ exports[`EuiI18n default rendering rendering to dom renders a string with placeh
</EuiI18n>
`;

exports[`EuiI18n default rendering rendering to dom renders when value is null 1`] = `
<EuiI18n
default="{arg}"
token="test"
values={
Object {
"arg": null,
}
}
>
<Component
arg={null}
/>
</EuiI18n>
`;

exports[`EuiI18n reading values from context mappingFunc calls the mapping function with the source string 1`] = `
<EuiContext
i18n={
Expand Down
7 changes: 7 additions & 0 deletions src/components/i18n/i18n.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ describe('EuiI18n', () => {

expect(renderCallback).toHaveBeenCalledWith(values);
});

it('renders when value is null', () => {
const component = mount(
<EuiI18n token="test" default="{arg}" values={{ arg: null }} />
);
expect(component).toMatchSnapshot();
});
});

describe('render prop with single token', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/i18n/i18n_util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function isPrimitive(value: ReactChild) {
type Child = string | { propName: string } | ReactChild | undefined;

function hasPropName(child: Child): child is { propName: string } {
return typeof child === 'object' && child.hasOwnProperty('propName');
return child
? typeof child === 'object' && child.hasOwnProperty('propName')
: false;
}

/**
Expand Down