Skip to content

Fix radix warnings on side modal #2536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2024
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
6 changes: 5 additions & 1 deletion app/ui/lib/SideModal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export function Default() {
return (
<>
<Button onClick={() => setIsOpen(true)}>Open menu</Button>
<SideModal isOpen={isOpen} onDismiss={() => setIsOpen(false)}>
<SideModal
title="Create something"
isOpen={isOpen}
onDismiss={() => setIsOpen(false)}
>
<SideModal.Body>
<SideModal.Section>Section content</SideModal.Section>
<SideModal.Section>
Expand Down
80 changes: 29 additions & 51 deletions app/ui/lib/SideModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function usePopoverZIndex() {
}

export type SideModalProps = {
title?: string
title: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title did not need to be optional. We always have a title.

subtitle?: ReactNode
onDismiss: () => void
isOpen: boolean
Expand All @@ -53,7 +53,6 @@ export function SideModal({
animate = true,
errors,
}: SideModalProps) {
const titleId = 'side-modal-title'
Copy link
Collaborator Author

@david-crespo david-crespo Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used to hook up the accessible title to the dialog, but Radix takes care of that for us.

image

const AnimatedDialogContent = animated(Dialog.Content)

const config = { tension: 650, mass: 0.125 }
Expand Down Expand Up @@ -81,40 +80,39 @@ export function SideModal({
<DialogOverlay />
<AnimatedDialogContent
className="DialogContent ox-side-modal pointer-events-auto fixed bottom-0 right-0 top-0 z-sideModal m-0 flex w-[32rem] flex-col justify-between border-l p-0 bg-raise border-secondary elevation-2"
aria-labelledby={titleId}
style={{
transform: x.to((value) => `translate3d(${value}%, 0px, 0px)`),
}}
// shuts off a warning from radix about dialog content needing a description
aria-describedby={undefined}
>
{title && (
<Dialog.Title asChild>
<>
<SideModal.Title id={titleId} title={title} subtitle={subtitle} />

{errors && errors.length > 0 && (
<div className="mb-6">
<Message
variant="error"
content={
errors.length === 1 ? (
errors[0]
) : (
<>
<div>{errors.length} issues:</div>
<ul className="ml-4 list-disc">
{errors.map((error, idx) => (
<li key={idx}>{error}</li>
))}
</ul>
</>
)
}
title={errors.length > 1 ? 'Errors' : 'Error'}
/>
</div>
)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why were errors inside the title????

</>
<div className="items-top mb-4 mt-8">
<Dialog.Title className="flex w-full items-center justify-between break-words pr-8 text-sans-2xl">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dialog.Title without asChild renders as an h2. Putting it directly around the title itself makes a lot more sense here.

{title}
</Dialog.Title>
{subtitle}
</div>
{errors && errors.length > 0 && (
<div className="mb-6">
<Message
variant="error"
content={
errors.length === 1 ? (
errors[0]
) : (
<>
<div>{errors.length} issues:</div>
<ul className="ml-4 list-disc">
{errors.map((error, idx) => (
<li key={idx}>{error}</li>
))}
</ul>
</>
)
}
title={errors.length > 1 ? 'Errors' : 'Error'}
/>
</div>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed everything looks the same as main when there are errors.

image

)}
{children}
</AnimatedDialogContent>
Expand All @@ -128,26 +126,6 @@ export function SideModal({

export const ResourceLabel = classed.h3`mt-2 flex items-center gap-1.5 text-sans-md text-accent`

SideModal.Title = ({
title,
id,
subtitle,
}: {
title: string
id?: string
subtitle?: ReactNode
}) => (
<div className="items-top mb-4 mt-8">
<h2
className="flex w-full items-center justify-between break-words pr-8 text-sans-2xl"
id={id}
>
{title}
</h2>
{subtitle}
</div>
)

// separate component because otherwise eslint thinks it's not a component and
// gets mad about the use of hooks
function SideModalBody({ children }: { children?: ReactNode }) {
Expand Down
Loading