Skip to content

Commit 37103e8

Browse files
committed
fix: Prevent styled component props from propagating to DOM
1 parent fc714ab commit 37103e8

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/components/Resizer/helpers.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled, { css } from 'styled-components';
22

33
type OrientationProps = {
4-
isVertical: boolean;
4+
$isVertical: boolean;
55
};
66
export const topBottomCss = css`
77
top: 0;
@@ -23,10 +23,10 @@ interface ButtonContainerProps extends OrientationProps {
2323
}
2424
export const ButtonContainer = styled.div<ButtonContainerProps>`
2525
position: absolute;
26-
${props => (props.isVertical ? topBottomCss : leftRightCss)}
27-
${props => (props.isVertical ? 'width: 5rem' : 'height: 5rem')};
26+
${props => (props.$isVertical ? topBottomCss : leftRightCss)}
27+
${props => (props.$isVertical ? 'width: 5rem' : 'height: 5rem')};
2828
transform: ${props =>
29-
props.isVertical
29+
props.$isVertical
3030
? `translateX(${props.isLtr ? '-' : ''}50%) ${
3131
props.grabberSize ? `translateX(calc(${props.grabberSize} / 2))` : ''
3232
}`
@@ -41,18 +41,21 @@ export const ButtonContainer = styled.div<ButtonContainerProps>`
4141
justify-content: center;
4242
`;
4343

44-
export const ResizeGrabber = styled.div<OrientationProps>`
44+
interface GrabberProps extends OrientationProps {
45+
$isCollapsed: boolean;
46+
}
47+
export const ResizeGrabber = styled.div<GrabberProps>`
4548
position: absolute;
4649
z-index: 3;
47-
transform: ${props => (props.isVertical ? 'translateX(-50%)' : 'translateY(-50%)')};
48-
cursor: ${props => (props.isVertical ? 'col-resize' : 'row-resize')};
49-
${props => (props.isVertical ? topBottomCss : leftRightCss)}
50+
transform: ${props => (props.$isVertical ? 'translateX(-50%)' : 'translateY(-50%)')};
51+
cursor: ${props => !props.$isCollapsed && (props.$isVertical ? 'col-resize' : 'row-resize')};
52+
${props => (props.$isVertical ? topBottomCss : leftRightCss)}
5053
`;
5154

52-
export const ResizePresentation = styled.div<{ isVertical: boolean }>`
55+
export const ResizePresentation = styled.div<OrientationProps>`
5356
z-index: 2;
5457
position: absolute;
55-
${props => (props.isVertical ? topBottomCss : leftRightCss)}
58+
${props => (props.$isVertical ? topBottomCss : leftRightCss)}
5659
`;
5760

5861
export const getSizeWithUnit = (size: string | number): string =>

src/components/Resizer/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ export const Resizer = ({
103103
[collapseOptions]
104104
);
105105
const collapseButton = collapseOptions ? (
106-
<ButtonContainer isVertical={isVertical} grabberSize={grabberSizeWithUnit} isLtr={isLtr}>
106+
<ButtonContainer $isVertical={isVertical} grabberSize={grabberSizeWithUnit} isLtr={isLtr}>
107107
<ButtonPositionOffset style={{ flexBasis: preButtonFlex }} />
108108
<Transition
109109
in={isHovered}
110110
timeout={collapseOptions.buttonTransitionTimeout}
111111
style={{ flex: '0 0 0', position: 'relative' }}
112112
>
113113
<ButtonWrapper
114-
isVertical={isVertical}
114+
$isVertical={isVertical}
115115
onClick={handleButtonClick}
116116
onMouseDown={handleButtonMousedown}
117117
>
@@ -125,7 +125,8 @@ export const Resizer = ({
125125
return (
126126
<div style={{ position: 'relative' }}>
127127
<ResizeGrabber
128-
isVertical={isVertical}
128+
$isVertical={isVertical}
129+
$isCollapsed={isCollapsed}
129130
style={getWidthOrHeight(grabberSize)}
130131
role="presentation"
131132
className={classes}
@@ -137,11 +138,11 @@ export const Resizer = ({
137138
{collapseButton}
138139
</ResizeGrabber>
139140
<Fade in={!isHovered}>
140-
<ResizePresentation isVertical={isVertical} style={{ ...getWidthOrHeight(1), ...css }} />
141+
<ResizePresentation $isVertical={isVertical} style={{ ...getWidthOrHeight(1), ...css }} />
141142
</Fade>
142143
<Fade in={isHovered}>
143144
<ResizePresentation
144-
isVertical={isVertical}
145+
$isVertical={isVertical}
145146
style={{ ...getWidthOrHeight(1), ...hoverCss }}
146147
/>
147148
</Fade>

0 commit comments

Comments
 (0)