Skip to content

Commit b06e35b

Browse files
fix(dialog): allow max width overrides (#574)
1 parent cff5260 commit b06e35b

5 files changed

Lines changed: 62 additions & 2 deletions

File tree

.changeset/shy-ravens-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
Allow unprefixed Dialog max-width classes to override the default viewport cap at desktop breakpoints.

packages/kumo-docs-astro/src/components/demos/DialogDemo.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,44 @@ export function DialogWithActionsDemo() {
8686
);
8787
}
8888

89+
/**
90+
* Dialog with a consumer-provided max width and wide intrinsic content.
91+
* The panel should stay capped at max-w-lg on desktop.
92+
*/
93+
export function DialogMaxWidthDemo() {
94+
return (
95+
<Dialog.Root>
96+
<Dialog.Trigger render={(p) => <Button {...p}>Open capped dialog</Button>} />
97+
<Dialog className="max-w-lg p-8">
98+
<div className="mb-4 flex items-start justify-between gap-4">
99+
<Dialog.Title className="text-2xl font-semibold">
100+
Max width override
101+
</Dialog.Title>
102+
<Dialog.Close
103+
aria-label="Close"
104+
render={(props) => (
105+
<Button
106+
{...props}
107+
variant="secondary"
108+
shape="square"
109+
icon={<X />}
110+
aria-label="Close"
111+
/>
112+
)}
113+
/>
114+
</div>
115+
<Dialog.Description className="text-kumo-subtle">
116+
This dialog uses <code>className="max-w-lg"</code> and should stay
117+
capped around 512px on desktop.
118+
</Dialog.Description>
119+
<div className="mt-4 truncate rounded-md border border-kumo-line bg-kumo-recessed p-3 font-mono text-sm">
120+
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
121+
</div>
122+
</Dialog>
123+
</Dialog.Root>
124+
);
125+
}
126+
89127
export function DialogConfirmationDemo() {
90128
return (
91129
<Dialog.Root disablePointerDismissal>
@@ -212,8 +250,9 @@ export function DialogWithSelectDemo() {
212250
</Dialog.Description>
213251
<Select
214252
className="w-full"
253+
placeholder="Select region..."
215254
renderValue={(v) =>
216-
regions.find((r) => r.value === v)?.label ?? "Select region..."
255+
regions.find((r) => r.value === v)?.label
217256
}
218257
>
219258
{regions.map((region) => (

packages/kumo-docs-astro/src/pages/components/dialog.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
DialogWithActionsDemo,
1616
DialogConfirmationDemo,
1717
DialogAlertDemo,
18+
DialogMaxWidthDemo,
1819
DialogWithSelectDemo,
1920
DialogWithComboboxDemo,
2021
DialogWithDropdownDemo,
@@ -171,6 +172,20 @@ export default function Example() {
171172
<DialogWithActionsDemo client:load />
172173
</ComponentExample>
173174

175+
### Custom Max Width
176+
177+
<p>
178+
Consumer max-width utilities such as `max-w-lg` should cap the dialog on
179+
desktop, even when the dialog contains wide intrinsic content.
180+
</p>
181+
<ComponentExample
182+
demo="DialogMaxWidthDemo"
183+
vrSection="custom-max-width"
184+
vrTitle="Custom Max Width"
185+
>
186+
<DialogMaxWidthDemo client:load />
187+
</ComponentExample>
188+
174189
### With Select
175190

176191
<p>Dialog containing a Select dropdown.</p>

packages/kumo/src/components/dialog/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function dialogVariants({
143143
}: KumoDialogVariantsProps = {}) {
144144
return cn(
145145
// Base styles
146-
"shadow-m ring ring-kumo-line fixed top-1/2 left-1/2 w-full sm:w-auto max-w-[calc(100vw-2rem)] sm:max-w-[calc(100vw-3rem)] -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl bg-kumo-base text-kumo-default duration-150 data-ending-style:scale-90 data-ending-style:opacity-0 data-starting-style:scale-90 data-starting-style:opacity-0",
146+
"shadow-m ring ring-kumo-line fixed top-1/2 left-1/2 w-full sm:w-auto max-w-[calc(100vw-2rem)] -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl bg-kumo-base text-kumo-default duration-150 data-ending-style:scale-90 data-ending-style:opacity-0 data-starting-style:scale-90 data-starting-style:opacity-0",
147147
// Apply size from KUMO_DIALOG_VARIANTS
148148
resolveVariant(KUMO_DIALOG_VARIANTS.size, size, KUMO_DIALOG_DEFAULT_VARIANTS.size).classes,
149149
);

packages/kumo/src/utils/variant-safety.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe("variant functions survive invalid variant values", () => {
108108
it("dialogVariants", () => {
109109
expect(() => dialogVariants({ size: BOGUS })).not.toThrow();
110110
expect(typeof dialogVariants({ size: BOGUS })).toBe("string");
111+
expect(dialogVariants()).not.toContain("sm:max-w");
111112
});
112113

113114
it("emptyVariants", () => {

0 commit comments

Comments
 (0)