Skip to content

Commit 54a40bf

Browse files
fix(material/dialog): reserve room for touch targets in scrollable content
`mat-dialog-content` scrolls, and its block-end padding is zero when the dialog has an actions row. Buttons, checkboxes and radios center a 48px touch target on a 40px control, and slide toggles center one on a 32px switch, so the target overhangs the control by 4-8px. An overhanging target at the end of the content is scrollable overflow, so a dialog whose content ends in one of those controls paints a scrollbar over content that fits. Reserve the overhang in the block-end padding instead. This keeps the touch targets at their accessible size, which the alternatives do not: disabling them (`touch-target-display: none`) shrinks the tap area, and anchoring them so they only overhang the block-start edge still left 4px of overflow in WebKit in local testing. Verified with a stock Material app in Chromium, Firefox and WebKit. A dialog with a trailing checkbox, radio, slide toggle or button goes from 4px, 4px, 8px and 4px of scrollable overflow respectively to 0 in all three engines. Dialogs with actions grow by 8px, which is the trade-off for not touching the tap areas. Fixes #29164.
1 parent 5fcd952 commit 54a40bf

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/material/dialog/_m3-dialog.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
dialog-container-small-max-width: calc(100vw - 32px),
2424
dialog-content-padding: 20px 24px,
2525
dialog-headline-padding: 6px 24px 13px,
26-
dialog-with-actions-content-padding: 20px 24px 0,
26+
// The block-end value reserves room for the touch targets of any controls at the end of
27+
// the content, which would otherwise be scrollable overflow. See dialog.scss.
28+
dialog-with-actions-content-padding: 20px 24px 8px,
2729
),
2830
color: (
2931
dialog-container-color: map.get($system, surface),

src/material/dialog/dialog.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,15 @@ $fallbacks: m3-dialog.get-tokens();
191191

192192
// Note: we can achieve this with a `:has` selector, but it results in an
193193
// increased specificity which breaks a lot of internal clients.
194+
//
195+
// The block-end padding reserves room for the touch targets of the controls the content may
196+
// contain. Buttons, checkboxes and radios center a 48px touch target on a 40px control and
197+
// slide toggles center one on a 32px switch, so the target overhangs the control by up to
198+
// 8px. Since this element scrolls, an overhanging target at the end of the content is
199+
// scrollable overflow, and the dialog shows a scrollbar over content that fits. Reserving
200+
// the overhang fixes it without shrinking the targets below their accessible size.
194201
.mat-mdc-dialog-container-with-actions & {
195-
padding: token-utils.slot(dialog-with-actions-content-padding, $fallbacks, 20px 24px 0);
202+
padding: token-utils.slot(dialog-with-actions-content-padding, $fallbacks, 20px 24px 8px);
196203
}
197204

198205
.mat-mdc-dialog-container .mat-mdc-dialog-title + & {

0 commit comments

Comments
 (0)