Anyone actually using <dialog> in production yet?

jt_loves_tacos

New Member
Messages
75
Reaction score
0
Location
Phoenix, AZ

Been rebuilding a settings modal at work and decided to finally use the native &lt;dialog&gt; element instead of another div soup overlay. Weirdly painless for the basic open/close stuff. showModal() handles focus trapping and Esc for me, and forms with method='dialog' close automatically. Felt like cheating after years of hacking z-index and focus traps.

But then iOS Safari did the usual thing. Backdrop blur looked fine on desktop, then on my phone the dialog got tucked under the keyboard when an input got focused. Had to add scroll padding and a resize listener. Also the default ::backdrop styling gets weird in older Safari unless you target it directly, which took me way too long to figure out.

Not saying I'm going back to custom modals, but I get why some teams wait. Anyone using &lt;dialog&gt; on a real project with forms? Did you hit the keyboard thing too? Curious if there's a cleaner fix than my janky JS bandaid.

tallguy_tx

New Member
Messages
61
Reaction score
0
Location
Austin, TX

Yeah the keyboard thing is real and I don't think it's your bandaid that's janky, I think it's just the only option right now. I do frontend contract work for a couple of offshore books (the irony of a guy who complains about UIGEA all day building deposit modals is not lost on me) and we hit this exact wall on the cashier flow last spring.

What worked for us, sort of: keep the dialog position: fixed and listen to visualViewport resize instead of window resize, then on focusin scroll the input into view manually. The window resize event straight up doesn't fire reliably when the iOS keyboard opens, which is why my first attempt did nothing. Also had to kill the 100vh habit and use 100dvh or the dialog ends up half under the keyboard anyway.

And yeah ::backdrop on older Safari is cursed. Half our traffic is people on some crusty iOS 15 device behind a VPN that keeps dropping, so I just hardcoded the backdrop color instead of trying to be cute with blur. Not worth the support tickets. Did you ever figure out if the scroll padding thing breaks when the dialog content is taller than the viewport? That's the part that keeps biting us.

jen_93

Member
Messages
62
Reaction score
0
Location
Cape Town, ZA

visualViewport over window resize is the move, 100%. I lost an afternoon to that exact thing, logging resize events and wondering why my handler fired exactly zero times when the keyboard popped up. 100dvh too, yeah, I'd been clinging to 100vh like an idiot for way too long.

But ngl the whole approach still feels fragile to me. On iOS 17 I've had visualViewport fire on pinch zoom as well, so if someone zooms in on a form field the dialog starts hopping around like it's possessed. I ended up gating the handler on whether the height actually changed by more than ~50px before doing anything. Feels like a hack stacked on a hack.

And to actually answer your question about tall content: yeah, scroll padding breaks. Once the dialog itself is the scroll container and the content overflows it, scroll-padding doesn't do what you want because you're padding the wrong thing. What finally worked for us was making the dialog a flex column with a scrollable middle section and a sticky footer holding the submit button. Then the keyboard just shrinks the scrollable area and you never fight the padding at all. Took me embarrassingly long to land on that.

The gotcha nobody warned me about though was background scroll bleed. showModal() doesn't lock the body, and overflow: hidden on body does basically nothing on iOS Safari, so you can still rubber band the page behind the dialog. Had to do the position:fixed body plus remember-scrollY dance, which is exactly the kind of crap I switched to &lt;dialog&gt; to avoid.

zer0cool99

New Member
Messages
67
Reaction score
0
Location
Seattle, WA

jen_93 the pinch zoom thing is what nearly ended me. I was doing the opposite of your gate, re-centering on every single fire, so the second someone zoomed into a field the dialog was basically vibrating. 50px delta is the move, stealing that.

But the flex column + sticky footer answer is the real one. I do the cashier front end for a Curacao book (deposit and withdraw modals, so yeah, the same irony tallguy_tx is living) and once we moved to a scrollable middle with the submit pinned, the keyboard fight just evaporated. Should've found that a year earlier instead of shipping scroll-padding garbage to production and pretending it worked.

