Skip to content

Commit 842db5b

Browse files
committed
fix: Collapse overlay now shows no matter the z-index of the children
1 parent 3ae06f0 commit 842db5b

File tree

2 files changed

+54
-21
lines changed

2 files changed

+54
-21
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"license": "MIT",
44
"name": "react-collapse-pane",
55
"repository": "https://github.com/b-zurg/react-collapse-pane",
6+
"homepage": "https://collapse-pane.zurg.dev",
7+
"bugs": "https://github.com/b-zurg/react-collapse-pane/issues",
8+
"description": "The splittable, draggable and collapsible react layout library.",
69
"author": "Buzurgmehr Arjmandi",
710
"module": "dist/react-collapse-pane.esm.js",
811
"main": "dist/index.js",
912
"typings": "dist/index.d.ts",
1013
"files": [
11-
"dist",
12-
"src"
14+
"dist"
1315
],
1416
"keywords": [
1517
"react",

src/components/Pane.tsx

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,53 @@ const horizontalCss = css`
1313
width: 100%;
1414
height: 0;
1515
`;
16-
const StyledDiv = styled.div<{ isVertical: boolean; shouldAnimate: boolean; timeout: number }>`
16+
const coverCss = css`
17+
position: absolute;
18+
top: 0;
19+
bottom: 0;
20+
left: 0;
21+
right: 0;
22+
`;
23+
24+
interface PaneRootProps {
25+
$isVertical: boolean;
26+
$shouldAnimate: boolean;
27+
$timeout: number;
28+
}
29+
const PaneRoot = styled.div<PaneRootProps>`
1730
position: relative;
1831
outline: none;
1932
border: 0;
2033
overflow: hidden;
2134
display: flex;
2235
flex-grow: 1;
2336
flex-shrink: 1;
24-
${props => (props.isVertical ? verticalCss : horizontalCss)}
25-
${props => props.shouldAnimate && `transition: flex-basis ${props.timeout}ms ease-in-out`}
37+
${props => (props.$isVertical ? verticalCss : horizontalCss)}
38+
${props => props.$shouldAnimate && `transition: flex-basis ${props.$timeout}ms ease-in-out`}
2639
`;
27-
const CollapseOverlay = styled.div`
28-
position: absolute;
29-
top: 0;
30-
bottom: 0;
31-
left: 0;
32-
right: 0;
40+
const WidthPreserver = styled.div<{ $isCollapsed: boolean }>`
41+
${coverCss}
42+
${props =>
43+
props.$isCollapsed &&
44+
css`
45+
* {
46+
z-index: 0;
47+
}
48+
z-index: 0;
49+
`}
50+
`;
51+
52+
const CollapseOverlay = styled.div<{ $timeout: number; $isCollapsed: boolean }>`
53+
${props => props.$isCollapsed && coverCss}
54+
${props =>
55+
props.$isCollapsed &&
56+
css`
57+
z-index: 1;
58+
`};
59+
opacity: ${props => (props.$isCollapsed ? 1 : 0)};
60+
transition: opacity ${props => props.$timeout}ms ease-in-out;
3361
`;
62+
3463
export interface PaneProps {
3564
size: number;
3665
minSize: number;
@@ -59,7 +88,7 @@ const UnMemoizedPane = ({
5988
const timeout = useMemo(() => transitionTimeout ?? DEFAULT_COLLAPSE_TRANSITION_TIMEOUT, [
6089
transitionTimeout,
6190
]);
62-
const [shouldAnimate, setShouldAnimate] = useState<boolean>(false);
91+
const [shouldAnimate, setShouldAnimate] = useState(false);
6392

6493
const didMount = useRef(false);
6594

@@ -78,21 +107,23 @@ const UnMemoizedPane = ({
78107
() => (split === 'vertical' ? { minWidth: minSize } : { minHeight: minSize }),
79108
[minSize, split]
80109
);
81-
const userSelect: React.CSSProperties = { userSelect: 'none' };
82-
const collapseOverlayStyle: React.CSSProperties = isCollapsed
83-
? { ...collapseOverlayCss, ...minStyle, ...userSelect }
110+
const widthPreserverStyle: React.CSSProperties = isCollapsed
111+
? { ...minStyle, userSelect: 'none' }
84112
: minStyle;
85113
return (
86-
<StyledDiv
87-
isVertical={split === 'vertical'}
114+
<PaneRoot
115+
$isVertical={split === 'vertical'}
116+
$shouldAnimate={timeout !== 0 && shouldAnimate}
117+
$timeout={timeout}
88118
className={classes}
89119
ref={forwardRef}
90120
style={{ flexBasis: size }}
91-
shouldAnimate={timeout !== 0 && shouldAnimate}
92-
timeout={timeout}
93121
>
94-
<CollapseOverlay style={collapseOverlayStyle}>{children}</CollapseOverlay>
95-
</StyledDiv>
122+
<CollapseOverlay $isCollapsed={isCollapsed} $timeout={timeout} style={collapseOverlayCss} />
123+
<WidthPreserver $isCollapsed={isCollapsed} style={widthPreserverStyle}>
124+
{children}
125+
</WidthPreserver>
126+
</PaneRoot>
96127
);
97128
};
98129

0 commit comments

Comments
 (0)