Skip to content

Commit

Permalink
[EuiFilterButton] Fix unstyled '0' content when numFilters is undefin…
Browse files Browse the repository at this point in the history
…ed (#5268)

* [EuiFilterButton] Fix unstyled '0' content when numFilters is undefined

- showBadge was evaluating as '0' because numActiveFilters was evaluating as 0
- if numActiveFilters was 0 (0 && 0 > 0) validated as 0 :/ just JS things

* Add changelog entry
  • Loading branch information
Constance authored Oct 13, 2021
1 parent f865e2a commit 2c29fc1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
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**

- Fixed `SuperDatePicker` from crashing due to invalid time input ([#5263](https://github.com/elastic/eui/pull/5263))
- Fixed content in `EuiFilterButton` again when `numFilters` is undefined ([#5268](https://github.com/elastic/eui/pull/5268))

## [`39.1.0`](https://github.com/elastic/eui/tree/v39.1.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,24 @@ exports[`EuiFilterButton renders zero properly 1`] = `
</span>
</button>
`;

exports[`EuiFilterButton does not render a badge or count if numFilters is not passed 1`] = `
<button
aria-label="aria-label"
class="euiButtonEmpty euiButtonEmpty--text euiFilterButton testClass1 testClass2"
data-test-subj="test subject string"
type="button"
>
<span
class="euiButtonContent euiButtonContent--iconRight euiButtonEmpty__content"
>
<span
class="euiButtonEmpty__text"
>
<span
class="euiFilterButton__textShift"
/>
</span>
</span>
</button>
`;
10 changes: 9 additions & 1 deletion src/components/filter_group/filter_button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ describe('EuiFilterButton', () => {

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

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

test('does not render a badge or count if numFilters is not passed', () => {
const component = render(
<EuiFilterButton {...requiredProps} numActiveFilters={0} />
);

expect(component).toMatchSnapshot();
Expand Down
3 changes: 2 additions & 1 deletion src/components/filter_group/filter_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
...rest
}) => {
const numFiltersDefined = numFilters != null; // != instead of !== to allow for null and undefined
const numActiveFiltersDefined = numActiveFilters && numActiveFilters > 0;
const numActiveFiltersDefined =
numActiveFilters != null && numActiveFilters > 0;

const classes = classNames(
'euiFilterButton',
Expand Down

0 comments on commit 2c29fc1

Please sign in to comment.