Skip to content

Commit 2ee3621

Browse files
fix disabled cancel button and add story
1 parent ebec4b0 commit 2ee3621

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

packages/ui-components/src/components/Modal/Modal.component.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,15 @@ export const Modal: React.FC<ModalProps> = ({
201201
) : (
202202
""
203203
)}
204-
{isCloseable && !disableCloseButton ? <Icon icon="close" onClick={handleCancelClick} /> : ""}
204+
{isCloseable ? (
205+
<Icon
206+
icon="close"
207+
onClick={handleCancelClick}
208+
disabled={disableCancelButton || disableCloseButton}
209+
/>
210+
) : (
211+
""
212+
)}
205213
</div>
206214
<div className={`juno-modal-content ${contentstyles} ${unpad ? "" : contentpaddingstyles}`}>
207215
{children}

packages/ui-components/src/components/Modal/Modal.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ export const CloseOnBackdropClick: Story = {
223223
},
224224
}
225225

226+
export const DisabledCloseButton: Story = {
227+
render: Template,
228+
args: {
229+
title: "Disabled Close Button Modal",
230+
children: <p>This Modal has a disabled close button.</p>,
231+
disableCloseButton: true,
232+
},
233+
}
234+
226235
export const Login: Story = {
227236
render: Template,
228237
args: {

packages/ui-components/src/components/Modal/Modal.test.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,28 +382,21 @@ describe("Modal", () => {
382382
expect(cancelButton).toBeInTheDocument()
383383
expect(cancelButton).toHaveAttribute("disabled")
384384

385+
expect(screen.getByRole("button", { name: "close" })).toBeDisabled()
386+
385387
await waitFor(() => userEvent.click(cancelButton))
386388
expect(mockOnCancel).not.toHaveBeenCalled()
387389
})
388390

389-
test("renders a modal without a close button in the header when disableCloseButton is true", async () => {
391+
test("renders a modal with no disabled close button if disableCloseButton is true", async () => {
390392
await waitFor(() =>
391393
render(
392394
<PortalProvider>
393395
<Modal open onCancel={mockOnCancel} disableCloseButton />
394396
</PortalProvider>
395397
)
396398
)
397-
398-
expect(screen.getByRole("dialog")).toBeInTheDocument()
399-
400-
// Ensure header close button doesn't exist
401-
const closeButton = screen.queryByRole("button", { name: "close" })
402-
expect(closeButton).not.toBeInTheDocument()
403-
404-
// Confirm that the modal remains open and the cancel handler was not called
405399
expect(screen.getByRole("dialog")).toBeInTheDocument()
406-
await userEvent.click(closeButton!)
407-
expect(mockOnCancel).not.toHaveBeenCalled()
400+
expect(screen.getByRole("button", { name: "close" })).toBeDisabled()
408401
})
409402
})

0 commit comments

Comments
 (0)