From cafffa059735cdb29e4d9eb49be21aaaa8707ece Mon Sep 17 00:00:00 2001 From: Grug Date: Fri, 23 Oct 2026 09:22:42 +0800 Subject: [PATCH] Don't close dialogs when a drag ends on the backdrop (#202) Only close a dialog or command dialog on backdrop click when the press also started on the backdrop, so selecting text inside and releasing outside no longer closes it. Co-authored-by: PhilipdeRijk --- site/src/docs/components/command.mdx | 8 ++++---- site/src/docs/components/dialog.mdx | 14 +++++++------- src/templates/jinja/command.html.jinja | 2 +- src/templates/jinja/dialog.html.jinja | 2 +- src/templates/nunjucks/command.njk | 2 +- src/templates/nunjucks/dialog.njk | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/site/src/docs/components/command.mdx b/site/src/docs/components/command.mdx index a979564..ae6dadf 100644 --- a/site/src/docs/components/command.mdx +++ b/site/src/docs/components/command.mdx @@ -197,7 +197,7 @@ A simple command menu in a dialog. - +
@@ -218,7 +218,7 @@ A simple command menu in a dialog. - +
@@ -248,7 +248,7 @@ A simple command menu in a dialog. - +
@@ -291,7 +291,7 @@ A simple command menu in a dialog. - +
diff --git a/site/src/docs/components/dialog.mdx b/site/src/docs/components/dialog.mdx index 7b40035..20a7378 100644 --- a/site/src/docs/components/dialog.mdx +++ b/site/src/docs/components/dialog.mdx @@ -2,7 +2,7 @@ - +

Edit profile

@@ -63,7 +63,7 @@ Basecoat uses the native `` element and `showModal()`. This differs from ```html - +

Edit profile

@@ -134,7 +134,7 @@ Basecoat uses the native `` element and `showModal()`. This differs from - +

Share link

@@ -157,7 +157,7 @@ Basecoat uses the native `` element and `showModal()`. This differs from - +

No Close Button

@@ -171,7 +171,7 @@ Basecoat uses the native `` element and `showModal()`. This differs from - +
@@ -199,7 +199,7 @@ Basecoat uses the native `` element and `showModal()`. This differs from - +

Scrollable Content

@@ -229,7 +229,7 @@ Dialog positioning and close button placement use logical properties. Set `dir="
- +

تعديل الملف الشخصي

diff --git a/src/templates/jinja/command.html.jinja b/src/templates/jinja/command.html.jinja index f59f9c8..d1548ee 100644 --- a/src/templates/jinja/command.html.jinja +++ b/src/templates/jinja/command.html.jinja @@ -98,7 +98,7 @@ class="command-dialog {{ dialog_attrs.class | default('') }}" aria-label="Command menu" {% if open %}open{% endif %} - onclick="if (event.target === this) this.close()" + onpointerdown="this.dataset.backdropPress = event.target === this" onclick="if (event.target === this && this.dataset.backdropPress === 'true') this.close()" {% for key, value in dialog_attrs.items() %} {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %} {% endfor %} diff --git a/src/templates/jinja/dialog.html.jinja b/src/templates/jinja/dialog.html.jinja index 5ce95a7..9a055aa 100644 --- a/src/templates/jinja/dialog.html.jinja +++ b/src/templates/jinja/dialog.html.jinja @@ -53,7 +53,7 @@ {% if title %}aria-labelledby="{{ id }}-title"{% endif %} {% if description %}aria-describedby="{{ id }}-description"{% endif %} {% if open %}open{% endif %} - {% if close_on_overlay_click %}onclick="if (event.target === this) this.close()"{% endif %} + {% if close_on_overlay_click %}onpointerdown="this.dataset.backdropPress = event.target === this" onclick="if (event.target === this && this.dataset.backdropPress === 'true') this.close()"{% endif %} {% for key, value in dialog_attrs.items() %} {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %} {% endfor %} diff --git a/src/templates/nunjucks/command.njk b/src/templates/nunjucks/command.njk index 00c8fec..34f6d20 100644 --- a/src/templates/nunjucks/command.njk +++ b/src/templates/nunjucks/command.njk @@ -92,7 +92,7 @@ class="command-dialog {{ dialog_attrs.class }}" aria-label="Command menu" {% if open %}open{% endif %} - onclick="if (event.target === this) this.close()" + onpointerdown="this.dataset.backdropPress = event.target === this" onclick="if (event.target === this && this.dataset.backdropPress === 'true') this.close()" {% for key, value in dialog_attrs %} {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %} {% endfor %} diff --git a/src/templates/nunjucks/dialog.njk b/src/templates/nunjucks/dialog.njk index 5af7655..36a6ba3 100644 --- a/src/templates/nunjucks/dialog.njk +++ b/src/templates/nunjucks/dialog.njk @@ -48,7 +48,7 @@ {% if title %}aria-labelledby="{{ id }}-title"{% endif %} {% if description %}aria-describedby="{{ id }}-description"{% endif %} {% if open %}open{% endif %} - {% if close_on_overlay_click %}onclick="if (event.target === this) this.close()"{% endif %} + {% if close_on_overlay_click %}onpointerdown="this.dataset.backdropPress = event.target === this" onclick="if (event.target === this && this.dataset.backdropPress === 'true') this.close()"{% endif %} {% for key, value in dialog_attrs %} {% if key != 'class' %}{{ key }}="{{ value }}"{% endif %} {% endfor %}