Skip to content

Commit fdbd3f9

Browse files
fix(accordions): allow dynamic height for stepper content (#1570)
1 parent 6553eae commit fdbd3f9

File tree

4 files changed

+21
-56
lines changed

4 files changed

+21
-56
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"index.esm.js": {
3-
"bundled": 35205,
4-
"minified": 25722,
5-
"gzipped": 5726,
3+
"bundled": 34406,
4+
"minified": 25373,
5+
"gzipped": 5671,
66
"treeshaked": {
77
"rollup": {
8-
"code": 19976,
8+
"code": 19685,
99
"import_statements": 683
1010
},
1111
"webpack": {
12-
"code": 22211
12+
"code": 21848
1313
}
1414
}
1515
},
1616
"index.cjs.js": {
17-
"bundled": 38108,
18-
"minified": 28376,
19-
"gzipped": 5959
17+
"bundled": 37237,
18+
"minified": 27955,
19+
"gzipped": 5905
2020
}
2121
}

packages/accordions/src/elements/stepper/components/Content.tsx

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,20 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import React, { forwardRef, useRef, useEffect, useContext, HTMLAttributes } from 'react';
9-
import mergeRefs from 'react-merge-refs';
10-
import debounce from 'lodash.debounce';
11-
import { ThemeContext } from 'styled-components';
12-
import { useDocument } from '@zendeskgarden/react-theming';
8+
import React, { forwardRef, HTMLAttributes } from 'react';
139

1410
import { StyledContent, StyledInnerContent } from '../../../styled';
1511
import { useStepContext, useStepperContext } from '../../../utils';
1612

1713
const ContentComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
1814
(props, ref) => {
19-
const contentRef = useRef<HTMLDivElement>();
2015
const { activeIndex, isHorizontal } = useStepperContext();
2116
const { currentStepIndex } = useStepContext();
2217
const isActive = currentStepIndex === activeIndex;
2318

24-
const theme = useContext(ThemeContext);
25-
const environment = useDocument(theme);
26-
27-
useEffect(() => {
28-
if (environment && isActive && isHorizontal === false) {
29-
const win = environment.defaultView! || window;
30-
31-
const updateMaxHeight = debounce(() => {
32-
if (contentRef.current) {
33-
const child = contentRef.current.children[0] as any;
34-
35-
child.style.maxHeight = `${child.scrollHeight}px`;
36-
}
37-
}, 100);
38-
39-
win.addEventListener('resize', updateMaxHeight);
40-
updateMaxHeight();
41-
42-
return () => {
43-
updateMaxHeight.cancel();
44-
win.removeEventListener('resize', updateMaxHeight);
45-
};
46-
}
47-
48-
return undefined;
49-
}, [isActive, isHorizontal, contentRef, environment]);
50-
5119
return isHorizontal === false ? (
52-
<StyledContent ref={mergeRefs([contentRef, ref])} isActive={isActive} {...props}>
53-
<StyledInnerContent isActive={isActive} aria-hidden={!isActive}>
54-
{props.children}
55-
</StyledInnerContent>
20+
<StyledContent ref={ref} isActive={isActive} {...props}>
21+
<StyledInnerContent aria-hidden={!isActive}>{props.children}</StyledInnerContent>
5622
</StyledContent>
5723
) : null;
5824
}

packages/accordions/src/styled/stepper/StyledContent.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ const sizeStyles = (props: IStyledContent & ThemeProps<DefaultTheme>) => {
2626
return css`
2727
margin: ${marginVertical}px ${marginRight}px ${marginVertical}px ${marginLeft}px;
2828
padding: 0 ${paddingRight}px ${paddingBottom}px ${paddingLeft}px;
29+
min-width: ${space.base * 30}px;
30+
height: auto;
2931
`;
3032
};
3133

3234
export const StyledContent = styled.div.attrs<IStyledContent>({
3335
'data-garden-id': COMPONENT_ID,
3436
'data-garden-version': PACKAGE_VERSION
3537
})<IStyledContent>`
36-
${sizeStyles}
37-
min-width: ${props => props.theme.space.base * 30}px;
38+
display: grid;
39+
grid-template-rows: ${props => (props.isActive ? 1 : 0)}fr;
40+
transition: grid-template-rows 0.25s ease-in-out;
3841
word-break: break-word;
3942
43+
${sizeStyles}
44+
4045
${props => retrieveComponentStyles(COMPONENT_ID, props)};
4146
`;
4247

packages/accordions/src/styled/stepper/StyledInnerContent.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import styled from 'styled-components';
8+
import styled, { ThemeProps, DefaultTheme } from 'styled-components';
99
import {
1010
getLineHeight,
1111
retrieveComponentStyles,
@@ -14,17 +14,11 @@ import {
1414

1515
const COMPONENT_ID = 'accordions.step_inner_content';
1616

17-
interface IStyledInnerContent {
18-
isActive?: boolean;
19-
}
20-
21-
export const StyledInnerContent = styled.div.attrs<IStyledInnerContent>({
17+
export const StyledInnerContent = styled.div.attrs<ThemeProps<DefaultTheme>>({
2218
'data-garden-id': COMPONENT_ID,
2319
'data-garden-version': PACKAGE_VERSION
24-
})<IStyledInnerContent>`
25-
transition: max-height 0.25s ease-in-out;
20+
})`
2621
overflow: hidden;
27-
max-height: ${props => !props.isActive && '0 !important'}; /* stylelint-disable-line */
2822
line-height: ${props => getLineHeight(props.theme.space.base * 5, props.theme.fontSizes.md)};
2923
color: ${props => props.theme.colors.foreground};
3024
font-size: ${props => props.theme.fontSizes.md};

0 commit comments

Comments
 (0)