Skip to content

Commit 6b6c5e7

Browse files
authored
fix(avatars,modals,notifications): prevent dev console warnings (#2040)
1 parent a9820b7 commit 6b6c5e7

File tree

8 files changed

+43
-10
lines changed

8 files changed

+43
-10
lines changed

packages/avatars/demo/avatar.stories.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import README from '../README.md';
2121
name="Avatar"
2222
args={{ type: TYPE[1] }}
2323
argTypes={{
24+
'aria-hidden': { control: 'boolean' },
2425
backgroundColor: { control: 'color' },
2526
badge: { control: 'text' },
2627
foregroundColor: { control: 'color' },

packages/avatars/src/elements/Avatar.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ describe('Avatar', () => {
9595
expect(element).toBeInTheDocument();
9696
});
9797

98+
it('does not render status with `aria-hidden`', () => {
99+
const label = 'test status';
100+
const { queryByText } = render(
101+
<Avatar aria-hidden badge="0" statusLabel={label}>
102+
<img alt="" />
103+
</Avatar>
104+
);
105+
const element = queryByText(label);
106+
107+
expect(element).not.toBeInTheDocument();
108+
});
109+
98110
it('renders with status and applies default label for available status', () => {
99111
const { getByText } = render(
100112
<Avatar status="available">

packages/avatars/src/elements/Avatar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Text } from './components/Text';
2222
const AvatarComponent = forwardRef<HTMLElement, IAvatarProps>(
2323
(
2424
{
25+
'aria-hidden': ariaHidden,
2526
backgroundColor,
2627
badge,
2728
children,
@@ -59,7 +60,7 @@ const AvatarComponent = forwardRef<HTMLElement, IAvatarProps>(
5960
return ['status'].concat(statusMessage || []).join(': ');
6061
}, [computedStatus, badge]);
6162

62-
const shouldValidate = computedStatus !== undefined;
63+
const shouldValidate = computedStatus !== undefined && ariaHidden !== true;
6364
const label = useText(
6465
AvatarComponent,
6566
{ statusLabel },
@@ -78,6 +79,7 @@ const AvatarComponent = forwardRef<HTMLElement, IAvatarProps>(
7879
$backgroundColor={backgroundColor}
7980
$foregroundColor={foregroundColor}
8081
aria-atomic="true"
82+
aria-hidden={ariaHidden}
8183
aria-live="polite"
8284
{...other}
8385
>
@@ -89,7 +91,7 @@ const AvatarComponent = forwardRef<HTMLElement, IAvatarProps>(
8991
$surfaceColor={surfaceColor}
9092
as="figcaption"
9193
>
92-
<Span hidden>{label}</Span>
94+
{ariaHidden !== true && <Span hidden>{label}</Span>}
9395
{computedStatus === 'active' ? (
9496
<span aria-hidden>{badge}</span>
9597
) : (

packages/modals/src/elements/Close.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export const Close = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLButt
2626
return () => setIsCloseButtonPresent(false);
2727
});
2828

29-
const ariaLabel = useText(Close, props, 'aria-label', 'Close modal');
29+
const ariaLabel = useText(
30+
Close,
31+
props,
32+
'aria-label',
33+
'Close modal',
34+
props['aria-describedby'] === undefined /* has tooltip */
35+
);
3036

3137
return (
3238
<StyledClose

packages/modals/src/elements/Drawer/Close.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ const CloseComponent = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLBu
2121
return () => setIsCloseButtonPresent(false);
2222
});
2323

24-
const ariaLabel = useText(CloseComponent, props, 'aria-label', 'Close drawer');
24+
const ariaLabel = useText(
25+
CloseComponent,
26+
props,
27+
'aria-label',
28+
'Close drawer',
29+
props['aria-describedby'] === undefined /* has tooltip */
30+
);
2531

2632
return (
2733
<StyledDrawerClose

packages/modals/src/elements/TooltipDialog/Close.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ const CloseComponent = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLBu
1515
(props, ref) => {
1616
const { getCloseProps } = useTooltipDialogContext();
1717

18-
const ariaLabel = useText(CloseComponent, props, 'aria-label', 'Close tooltip');
18+
const ariaLabel = useText(
19+
CloseComponent,
20+
props,
21+
'aria-label',
22+
'Close tooltip',
23+
props['aria-describedby'] === undefined /* has tooltip */
24+
);
1925

2026
return (
2127
<StyledTooltipDialogClose

packages/notifications/src/elements/toaster/ToastSlot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const ToastSlot = ({ toasts, placement, zIndex, limit, ...props }: IToast
8888
>
8989
<StyledFadeInTransition
9090
ref={transitionRef}
91-
placement={placement}
91+
$placement={placement}
9292
$isHidden={isHidden(index)}
9393
>
9494
<Toast toast={toast} pauseTimers={pauseTimers || isHidden(index)} />

packages/notifications/src/elements/toaster/styled.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const TRANSITION_CLASS = 'garden-toast-transition';
1313

1414
const DEFAULT_DURATION = '400ms';
1515

16-
export const StyledFadeInTransition = styled.div<{ $isHidden: boolean; placement: Placement }>`
16+
export const StyledFadeInTransition = styled.div<{ $isHidden: boolean; $placement: Placement }>`
1717
transition: opacity ${DEFAULT_DURATION} ease-in 300ms;
1818
opacity: ${p => (p.$isHidden ? '0 !important' : 1)};
1919
margin-bottom: ${p => p.theme.space.base * 2}px;
@@ -24,9 +24,9 @@ export const StyledFadeInTransition = styled.div<{ $isHidden: boolean; placement
2424
transform: translateY(
2525
${props => {
2626
if (
27-
props.placement === 'bottom-start' ||
28-
props.placement === 'bottom' ||
29-
props.placement === 'bottom-end'
27+
props.$placement === 'bottom-start' ||
28+
props.$placement === 'bottom' ||
29+
props.$placement === 'bottom-end'
3030
) {
3131
return '100px';
3232
}

0 commit comments

Comments
 (0)