Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions demo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function App() {
okButtonText: 'Yes',
okButtonDangerous: true,
cancelButtonText: 'No',
title: 'Warning',
})
) {
alert('Rest in pieces.');
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface ConfirmModalProps extends WrappedModalProps {
onOk?: (() => void) | (() => Promise<any>);
onCancel?: (isSubmitLoading?: boolean) => any;
canCancelOnLoading?: boolean;
title?: React.ReactNode;
}

interface PromptModalProps extends WrappedModalProps {
Expand Down
6 changes: 6 additions & 0 deletions src/InteractionModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function InteractionModal({
children,
canCancelOnLoading = false,
modalProps: extraModalProps = {},
title,
}) {
const [shouldShowModal, setShouldShowModal] = useState(true);
const [submitLoading, setSubmitLoading] = useState(false);
Expand Down Expand Up @@ -90,6 +91,11 @@ function InteractionModal({
aria-describedby="alertdialog-description"
{...modalProps}
>
{title && (
<Modal.Header>
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
)}
<Modal.Body id="alertdialog-description">{children}</Modal.Body>
<Modal.Footer>
{showCancelButton && (
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/confirm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ it('shows dialog with given message and two buttons', async () => {
).toBeInTheDocument();
});

it('show dialog with custom title', async () => {
const title = 'Custom Title';
confirm('Message', {
title,
});

expect(screen.getByRole('alertdialog')).toHaveTextContent(title);
expect(screen.queryByLabelText('Close')).toBeInTheDocument();
});
it('show dialog without custom title', async () => {
confirm('Message');

expect(screen.queryByLabelText('Close')).not.toBeInTheDocument();
});

it('renders custom button text', async () => {
const okButtonText = 'Okay';
const cancelButtonText = 'Nah';
Expand Down
Loading