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

[EuiFilterButton] Allow for zero notifications #1510

Merged
merged 3 commits into from
Feb 5, 2019
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 @@
- Updated `EuiPage` background color to match body background color ([#1513](https://github.com/elastic/eui/pull/1513))
- Fixed React key usage in `EuiPagination` ([#1514](https://github.com/elastic/eui/pull/1514))
- Fixed bug which prevented `EuiSwitch` with generated ID from having its label announced by VoiceOver ([#1519](https://github.com/elastic/eui/pull/1519))
- Fixed `EuiFilterButton` handling `numFilters` when `0` was specified ([#1510](https://github.com/elastic/eui/pull/1510))

## [`6.8.0`](https://github.com/elastic/eui/tree/v6.8.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,29 @@ exports[`EuiFilterButton is rendered 1`] = `
</span>
</button>
`;

exports[`EuiFilterButton renders zero properly 1`] = `
<button
aria-label="aria-label"
class="euiButtonEmpty euiButtonEmpty--text euiButtonEmpty--iconRight euiFilterButton testClass1 testClass2"
data-test-subj="test subject string"
type="button"
>
<span
class="euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text euiFilterButton__text-hasNotification"
>
<span
class="euiFilterButton__textShift"
/>
<span
class="euiNotificationBadge euiFilterButton__notification"
>
0
</span>
</span>
</span>
</button>
`;
6 changes: 4 additions & 2 deletions src/components/filter_group/filter_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export const EuiFilterButton = ({
className,
);

// != instead of !== to allow for null and undefined
const numFiltersDefined = numFilters != null;
const buttonTextClassNames = classNames(
{ 'euiFilterButton__text-hasNotification': numFilters, },
{ 'euiFilterButton__text-hasNotification': numFiltersDefined, },
textProps && textProps.className,
);

Expand All @@ -52,7 +54,7 @@ export const EuiFilterButton = ({
<span className="euiFilterButton__textShift" data-text={children}>
{children}
</span>
{numFilters &&
{numFiltersDefined &&
<EuiNotificationBadge className="euiFilterButton__notification">{numFilters}</EuiNotificationBadge>
}
</Fragment>
Expand Down
8 changes: 8 additions & 0 deletions src/components/filter_group/filter_button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ describe('EuiFilterButton', () => {
expect(component)
.toMatchSnapshot();
});

test('renders zero properly', () => {
const component = render(
<EuiFilterButton {...requiredProps} numFilters={0} />
);

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