Skip to content

Commit 7a29323

Browse files
authored
feat(MessageBox): expose all Dialog props, except footer, headerText and onAfterClose (#2141)
1 parent 1dfad08 commit 7a29323

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

packages/main/src/components/MessageBox/MessageBox.test.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ describe('MessageBox', () => {
188188

189189
expect(dialogInitialFocus).toEqual(cancelBtnId);
190190
});
191-
192-
createPassThroughPropsTest(MessageBox);
191+
test('display custom header', () => {
192+
const { getByText, queryByText } = render(
193+
<MessageBox open header={<div>Custom Header</div>}>
194+
Content
195+
</MessageBox>
196+
);
197+
expect(queryByText('Confirmation')).toBeNull();
198+
expect(getByText('Custom Header')).toHaveTextContent('Custom Header');
199+
});
193200
});

packages/main/src/components/MessageBox/index.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import '@ui5/webcomponents-icons/dist/message-information.js';
44
import '@ui5/webcomponents-icons/dist/message-success.js';
55
import '@ui5/webcomponents-icons/dist/message-warning.js';
66
import '@ui5/webcomponents-icons/dist/question-mark.js';
7-
import {
8-
useConsolidatedRef,
9-
useI18nBundle,
10-
useIsomorphicLayoutEffect,
11-
usePassThroughHtmlProps
12-
} from '@ui5/webcomponents-react-base/dist/hooks';
7+
import { useConsolidatedRef, useI18nBundle, useIsomorphicLayoutEffect } from '@ui5/webcomponents-react-base/dist/hooks';
138
import { StyleClassHelper } from '@ui5/webcomponents-react-base/dist/StyleClassHelper';
149
import { enrichEventWithDetails } from '@ui5/webcomponents-react-base/dist/Utils';
1510
import {
@@ -31,14 +26,13 @@ import {
3126
} from '@ui5/webcomponents-react/dist/assets/i18n/i18n-defaults';
3227
import { Button } from '@ui5/webcomponents-react/dist/Button';
3328
import { ButtonDesign } from '@ui5/webcomponents-react/dist/ButtonDesign';
34-
import { Dialog } from '@ui5/webcomponents-react/dist/Dialog';
29+
import { Dialog, DialogPropTypes } from '@ui5/webcomponents-react/dist/Dialog';
3530
import { Icon } from '@ui5/webcomponents-react/dist/Icon';
3631
import { MessageBoxActions } from '@ui5/webcomponents-react/dist/MessageBoxActions';
3732
import { MessageBoxTypes } from '@ui5/webcomponents-react/dist/MessageBoxTypes';
3833
import { Text } from '@ui5/webcomponents-react/dist/Text';
3934
import { Title } from '@ui5/webcomponents-react/dist/Title';
4035
import { TitleLevel } from '@ui5/webcomponents-react/dist/TitleLevel';
41-
import { CommonProps } from '@ui5/webcomponents-react/interfaces/CommonProps';
4236
import { Ui5CustomEvent } from '@ui5/webcomponents-react/interfaces/Ui5CustomEvent';
4337
import { Ui5DialogDomRef } from '@ui5/webcomponents-react/interfaces/Ui5DialogDomRef';
4438
import React, {
@@ -71,7 +65,7 @@ const deprecatedActions = new Set<MessageBoxAction>([
7165
MessageBoxActions.YES
7266
]);
7367

74-
export interface MessageBoxPropTypes extends CommonProps {
68+
export interface MessageBoxPropTypes extends Omit<DialogPropTypes, 'children' | 'footer' | 'headerText' | 'onAfterClose'> {
7569
/**
7670
* Flag whether the Message Box should be opened or closed
7771
*/
@@ -155,7 +149,8 @@ const MessageBox = forwardRef((props: MessageBoxPropTypes, ref: Ref<Ui5DialogDom
155149
actions,
156150
emphasizedAction,
157151
onClose,
158-
initialFocus
152+
initialFocus,
153+
...rest
159154
} = props;
160155
const dialogRef = useConsolidatedRef<Ui5DialogDomRef>(ref);
161156

@@ -269,8 +264,6 @@ const MessageBox = forwardRef((props: MessageBoxPropTypes, ref: Ref<Ui5DialogDom
269264
}
270265
}, [dialogRef.current, open]);
271266

272-
const passThroughProps = usePassThroughHtmlProps(props, ['onClose']);
273-
274267
const messageBoxClassNames = StyleClassHelper.of(classes.messageBox).putIfPresent(className).className;
275268
const internalActions = getActions();
276269

@@ -343,6 +336,8 @@ const MessageBox = forwardRef((props: MessageBoxPropTypes, ref: Ref<Ui5DialogDom
343336
}
344337
}
345338
}, [emphasizedAction]);
339+
// @ts-ignore
340+
const { footer, headerText, title, onAfterClose, ...restWithoutOmitted } = rest;
346341
// todo: remove lowercase conversions
347342
return (
348343
<Dialog
@@ -352,13 +347,15 @@ const MessageBox = forwardRef((props: MessageBoxPropTypes, ref: Ref<Ui5DialogDom
352347
title={tooltip ?? props.title}
353348
className={messageBoxClassNames}
354349
onAfterClose={open ? handleOnClose : stopPropagation}
350+
{...restWithoutOmitted}
355351
initialFocus={getInitialFocus()}
356-
{...passThroughProps}
357352
>
358-
<header slot="header" className={classes.header} data-type={type}>
359-
{iconToRender}
360-
<Title level={TitleLevel.H2}>{titleToRender()}</Title>
361-
</header>
353+
{!props.header && (
354+
<header slot="header" className={classes.header} data-type={type}>
355+
{iconToRender}
356+
<Title level={TitleLevel.H2}>{titleToRender()}</Title>
357+
</header>
358+
)}
362359
<Text className={classes.content}>{children}</Text>
363360
<footer slot="footer" className={classes.footer}>
364361
{internalActions.map((action, index) => {

0 commit comments

Comments
 (0)