Skip to content

Commit

Permalink
fix: CounterBadge now always renders its children if provided (#24916)
Browse files Browse the repository at this point in the history
  • Loading branch information
behowell authored Sep 29, 2022
1 parent 9c2ca0d commit 0885025
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: CounterBadge now always renders its children if provided",
"packageName": "@fluentui/react-badge",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
exports[`CounterBadge renders a default state 1`] = `
<div
className="fui-Badge fui-CounterBadge"
>
0
</div>
/>
`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import type { BadgeState } from '../Badge/index';
import { useBadge_unstable } from '../Badge/index';
import type { CounterBadgeProps, CounterBadgeState } from './CounterBadge.types';

Expand All @@ -16,16 +17,16 @@ export const useCounterBadge_unstable = (props: CounterBadgeProps, ref: React.Re
} = props;

const state: CounterBadgeState = {
...(useBadge_unstable(props, ref) as CounterBadgeState),
...(useBadge_unstable(props, ref) as Pick<CounterBadgeState, keyof BadgeState>),
shape,
appearance,
showZero,
count,
dot,
};

if (!state.dot && !state.root.children) {
state.root.children = state.count > overflowCount ? `${overflowCount}+` : `${state.count}`;
if ((count !== 0 || showZero) && !dot && !state.root.children) {
state.root.children = count > overflowCount ? `${overflowCount}+` : `${count}`;
}

return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useCounterBadgeStyles_unstable = (state: CounterBadgeState): Counte
state.root.className = mergeClasses(
counterBadgeClassNames.root,
state.dot && styles.dot,
!state.showZero && state.count === 0 && !state.dot && styles.hide,
!state.root.children && !state.dot && styles.hide,
state.root.className,
);

Expand Down

0 comments on commit 0885025

Please sign in to comment.