DOM manipulation utilities for Material Components providing cross-browser compatibility, focus management, and accessibility features.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Event handling utilities for detecting and configuring passive event listeners to improve scroll performance.
Determine whether the current browser supports passive event listeners and return appropriate options.
/**
* Determine whether the current browser supports passive event listeners, and if so, use them
* @param globalObj - The global window object to test against (defaults to window)
* @returns {passive: true} if passive listeners are supported, false otherwise
*/
function applyPassive(globalObj?: Window): boolean | EventListenerOptions;Usage Examples:
import { applyPassive } from '@material/dom/events';
// Apply passive listeners for scroll events
const passiveOptions = applyPassive();
element.addEventListener('touchstart', handler, passiveOptions);
element.addEventListener('touchmove', handler, passiveOptions);
element.addEventListener('wheel', handler, passiveOptions);
// Use with custom window object (for testing or iframe contexts)
const iframeWindow = iframe.contentWindow;
const iframePassiveOptions = applyPassive(iframeWindow);
iframeElement.addEventListener('scroll', handler, iframePassiveOptions);Passive event listeners are a web standard that improves scrolling performance by telling the browser that the event handler will not call preventDefault(). This allows the browser to process scrolling immediately without waiting for JavaScript execution.
Use passive listeners for events where you:
Common events that benefit from passive listeners:
touchstarttouchmovewheelscrollThe function automatically detects support for passive listeners and returns:
{passive: true} - Modern browsers with passive listener supportfalse - Older browsers that don't support passive listenersThis ensures your code works consistently across all browsers while taking advantage of performance improvements when available.