Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/eui/changelogs/upcoming/8327.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated `EuiAccordion` to prevent content from being transitioned on initial render when `initialIsOpen=true`

Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ exports[`EuiAccordion props initialIsOpen is rendered 1`] = `
</div>
<div
aria-labelledby="generated-id"
class="euiAccordion__childWrapper emotion-euiAccordion__childWrapper-isOpen"
class="euiAccordion__childWrapper emotion-euiAccordion__childWrapper-isOpen-noTransition"
id="12"
role="group"
style="block-size: 0;"
Expand Down
1 change: 1 addition & 0 deletions packages/eui/src/components/accordion/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export class EuiAccordionClass extends Component<
isLoading={isLoading}
isLoadingMessage={isLoadingMessage}
isOpen={this.isOpen}
initialIsOpen={initialIsOpen}
>
{children}
</EuiAccordionChildren>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export const euiAccordionChildWrapperStyles = (
users on Chrome & FF */
${euiFocusRing(euiThemeContext)}
`,
// choosing to override transition instead of applying it conditionally
// to keep a more logical style appliance:
// default case = has transition as part of default styles (all cases expect initial isOpen=true when initialIsOpen=true)
// special case: no transition for initial isOpen=true when initialIsOpen=true
noTransition: css`
${euiCanAnimate} {
transition: none;
}
`,
isClosed: css`
${logicalCSS('height', 0)}
opacity: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, {
FunctionComponent,
HTMLAttributes,
useCallback,
useEffect,
useMemo,
useState,
} from 'react';
Expand All @@ -28,7 +29,12 @@ import {
type _EuiAccordionChildrenProps = HTMLAttributes<HTMLDivElement> &
Pick<
EuiAccordionProps,
'role' | 'children' | 'paddingSize' | 'isLoading' | 'isLoadingMessage'
| 'role'
| 'children'
| 'paddingSize'
| 'initialIsOpen'
| 'isLoading'
| 'isLoadingMessage'
> & {
isOpen: boolean;
};
Expand All @@ -41,6 +47,7 @@ export const EuiAccordionChildren: FunctionComponent<
isLoading,
isLoadingMessage,
isOpen,
initialIsOpen,
...rest
}) => {
/**
Expand All @@ -61,12 +68,22 @@ export const EuiAccordionChildren: FunctionComponent<
/**
* Wrapper
*/
const [hasTransition, setHasTransition] = useState(false);
const wrapperStyles = euiAccordionChildWrapperStyles(euiTheme);
const wrapperCssStyles = [
wrapperStyles.euiAccordion__childWrapper,
isOpen ? wrapperStyles.isOpen : wrapperStyles.isClosed,
initialIsOpen && !hasTransition && isOpen && wrapperStyles.noTransition,
];

/* Controls enabling opening/closing transitions on first interaction
when initialIsOpen=true; this only runs once */
useEffect(() => {
if (initialIsOpen && !isOpen && !hasTransition) {
setHasTransition(true);
}
}, [isOpen, initialIsOpen, hasTransition]);

/**
* Update the accordion wrapper height whenever the accordion opens, and also
* whenever the child content updates (which will change the height)
Expand Down