Skip to content

Commit

Permalink
fix(callout): fix callout expand in production (#736)
Browse files Browse the repository at this point in the history
* fix(callout): fix callout expand in production

Fixes issue where the Callout component content was not expanding correctly in prdouction. This is
because the property `name` is obfuscated in production for some environments. Setting and checking
for `displayName` should fix the issue because it is not obfuscated in production.

* refactor(callouttitle): replaces string literal for callout with a constant
  • Loading branch information
codemonkey800 authored Jan 17, 2024
1 parent 4215898 commit 1a4decb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { AlertTitleProps } from "@mui/material/AlertTitle";
import { CALLOUT_TITLE_DISPLAY_NAME } from "../../constants";
import { StyledCalloutTitle } from "./style";

const CalloutTitle = ({ children }: AlertTitleProps): JSX.Element => {
return <StyledCalloutTitle>{children}</StyledCalloutTitle>;
};

// Display name required to ensure Callout expand works correctly.
CalloutTitle.displayName = CALLOUT_TITLE_DISPLAY_NAME;

export default CalloutTitle;
1 change: 1 addition & 0 deletions packages/components/src/core/Callout/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CALLOUT_TITLE_DISPLAY_NAME = "CalloutTitle";
5 changes: 4 additions & 1 deletion packages/components/src/core/Callout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Grow } from "@mui/material";
import React, { useEffect, useState } from "react";
import ButtonIcon from "../ButtonIcon";
import Icon from "../Icon";
import { CALLOUT_TITLE_DISPLAY_NAME } from "./constants";
import { StyledCallout } from "./style";

const SDS_STAGE_OPEN = "open";
Expand Down Expand Up @@ -100,7 +101,9 @@ const Callout = ({
let calloutContent;

const firstChildIsCalloutTitle =
Array.isArray(children) && children[0]?.type?.name === "CalloutTitle";
Array.isArray(children) &&
children[0]?.type?.displayName === CALLOUT_TITLE_DISPLAY_NAME;

if (firstChildIsCalloutTitle) {
[calloutTitle, ...calloutContent] = children;
}
Expand Down

0 comments on commit 1a4decb

Please sign in to comment.