Skip to content

Commit 2087181

Browse files
committed
Refactor Badge and ExpandablePanel components for improved accessibility and performance
1 parent a1d9ac6 commit 2087181

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

packages/ui/src/components/Badge.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ const getColor = (color: BadgeColor) => {
2323
}
2424
}
2525

26-
export const Badge: React.FC<BadgeProps> = ({
27-
color = "primary",
28-
invisible = false,
29-
children
30-
}) => {
26+
export const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(({
27+
color = "primary",
28+
invisible = false,
29+
children
30+
}, ref) => {
3131
return (
32-
<div className="relative inline-block w-fit">
32+
<div ref={ref} className="relative inline-block w-fit">
3333
{children}
3434
<span
3535
className={`absolute top-0.5 right-0.5 transform translate-x-1/2 -translate-y-1/2 rounded-full
@@ -39,4 +39,6 @@ export const Badge: React.FC<BadgeProps> = ({
3939
/>
4040
</div>
4141
);
42-
}
42+
});
43+
44+
Badge.displayName = "Badge";

packages/ui/src/components/ExpandablePanel.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,25 @@ export function ExpandablePanel({
9191
setOpen(updatedOpen);
9292
}}>
9393

94-
<Collapsible.Trigger
95-
className={cls(
96-
"rounded-t flex items-center justify-between w-full min-h-[52px]",
97-
"hover:bg-surface-accent-200 hover:bg-opacity-40 dark:hover:bg-surface-800 dark:hover:bg-opacity-40",
98-
invisible ? "border-b px-2" : "p-4",
99-
open ? "py-6" : "py-4",
100-
"transition-all duration-200",
101-
invisible && defaultBorderMixin,
102-
asField && fieldBackgroundMixin,
103-
titleClassName
104-
)}
105-
>
106-
{title}
107-
<KeyboardArrowDownIcon className={cls("transition", open ? "rotate-180" : "")}/>
94+
<Collapsible.Trigger asChild>
95+
<div
96+
className={cls(
97+
"rounded-t flex items-center justify-between w-full min-h-[52px]",
98+
"hover:bg-surface-accent-200 hover:bg-opacity-40 dark:hover:bg-surface-800 dark:hover:bg-opacity-40",
99+
invisible ? "border-b px-2" : "p-4",
100+
open ? "py-6" : "py-4",
101+
"transition-all duration-200",
102+
invisible && defaultBorderMixin,
103+
asField && fieldBackgroundMixin,
104+
titleClassName,
105+
"cursor-pointer"
106+
)}
107+
role="button"
108+
tabIndex={0}
109+
>
110+
{title}
111+
<KeyboardArrowDownIcon className={cls("transition", open ? "rotate-180" : "")}/>
112+
</div>
108113
</Collapsible.Trigger>
109114

110115
<Collapsible.Content

0 commit comments

Comments
 (0)