Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (v8 MessageBar): Add showExpandButton prop to allow manual override to explicitly show the expand button #32884

Merged
merged 14 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,52 @@ const SuccessExample = () => (
</MessageBar>
);

const WarningExample = (p: IExampleProps) => (
<MessageBar
messageBarType={MessageBarType.warning}
isMultiline={false}
onDismiss={p.resetChoice}
dismissButtonAriaLabel="Close"
actions={
<div>
<MessageBarButton>Action</MessageBarButton>
</div>
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.
<Link href="www.bing.com" target="_blank" underline>
Visit our website.
</Link>
</MessageBar>
);
}

window.onresize = onResize;
emmayjiang marked this conversation as resolved.
Show resolved Hide resolved

return (
<MessageBar
id="warningMessageBar"
messageBarType={MessageBarType.warning}
isMultiline={false}
onDismiss={p.resetChoice}
dismissButtonAriaLabel="Close"
actions={
<div>
<MessageBarButton>Action</MessageBarButton>
</div>
}
showExpandButton={showExpandButton}
>
Warning MessageBar content.
<Link href="www.bing.com" target="_blank" underline>
Visit our website.
</Link>
</MessageBar>
);
};

const WarningExample2 = (p: IExampleProps) => (
<MessageBar
Expand Down
1 change: 1 addition & 0 deletions packages/react/etc/react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7026,6 +7026,7 @@ export interface IMessageBarProps extends React_2.HTMLAttributes<HTMLElement>, R
// @deprecated
overflowButtonAriaLabel?: string;
role?: 'alert' | 'status' | 'none';
showExpandButton?: boolean;
styles?: IStyleFunctionOrObject<IMessageBarStyleProps, IMessageBarStyles>;
theme?: ITheme;
truncated?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const MessageBarBase: React.FunctionComponent<IMessageBarProps> = React.f
delayedRender = true,
expandButtonProps,
onExpandButtonToggled = undefined,
showExpandButton,
} = props;

// Wrap 'toggleExpandSingleLine' to execute the 'onExpandButtonToggled' callback whenever the expand button toggles
Expand Down Expand Up @@ -108,6 +109,8 @@ export const MessageBarBase: React.FunctionComponent<IMessageBarProps> = React.f
/>
) : null;

// console.log(truncated, isMultiline);
emmayjiang marked this conversation as resolved.
Show resolved Hide resolved

return (
<div ref={ref} className={classNames.root} {...regionProps}>
<div className={classNames.content}>
Expand Down Expand Up @@ -137,7 +140,7 @@ export const MessageBarBase: React.FunctionComponent<IMessageBarProps> = React.f
</span>
</div>
{
/* singleline expand/collapse button */ !isMultiline && !actionsDiv && truncated && (
/* singleline expand/collapse button */ (showExpandButton || (!isMultiline && !actionsDiv && truncated)) && (
<div className={classNames.expandSingleLine}>
<IconButton
disabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export interface IMessageBarProps extends React.HTMLAttributes<HTMLElement>, Rea
* @default true
*/
delayedRender?: boolean;

/**
* An optional override to show the expand/collapse icon.
emmayjiang marked this conversation as resolved.
Show resolved Hide resolved
* @defaultvalue false
*/
showExpandButton?: boolean;
}

/**
Expand Down
Loading