Skip to content

Commit 0147c60

Browse files
authored
feat: confirm support title (#67)
1 parent 7b435ab commit 0147c60

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

demo/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function App() {
4747
okButtonText: 'Yes',
4848
okButtonDangerous: true,
4949
cancelButtonText: 'No',
50+
title: 'Warning',
5051
})
5152
) {
5253
alert('Rest in pieces.');

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface ConfirmModalProps extends WrappedModalProps {
1717
onOk?: (() => void) | (() => Promise<any>);
1818
onCancel?: (isSubmitLoading?: boolean) => any;
1919
canCancelOnLoading?: boolean;
20+
title?: React.ReactNode;
2021
}
2122

2223
interface PromptModalProps extends WrappedModalProps {

src/InteractionModal.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function InteractionModal({
1111
children,
1212
canCancelOnLoading = false,
1313
modalProps: extraModalProps = {},
14+
title,
1415
}) {
1516
const [shouldShowModal, setShouldShowModal] = useState(true);
1617
const [submitLoading, setSubmitLoading] = useState(false);
@@ -90,6 +91,11 @@ function InteractionModal({
9091
aria-describedby="alertdialog-description"
9192
{...modalProps}
9293
>
94+
{title && (
95+
<Modal.Header>
96+
<Modal.Title>{title}</Modal.Title>
97+
</Modal.Header>
98+
)}
9399
<Modal.Body id="alertdialog-description">{children}</Modal.Body>
94100
<Modal.Footer>
95101
{showCancelButton && (

src/__tests__/confirm.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ it('shows dialog with given message and two buttons', async () => {
2929
).toBeInTheDocument();
3030
});
3131

32+
it('show dialog with custom title', async () => {
33+
const title = 'Custom Title';
34+
confirm('Message', {
35+
title,
36+
});
37+
38+
expect(screen.getByRole('alertdialog')).toHaveTextContent(title);
39+
expect(screen.queryByLabelText('Close')).toBeInTheDocument();
40+
});
41+
it('show dialog without custom title', async () => {
42+
confirm('Message');
43+
44+
expect(screen.queryByLabelText('Close')).not.toBeInTheDocument();
45+
});
46+
3247
it('renders custom button text', async () => {
3348
const okButtonText = 'Okay';
3449
const cancelButtonText = 'Nah';

0 commit comments

Comments
 (0)