Angle nobody's hit yet: iframes. Our PayID provider hands you an embedded iframe for the payment step and on iOS that thing runs its own focus and scroll behavior inside the dialog. visualViewport fires from inside the frame and your handler has no clue what's going on. We gave up and pushed the payment step out of the dialog into a full screen route. Ugly, but the support tickets stopped. Do you unmount the dialog on route change or leave it mounted? Ours leaks a focus trap if we don't nuke it.

zer0cool99

New Member
Messages
67
Reaction score
0
Location
Seattle, WA

jen_93 the 50px gate is solid but it bit me on Android. visualViewport there can jump way more than 50 when the URL bar collapses on scroll, so my gate kept tripping mid-session and re-centering the dialog for no reason. Adding a check that document.activeElement is actually inside the dialog fixed most of it. Android's the afterthought in every one of these threads, everyone tests iOS and ships.

And on my own question, since nobody bit: we unmount. Route change nukes the whole dialog node and we mount fresh. Leaving it mounted leaked the focus trap every time we bounced between deposit and withdraw, and the stale returnValue from the old form pre-filled the wrong field once. Took a support ticket to trace that one. Not glamorous but the tickets stopped.

tallguy_tx the UIGEA irony is real, half my day is building deposit flows for a book that ACMA would love to block and the other half is me arguing on here about it. Anyway your 100dvh tip is the one I'm mad I didn't know a year ago.

emilyb85

New Member
Messages
67
Reaction score
0
Location
Amsterdam, NL

Not to be that person, but the 50px gate is exactly the kind of magic number that's going to confuse whoever inherits this in eight months. Nobody will remember why 50. jen_93 you already hit the Android problem and zer0cool99 patched it with an activeElement check, which is basically admitting the threshold was never the real signal. The focus check is the fix, the gate is a bandaid on the bandaid.

Where I'll actually push back harder is the flex column + sticky footer consensus. It's great when the dialog is a form with a submit. But half the dialogs I ship are confirmations or a single-line rename field, and forcing every one of them into scrollable-middle-plus-pinned-footer is a ton of structure for a problem that does not exist on those. We found one hammer and now everything's a nail. Are you all differentiating per dialog type or is it sticky footer across the board now? Genuinely curious because I might be wrong and just lazy.

zer0cool99 the iframe thing is the most honest post in here. Everyone's writing elaborate resize handlers while quietly routing the payment step out of the dialog entirely, which is the actual answer nobody wants to put in a blog post. I've done the same with a Stripe step and felt zero guilt about it.

zer0cool99

New Member
Messages
67
Reaction score
0
Location
Seattle, WA

emilyb85 you're right about the magic number and I hate that you're right. 50 was whatever felt like "keyboard opened" at 2am. The activeElement check is the actual logic, the gate is just a cheap way to skip work when nothing's focused. I'd defend it but honestly if I got hit by a bus the next person would delete that line and the dialog would start vibrating on pinch zoom again. Which is its own argument for not keeping it.

Where I'll push back though: the single-line rename dialog you're describing is exactly where the flex column costs you nothing. display:flex; flex-direction:column on the dialog and you just... don't add a scrollable middle. Two lines of CSS, no sticky footer, done. I think the "hammer" complaint is real but it's aimed at people copy-pasting the whole pattern into a confirm dialog, not at the pattern itself. The structure isn't the problem, blindly reusing the structure is.

And yeah I've got three dialog types in the codebase right now. Confirm (no flex, no footer), rename/single input (flex column, no scroll middle), and the deposit form (the full scrollable middle + pinned submit). The first two have never had a keyboard bug since I stopped trying to solve them with the deposit fix. So no, not sticky footer across the board. You're not being lazy, you're being correct.

The iframe thing, for what it's worth, I've now watched two teams independently arrive at "route it out of the dialog" like it's some clever architecture decision when it's really just surrender. Nobody writes that post because it's not a fix.

You must log in or register to reply here.