Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
HTML

HTML5: Fix a Dialog Backdrop Blocking Clicks After Close

- 02.12.26 - ErcanOPAK

🧩 HTML5: Fix a Dialog Backdrop Blocking Clicks After Close

The native ::backdrop pseudo-element that <dialog> renders behind a modal only exists while the dialog is open via showModal() — closing it with .close() normally removes the backdrop along with the dialog’s own open state. But a dialog whose closing is driven by a CSS transition (fading it out before actually calling .close()) can end up in a window where the dialog element still reports open while its content is visually faded to nothing, and if that transition’s transitionend handler never fires — a transform property mismatch, a transition that got interrupted by a rapid re-open — the backdrop keeps rendering fully transparent but still fully interactive, silently eating clicks on whatever’s underneath it.

🔎 The Problem

dialog.addEventListener('transitionend', () => dialog.close());

function hideDialog() {
  dialog.classList.add('is-closing'); // triggers opacity transition
  // if the dialog is closed again (e.g. user double-clicks the close
  // button) before transitionend fires once, the listener can fire for
  // the WRONG property or never fire at all depending on what else is
  // transitioning, and dialog.close() never actually gets called

  // dialog.open is still true, ::backdrop is still rendered (at
  // opacity: 0 from the CSS), and it still intercepts every click
  // underneath it - the page looks fully interactive but isn't

✅ Fix: Don’t Rely on a Single transitionend Firing to Close It

  • Pair transitionend with a fallback setTimeout set slightly longer than the transition’s declared duration, calling .close() unconditionally if it hasn’t already fired — this guarantees the dialog actually closes even if the transition event never reaches the listener.
  • Check event.propertyName inside the transitionend handler and only close on the specific property you’re actually animating (typically opacity), since a dialog with multiple simultaneous transitions can fire transitionend for an unrelated property first and trigger the handler at the wrong moment, or trigger it multiple times.
  • Guard against a rapid re-open/re-close by tracking a simple boolean (or checking dialog.open) before starting a new closing transition, so a user double-clicking close doesn’t leave two overlapping transition sequences each racing to decide when the dialog actually closes.

🚨 Why This Is Dangerous

  • A page that looks fully loaded and interactive but silently swallows every click in a region the user can’t visually tell is covered reads to that user as the site being broken, with no console error and no visual cue pointing at the invisible backdrop actually responsible.

A dialog’s backdrop is only as temporary as the event you’re trusting to remove it — and an event that can fail to fire leaves an invisible, fully interactive layer sitting on top of your page indefinitely.

— Frontend Architect

Related posts:

HTML: Use Popover API for Native Tooltips and Popups

HTML: Use Popover API for Native Tooltips and Popups

HTML Forms Submit Twice

HTML Forms Submit Twice

HTML: Implement Accessibility (A11y) Best Practices

HTML: Implement Accessibility (A11y) Best Practices

Views: 0
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

SQL Server: Fix an Extended Events Session Filling Its Target File
The AI Prompt That Sorts Board Game Boxes by Play Time

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com