Skip to content

Commit

Permalink
feat(material/core): Allow namespacing ripple-loader event handler (#…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
RussellSprouts and Ryan Russell committed Mar 13, 2024
1 parent 20bf71c commit e2a45bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/material/core/private/ripple-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class MatRippleLoader implements OnDestroy {
},
): void {
// Indicates that the ripple has not yet been rendered for this component.
host.setAttribute(matRippleUninitialized, '');
host.setAttribute(matRippleUninitialized, this._globalRippleOptions?.namespace ?? '');

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

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

const element = eventTarget.closest(`[${matRippleUninitialized}]`);
const element = eventTarget.closest(
`[${matRippleUninitialized}="${this._globalRippleOptions?.namespace ?? ''}"]`,
);
if (element) {
this._createRipple(element as HTMLElement);
}
Expand Down
5 changes: 5 additions & 0 deletions src/material/core/ripple/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export interface RippleGlobalOptions {
* default, ripples will wait for the enter animation to complete and for mouse or touch release.
*/
terminateOnPointerUp?: boolean;

/**
* A namespace to use for ripple loader to allow multiple instances to exist on the same page.
*/
namespace?: string;
}

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

0 comments on commit e2a45bf

Please sign in to comment.