Skip to content

Commit

Permalink
fix(SidePanel): resolve storybook SlideOver animation flickering in d…
Browse files Browse the repository at this point in the history
…oc page (#6554)

* refactor(useFocus): refactor repeated useEffect code

* fix(SidePanel): resolve storybook flickering issue

* fix(SidePanel): resolve storybook flickering issue
  • Loading branch information
makafsal authored Dec 23, 2024
1 parent 660c98a commit 03c31fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { StoryDocsPage } from '../../global/js/utils/StoryDocsPage';

import * as stories from './SidePanel';
import * as stories from './SidePanel.stories';

const DocsPage = () => (
<StoryDocsPage
Expand Down
34 changes: 16 additions & 18 deletions packages/ibm-products/src/components/SidePanel/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export let SidePanel = React.forwardRef(
if (!open) {
onUnmount?.();
}
setAnimationComplete(true);
setAnimationComplete(!animationComplete);
};

// Set the internal state `animationComplete` to true if
Expand Down Expand Up @@ -631,26 +631,24 @@ export let SidePanel = React.forwardRef(
]);

useEffect(() => {
if (open) {
setTimeout(() => {
if (open && animationComplete) {
if (
selectorPrimaryFocus &&
getSpecificElement(sidePanelRef?.current, selectorPrimaryFocus)
) {
const primeFocusEl = getSpecificElement(
sidePanelRef?.current,
selectorPrimaryFocus
);
if (
selectorPrimaryFocus &&
getSpecificElement(sidePanelRef?.current, selectorPrimaryFocus)
primeFocusEl &&
window?.getComputedStyle(primeFocusEl)?.display !== 'none'
) {
const primeFocusEl = getSpecificElement(
sidePanelRef?.current,
selectorPrimaryFocus
);
if (
primeFocusEl &&
window?.getComputedStyle(primeFocusEl)?.display !== 'none'
) {
(primeFocusEl as HTMLElement)?.focus();
}
} else if (!slideIn) {
firstElement?.focus();
setTimeout(() => primeFocusEl?.focus(), 0);
}
}, 0);
} else if (!slideIn) {
setTimeout(() => firstElement?.focus(), 0);
}
}
}, [
animationComplete,
Expand Down

0 comments on commit 03c31fc

Please sign in to comment.