Skip to content

Commit

Permalink
Remove footer when side modal is read-only (#2621)
Browse files Browse the repository at this point in the history
* Remove sidemodal footer when read-only

* Update test to use X to close modal

* move close button back into SideModal

---------

Co-authored-by: David Crespo <[email protected]>
  • Loading branch information
charliepark and david-crespo authored Dec 13, 2024
1 parent c1fbf63 commit 2b0c3f1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
15 changes: 8 additions & 7 deletions app/components/form/SideModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* Copyright Oxide Computer Company
*/

import { useEffect, useId, useState, type ReactNode } from 'react'
import type { FieldValues, UseFormReturn } from 'react-hook-form'
import { NavigationType, useNavigationType } from 'react-router-dom'
Expand Down Expand Up @@ -127,11 +128,11 @@ export function SideModalForm<TFieldValues extends FieldValues>({
{children}
</form>
</SideModal.Body>
<SideModal.Footer error={!!submitError}>
<Button variant="ghost" size="sm" onClick={onDismiss}>
Cancel
</Button>
{onSubmit && (
{onSubmit && (
<SideModal.Footer error={!!submitError}>
<Button variant="ghost" size="sm" onClick={onDismiss}>
Cancel
</Button>
<Button
type="submit"
size="sm"
Expand All @@ -142,8 +143,8 @@ export function SideModalForm<TFieldValues extends FieldValues>({
>
{label}
</Button>
)}
</SideModal.Footer>
</SideModal.Footer>
)}

{showNavGuard && (
<Modal
Expand Down
18 changes: 8 additions & 10 deletions app/ui/lib/SideModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export function SideModal({
</div>
)}
{children}

{/* Close button is here at the end so we aren't automatically focusing on it when the side modal is opened. Positioned in the safe area at the top */}
<Dialog.Close
className="absolute right-[var(--content-gutter)] top-10 -m-2 flex rounded p-2 hover:bg-hover"
aria-label="Close"
>
<Close12Icon className="text-default" />
</Dialog.Close>
</AnimatedDialogContent>
</Dialog.Portal>
</Dialog.Root>
Expand Down Expand Up @@ -161,15 +169,5 @@ SideModal.Footer = ({ children, error }: { children: ReactNode; error?: boolean
</div>
)}
{children}
{/*
Close button is here at the end so we aren't automatically focusing on it
when the side modal is opened. Positioned in the safe area at the top
*/}
<Dialog.Close
className="absolute right-[var(--content-gutter)] top-10 -m-2 flex rounded p-2 hover:bg-hover"
aria-label="Close"
>
<Close12Icon className="text-default" />
</Dialog.Close>
</footer>
)
4 changes: 2 additions & 2 deletions test/e2e/silos.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ test('Identity providers', async ({ page }) => {
'groups'
)

await page.getByRole('button', { name: 'Cancel' }).click()
await page.getByRole('button', { name: 'Close' }).click()

await expect(dialog).toBeHidden()

Expand Down Expand Up @@ -320,7 +320,7 @@ test('Silo IP pools link pool', async ({ page }) => {
await expect(modal).toBeVisible()

// close modal works
await page.getByRole('button', { name: 'Cancel' }).click()
await page.getByRole('button', { name: 'Close' }).click()
await expect(modal).toBeHidden()

// reopen
Expand Down

0 comments on commit 2b0c3f1

Please sign in to comment.