Skip to content
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 @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what's doubly hilarious in retrospect, undefined > 0 and null > 0 both evaluate to false so there's actually no need for a numActiveFilters && in the first place 💀 I can simplify that if folks prefer here.

I still can't get over 0 && 0 > 0 evaluating to 0 tbh

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind keeping it as is. We don't have to think about what undefined > 0 and null > 0 evaluate to with the current logic.


const classes = classNames(
'euiFilterButton',
Expand Down