diff --git a/change/@fluentui-react-7127d38e-75df-4f5d-a363-88e57b77cbb8.json b/change/@fluentui-react-7127d38e-75df-4f5d-a363-88e57b77cbb8.json new file mode 100644 index 0000000000000..e73198cad0a52 --- /dev/null +++ b/change/@fluentui-react-7127d38e-75df-4f5d-a363-88e57b77cbb8.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "fix (v8 MessageBar): Add showExpandButton prop to allow manual override to explicitly show the expand button", + "packageName": "@fluentui/react", + "email": "jiangemma@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-examples/src/react/MessageBar/MessageBar.Basic.Example.tsx b/packages/react-examples/src/react/MessageBar/MessageBar.Basic.Example.tsx index f3201d3ab64f4..bbe40b3c22d36 100644 --- a/packages/react-examples/src/react/MessageBar/MessageBar.Basic.Example.tsx +++ b/packages/react-examples/src/react/MessageBar/MessageBar.Basic.Example.tsx @@ -106,24 +106,52 @@ const SuccessExample = () => ( ); -const WarningExample = (p: IExampleProps) => ( - - Action - +const WarningExample = (p: IExampleProps) => { + const [showExpandButton, setShowExpandButton] = React.useState(false); + + function onResize() { + const messageBarMessage = document.getElementById('warningMessageBar') as HTMLDivElement; + + if (messageBarMessage) { + const temp = messageBarMessage.cloneNode(true) as any; + + temp.style.position = 'fixed'; + temp.style.overflow = 'visible'; + temp.style.whiteSpace = 'nowrap'; + temp.style.visibility = 'hidden'; + + (messageBarMessage.parentElement as any).appendChild(temp); + + const fullWidth = temp.getBoundingClientRect().width; + const displayWidth = messageBarMessage.getBoundingClientRect().width; + + setShowExpandButton(fullWidth > displayWidth); } - > - Warning MessageBar content. - - Visit our website. - - -); + } + + window.onresize = onResize; + + return ( + + Action + + } + showExpandButton={showExpandButton} + > + Warning MessageBar content. + + Visit our website. + + + ); +}; const WarningExample2 = (p: IExampleProps) => ( , R // @deprecated overflowButtonAriaLabel?: string; role?: 'alert' | 'status' | 'none'; + showExpandButton?: boolean; styles?: IStyleFunctionOrObject; theme?: ITheme; truncated?: boolean; diff --git a/packages/react/src/components/MessageBar/MessageBar.base.tsx b/packages/react/src/components/MessageBar/MessageBar.base.tsx index 1f7cc745721a8..708771114cce5 100644 --- a/packages/react/src/components/MessageBar/MessageBar.base.tsx +++ b/packages/react/src/components/MessageBar/MessageBar.base.tsx @@ -65,6 +65,7 @@ export const MessageBarBase: React.FunctionComponent = React.f delayedRender = true, expandButtonProps, onExpandButtonToggled = undefined, + showExpandButton, } = props; // Wrap 'toggleExpandSingleLine' to execute the 'onExpandButtonToggled' callback whenever the expand button toggles @@ -137,7 +138,7 @@ export const MessageBarBase: React.FunctionComponent = React.f { - /* singleline expand/collapse button */ !isMultiline && !actionsDiv && truncated && ( + /* singleline expand/collapse button */ (showExpandButton || (!isMultiline && !actionsDiv && truncated)) && (
, Rea * @default true */ delayedRender?: boolean; + + /** + * An optional override to show the expand/collapse icon. It will only be shown by default for + * single-line truncated MessageBars that do not have actions. + * @defaultvalue false + */ + showExpandButton?: boolean; } /**