Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 772cc10

Browse files
asyncLizcopybara-github
authored andcommitted
fix(dialog): add property to customize suppressDefaultPressSelector
PiperOrigin-RevId: 351683721
1 parent cb2660e commit 772cc10

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/mdc-dialog/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ Method Signature | Description
425425
`handleClick(event: MouseEvent)` | Handles `click` events on or within the dialog's root element.
426426
`handleKeydown(event: KeyboardEvent)` | Handles `keydown` events on or within the dialog's root element.
427427
`handleDocumentKeydown(event: Event)` | Handles `keydown` events on or within the document while the dialog is open.
428+
`getSuppressDefaultPressSelector() => string` | Returns the selector string for elements that suppress the default dialog press action, such as pressing enter in a textarea.
429+
`setSuppressDefaultPressSelector(selector: string)` | Customize the selector string to suppress the default dialog press action. An empty string indicates that no elements should suppress the default action.
428430

429431
#### Event handlers
430432

packages/mdc-dialog/foundation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ export class MDCDialogFoundation extends MDCFoundation<MDCDialogAdapter> {
228228
// </horizontal-layout>
229229
// </mwc-dialog>
230230
const target = evt.composedPath ? evt.composedPath()[0] : evt.target;
231-
const isDefault = !this.adapter.eventTargetMatches(
232-
target, this.suppressDefaultPressSelector);
231+
const isDefault = this.suppressDefaultPressSelector ?
232+
!this.adapter.eventTargetMatches(
233+
target, this.suppressDefaultPressSelector) :
234+
true;
233235
if (isEnter && isDefault) {
234236
this.adapter.clickDefaultButton();
235237
}

0 commit comments

Comments
 (0)