Skip to content

Commit e2a45bf

Browse files
RussellSproutsRyan Russell
and
Ryan Russell
authored
feat(material/core): Allow namespacing ripple-loader event handler (#28699)
ripple-loader registers an event handler on the document to do event delegation. If there are multiple instances of ripple-loader on one page, then they will both try to handle events for [mat-ripple-loader-uninitialized] elements. If a namespace is provided, then the handler will only handle events for [mat-ripple-loader-uninitialized="{namespace}"] elements. Co-authored-by: Ryan Russell <ryanrussell@google.com>
1 parent 20bf71c commit e2a45bf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/material/core/private/ripple-loader.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class MatRippleLoader implements OnDestroy {
8888
},
8989
): void {
9090
// Indicates that the ripple has not yet been rendered for this component.
91-
host.setAttribute(matRippleUninitialized, '');
91+
host.setAttribute(matRippleUninitialized, this._globalRippleOptions?.namespace ?? '');
9292

9393
// Store the additional class name(s) that should be added to the ripple element.
9494
if (config.className || !host.hasAttribute(matRippleClassName)) {
@@ -139,7 +139,9 @@ export class MatRippleLoader implements OnDestroy {
139139

140140
// TODO(wagnermaciel): Consider batching these events to improve runtime performance.
141141

142-
const element = eventTarget.closest(`[${matRippleUninitialized}]`);
142+
const element = eventTarget.closest(
143+
`[${matRippleUninitialized}="${this._globalRippleOptions?.namespace ?? ''}"]`,
144+
);
143145
if (element) {
144146
this._createRipple(element as HTMLElement);
145147
}

src/material/core/ripple/ripple.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface RippleGlobalOptions {
4242
* default, ripples will wait for the enter animation to complete and for mouse or touch release.
4343
*/
4444
terminateOnPointerUp?: boolean;
45+
46+
/**
47+
* A namespace to use for ripple loader to allow multiple instances to exist on the same page.
48+
*/
49+
namespace?: string;
4550
}
4651

4752
/** Injection token that can be used to specify the global ripple options. */

0 commit comments

Comments
 (0)