Skip to content

Commit fbe9eed

Browse files
authored
refactor: avoid rendering button inside button (#4968)
Color thumb should be a button only inside of color picker when it is clickable. In case of repeated style it is just a visual indicator. This fixes huge react warnings about button rendered inside of another button.
1 parent af98a41 commit fbe9eed

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

apps/builder/app/builder/features/style-panel/shared/color-picker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export const ColorPopover = ({
216216
<ColorThumb
217217
color={styleValueToRgbaColor(value)}
218218
css={{ margin: theme.spacing[2] }}
219+
interactive={true}
219220
tabIndex={-1}
220221
/>
221222
</PopoverTrigger>

apps/builder/app/builder/features/style-panel/shared/color-thumb.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,25 @@ const thumbStyle = css({
5858
},
5959
});
6060

61-
type Props = Omit<ComponentProps<"button">, "color"> & {
61+
type Props = Omit<ComponentProps<"button" | "span">, "color"> & {
62+
interactive?: boolean;
6263
color?: RgbaColor;
6364
css?: CSS;
6465
};
6566

6667
export const ColorThumb = forwardRef<ElementRef<"button">, Props>(
67-
({ color = transparentColor, css, ...rest }, ref) => {
68+
({ interactive, color = transparentColor, css, ...rest }, ref) => {
6869
const background =
6970
color === undefined || color.a < 1
7071
? // Chessboard pattern 5x5
7172
`repeating-conic-gradient(rgba(0,0,0,0.22) 0% 25%, transparent 0% 50%) 0% 33.33% / 40% 40%, ${colord(color).toRgbString()}`
7273
: colord(color).toRgbString();
7374
const borderColor = calcBorderColor(color);
7475

76+
const Component = interactive ? "button" : "span";
77+
7578
return (
76-
<button
79+
<Component
7780
{...rest}
7881
ref={ref}
7982
style={{

0 commit comments

Comments
 (0)