Skip to content

didResize

The didResize modifier triggers a callback when resize events are observed on the target element.

Signature

typescript
interface DidResizeSignature {
  Args: {
    Positional: [handler: DidResizeHandler, options?: ResizeObserverOptions];
  };
  Element: Element;
}

type DidResizeHandler = (
  entry: ResizeObserverEntry,
  observer: ResizeObserver,
) => void;

Arguments

ArgumentTypeRequiredDescription
handler(entry: ResizeObserverEntry, observer: ResizeObserver) => voidYesCallback invoked on resize
optionsResizeObserverOptionsNoOptions passed to ResizeObserver.observe()

Handler Parameters

ParameterTypeDescription
entryResizeObserverEntryContains the new dimensions of the observed element
observerResizeObserverThe ResizeObserver instance

ResizeObserverOptions

OptionTypeDefaultDescription
box'content-box' | 'border-box' | 'device-pixel-content-box''content-box'Which box model to observe

Implementation Details

  • Uses a single shared ResizeObserver instance across all uses of the modifier for optimal performance.
  • Handlers are stored in a WeakMap keyed by the observed element.
  • Resize callbacks are batched via requestAnimationFrame.
  • Automatically cleans up (unobserves) when the element is destroyed or when arguments change.
  • Becomes a no-op in browsers that don't support ResizeObserver.

Importing

typescript
// Default export (modifier class)
import DidResizeModifier from 'ember-resize-modifier/modifiers/did-resize';

// Named export
import { didResize } from 'ember-resize-modifier';

Example