Skip to content

Commit fa1f577

Browse files
authored
fix(accordions): hide collapsed panel content (#1662)
1 parent 3533523 commit fa1f577

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

packages/accordions/src/elements/accordion/components/Panel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const PanelComponent = forwardRef<HTMLElement, HTMLAttributes<HTMLElement>>(
1919

2020
return (
2121
<StyledPanel
22+
inert={isExpanded ? undefined : ''}
2223
isAnimated={isAnimated}
2324
isBare={isBare}
2425
isCompact={isCompact}
@@ -30,7 +31,7 @@ const PanelComponent = forwardRef<HTMLElement, HTMLAttributes<HTMLElement>>(
3031
...props
3132
}) as HTMLAttributes<HTMLElement>)}
3233
>
33-
<StyledInnerPanel>{children}</StyledInnerPanel>
34+
<StyledInnerPanel isAnimated={isAnimated}>{children}</StyledInnerPanel>
3435
</StyledPanel>
3536
);
3637
}

packages/accordions/src/styled/accordion/StyledInnerPanel.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,31 @@
77

88
import styled from 'styled-components';
99
import { retrieveComponentStyles, DEFAULT_THEME } from '@zendeskgarden/react-theming';
10+
import { StyledPanel } from './StyledPanel';
1011

1112
const COMPONENT_ID = 'accordions.step_inner_panel';
1213

14+
interface IStyledInnerPanel {
15+
isAnimated?: boolean;
16+
}
17+
1318
export const StyledInnerPanel = styled.div.attrs({
1419
'data-garden-id': COMPONENT_ID,
1520
'data-garden-version': PACKAGE_VERSION
16-
})`
21+
})<IStyledInnerPanel>`
1722
overflow: hidden;
1823
line-height: inherit;
1924
font-size: inherit;
2025
26+
${StyledPanel}[aria-hidden='true'] > & {
27+
transition: ${props => props.isAnimated && 'visibility 0s 0.25s'};
28+
visibility: hidden;
29+
}
30+
31+
${StyledPanel}[aria-hidden='false'] > & {
32+
visibility: visible;
33+
}
34+
2135
${props => retrieveComponentStyles(COMPONENT_ID, props)};
2236
`;
2337

packages/accordions/src/styled/accordion/StyledPanel.spec.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ describe('StyledPanel', () => {
1616

1717
expect(container.firstChild).toHaveStyleRule('grid-template-rows', '0fr');
1818
expect(container.firstChild).toHaveStyleRule('padding', '8px 20px 32px');
19-
expect(container.firstChild).toHaveStyleRule(
20-
'border-bottom-width',
21-
`${DEFAULT_THEME.borderWidths.sm}`
22-
);
19+
expect(container.firstChild).toHaveStyleRule('border-bottom', `${DEFAULT_THEME.borders.sm}`);
2320
expect(container.firstChild).toHaveStyleRule(
2421
'border-bottom-color',
2522
`${getColor('neutralHue', 300, DEFAULT_THEME)}`
@@ -53,10 +50,7 @@ describe('StyledPanel', () => {
5350
it('renders isBare styling correctly', () => {
5451
const { container } = render(<StyledPanel isBare />);
5552

56-
expect(container.firstChild).toHaveStyleRule(
57-
'border-bottom-width',
58-
`${DEFAULT_THEME.borderWidths.sm}`
59-
);
53+
expect(container.firstChild).toHaveStyleRule('border-bottom', `${DEFAULT_THEME.borders.sm}`);
6054
expect(container.firstChild).toHaveStyleRule('border-bottom-color', 'transparent');
6155
});
6256

packages/accordions/src/styled/accordion/StyledPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@zendeskgarden/react-theming';
1515

1616
interface IStyledPanel {
17+
inert?: string;
1718
isBare?: boolean;
1819
isCompact?: boolean;
1920
isExpanded?: boolean;
@@ -50,8 +51,7 @@ const sizeStyles = (props: IStyledPanel & ThemeProps<DefaultTheme>) => {
5051

5152
return css`
5253
grid-template-rows: ${isExpanded ? 1 : 0}fr;
53-
border-bottom-width: ${theme.borderWidths.sm};
54-
border-bottom-style: solid;
54+
border-bottom: ${theme.borders.sm};
5555
padding: ${paddingTop}px ${paddingHorizontal}px ${paddingBottom}px;
5656
line-height: ${getLineHeight(base * 5, theme.fontSizes.md)};
5757
font-size: ${theme.fontSizes.md};

0 commit comments

Comments
 (0)