Skip to content

Commit

Permalink
Make actions an optional prop and hide the footer when not present. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
willrlin authored Aug 19, 2021
1 parent 0c5618f commit 589f16d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion ui-components/__tests__/overlays/Modal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { render, cleanup } from "@testing-library/react"
import { render, cleanup, getByTestId } from "@testing-library/react"
import { Modal } from "../../src/overlays/Modal"

afterEach(cleanup)
Expand Down Expand Up @@ -47,4 +47,15 @@ describe("<Modal>", () => {
expect(getByText("Action 1")).toBeTruthy()
expect(getByText("Action 2")).toBeTruthy()
})
it("does not render footer with no actions", () => {
const portalRoot = document.createElement("div")
portalRoot.setAttribute("id", "__next")
document.body.appendChild(portalRoot)
const { queryByTestId } = render(
<Modal open={true} title={"Modal Title"} onClose={() => {}} ariaDescription={"My Modal"}>
<strong>Modal Children</strong>
</Modal>
)
expect(queryByTestId("footer")).toBeFalsy()
})
})
6 changes: 3 additions & 3 deletions ui-components/src/overlays/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Overlay, OverlayProps } from "./Overlay"

export interface ModalProps extends Omit<OverlayProps, "children"> {
title: string
actions: React.ReactNode[]
actions?: React.ReactNode[]
hideCloseIcon?: boolean
children?: React.ReactNode
}
Expand All @@ -18,7 +18,7 @@ const ModalHeader = (props: { title: string }) => (
)

const ModalFooter = (props: { actions: React.ReactNode[] }) => (
<footer className="modal__footer bg-primary-lighter">
<footer className="modal__footer bg-primary-lighter" data-testid="footer">
<GridSection columns={4} reverse={true} tightSpacing={true}>
{props.actions &&
props.actions.map((action: React.ReactNode, index: number) => (
Expand Down Expand Up @@ -48,7 +48,7 @@ export const Modal = (props: ModalProps) => {
)}
</section>

<ModalFooter actions={props.actions} />
{props.actions && <ModalFooter actions={props.actions} />}

{!props.hideCloseIcon && (
<button className="modal__close" aria-label="Close" onClick={props.onClose} tabIndex={0}>
Expand Down

0 comments on commit 589f16d

Please sign in to comment.