diff --git a/packages/ibm-products/src/components/CreateSidePanel/CreateSidePanel.js b/packages/ibm-products/src/components/CreateSidePanel/CreateSidePanel.js
index 0ad8133759..601d69d3c1 100644
--- a/packages/ibm-products/src/components/CreateSidePanel/CreateSidePanel.js
+++ b/packages/ibm-products/src/components/CreateSidePanel/CreateSidePanel.js
@@ -38,6 +38,7 @@ export let CreateSidePanel = React.forwardRef(
disableSubmit,
formTitle,
formDescription,
+ id,
onRequestClose,
onRequestSubmit,
open,
@@ -76,6 +77,7 @@ export let CreateSidePanel = React.forwardRef(
test
) =>
<>
{
>
{
setOpen(false)}
onRequestSubmit={() => setOpen(false)}
diff --git a/packages/ibm-products/src/components/EditSidePanel/EditSidePanel.test.js b/packages/ibm-products/src/components/EditSidePanel/EditSidePanel.test.js
index 0524fc6a27..1afca380ae 100644
--- a/packages/ibm-products/src/components/EditSidePanel/EditSidePanel.test.js
+++ b/packages/ibm-products/src/components/EditSidePanel/EditSidePanel.test.js
@@ -34,6 +34,7 @@ const renderEditPanel = ({ ...rest } = {}, children = childrenContent) =>
render(
{
@@ -148,7 +149,7 @@ export let SidePanel = React.forwardRef(
useEffect(() => {
if (open && actions && actions.length && animationComplete) {
- const sidePanelOuter = document.querySelector(`#${blockClass}-outer`);
+ const sidePanelOuter = document.querySelector(`#${id}`);
const actionsContainer = getActionsContainerElement();
let actionsHeight = actionsContainer?.offsetHeight + 16; // add additional 1rem spacing to bottom padding
actionsHeight = `${Math.round(actionsHeight / 16)}rem`;
@@ -157,7 +158,14 @@ export let SidePanel = React.forwardRef(
actionsHeight
);
}
- }, [actions, condensedActions, open, animationComplete]);
+ }, [
+ actions,
+ condensedActions,
+ open,
+ animationComplete,
+ id,
+ getActionsContainerElement,
+ ]);
// Add console warning if labelText is provided without a title.
// This combination is not allowed.
@@ -172,7 +180,7 @@ export let SidePanel = React.forwardRef(
/* istanbul ignore next */
const handleResize = ({ height }) => {
setPanelHeight(height);
- const sidePanelOuter = document.querySelector(`#${blockClass}-outer`);
+ const sidePanelOuter = document.querySelector(`#${id}`);
const actionsContainer = getActionsContainerElement();
let actionsHeight = actionsContainer?.offsetHeight + 16; // add additional 1rem spacing to bottom padding
actionsHeight = `${Math.round(actionsHeight / 16)}rem`;
@@ -182,13 +190,13 @@ export let SidePanel = React.forwardRef(
);
};
- const getActionsContainerElement = () => {
- const sidePanelOuter = document.querySelector(`#${blockClass}-outer`);
+ const getActionsContainerElement = useCallback(() => {
+ const sidePanelOuter = document.querySelector(`#${id}`);
return (
sidePanelOuter &&
sidePanelOuter.querySelector(`.${blockClass}__actions-container`)
);
- };
+ }, [id]);
// Title and subtitle scroll animation
useEffect(() => {
@@ -200,9 +208,9 @@ export let SidePanel = React.forwardRef(
title.length &&
!reducedMotion.matches
) {
- const sidePanelOuter = document.querySelector(`#${blockClass}-outer`);
+ const sidePanelOuter = document.querySelector(`#${id}`);
const sidePanelScrollArea = document.querySelector(
- `#${blockClass}-outer .${blockClass}__inner-content`
+ `#${id} .${blockClass}__inner-content`
);
const sidePanelTitleElement = document.querySelector(
`.${blockClass}__title-text`
@@ -371,7 +379,7 @@ export let SidePanel = React.forwardRef(
});
}
if (open && !animateTitle) {
- const sidePanelOuter = document.querySelector(`#${blockClass}-outer`);
+ const sidePanelOuter = document.querySelector(`#${id}`);
const sidePanelTitleElement = document.querySelector(
`.${blockClass}__title-container .${blockClass}__title-text`
);
@@ -413,6 +421,7 @@ export let SidePanel = React.forwardRef(
title,
size,
reducedMotion.matches,
+ id,
]);
// click outside functionality if `includeOverlay` prop is set
@@ -714,7 +723,7 @@ export let SidePanel = React.forwardRef(
investigate incident management within this side panel.
>
),
+ id: 'storybook-sidepanel',
};
const headerData = [
diff --git a/packages/ibm-products/src/components/SidePanel/SidePanel.test.js b/packages/ibm-products/src/components/SidePanel/SidePanel.test.js
index c1a13ce2fc..611bdaa4f4 100644
--- a/packages/ibm-products/src/components/SidePanel/SidePanel.test.js
+++ b/packages/ibm-products/src/components/SidePanel/SidePanel.test.js
@@ -35,6 +35,7 @@ const onUnmountFn = jest.fn();
const renderSidePanel = ({ ...rest } = {}, children = test
) =>
render(
{
includeOverlay
open={false}
onRequestClose={onRequestCloseFn}
+ id="sidepanel-id"
>
Content