Skip to content

Commit a8e7088

Browse files
authored
chore: polish article and update example
Triggered by: https://supportheroes.telerik.com/ticket/1617570
1 parent 00c8507 commit a8e7088

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

knowledge-base/dialog-close-on-esc.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This knowledge base article answers to the following questions:
1313

1414
* How to make Dialog responsive to keyboard events when content is clicked?
1515
* Why doesn't ESC key work after clicking inside Dialog content?
16+
* How can I make the Dialog close with the ESC key after the title has been clicked?
1617
* How to maintain keyboard functionality in Dialog after focus changes?
1718

1819
When you click or focus inside the Dialog content area, the focus moves away from the Dialog component. As a result, the Dialog does not receive keyboard events, and pressing the `ESC` key does not close it. This behavior occurs because the keydown events are not invoked for the Dialog when the focus is on another element or the body tag.
@@ -28,8 +29,13 @@ To ensure the Dialog closes on `ESC` even after focusing the content, wrap the D
2829
Width="500px"
2930
Height="300px"
3031
Class="focusable-content">
32+
<DialogTitle>
33+
<div tabindex="0" class="dialog-wrapper">
34+
Focusable Title
35+
</div>
36+
</DialogTitle>
3137
<DialogContent>
32-
<div tabindex="0" class="dialog-content-wrapper">
38+
<div tabindex="0" class="dialog-wrapper">
3339
<p>Click anywhere in this content area, then press ESC to close the dialog.</p>
3440
</div>
3541
</DialogContent>
@@ -46,8 +52,19 @@ To ensure the Dialog closes on `ESC` even after focusing the content, wrap the D
4652
padding: 0;
4753
}
4854
55+
/* Remove default Dialog title padding to let wrapper handle it */
56+
.focusable-content .k-dialog-titlebar {
57+
padding: 0;
58+
}
59+
60+
/* Focusable wrapper that fills the entire Dialog title area */
61+
.focusable-content .k-dialog-titlebar-actions {
62+
padding-block: var(--kendo-spacing-3, 0.75rem);
63+
padding-inline: var(--kendo-spacing-4, 1rem);
64+
}
65+
4966
/* Focusable wrapper that fills the entire Dialog content area */
50-
.focusable-content .dialog-content-wrapper {
67+
.focusable-content .dialog-wrapper {
5168
padding: 1rem;
5269
outline: none;
5370
height: 100%;
@@ -56,9 +73,9 @@ To ensure the Dialog closes on `ESC` even after focusing the content, wrap the D
5673
}
5774
5875
/* Optional visual indication when the wrapper is focused */
59-
.focusable-content .dialog-content-wrapper:focus-within {
76+
/* .focusable-content .dialog-wrapper:focus-within {
6077
background-color: rgba(0, 123, 255, 0.05);
61-
}
78+
} */
6279
</style>
6380
6481
@code {

0 commit comments

Comments
 (0)