How to use the @angular/cdk/coercion.coerceElement function in @angular/cdk

To help you get started, we’ve selected a few @angular/cdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shlomiassaf / ngrid / libs / table / drag / src / lib / drag-and-drop / core / drop-list-ref.ts View on Github external
withElement(element: ElementRef | HTMLElement): this {
    // TODO: Workaround, see if we can push this through https://github.com/angular/material2/issues/15086
    (this as { -readonly [P in keyof PblDropListRef]: PblDropListRef[P] }).element = coerceElement(element);
    return this;
  }
github angular / components / src / cdk / drag-drop / drop-list-ref.ts View on Github external
}

    // Since the item may be in the `activeDraggables` already (e.g. if the user dragged it
    // into another container and back again), we have to ensure that it isn't duplicated.
    if (currentIndex > -1) {
      activeDraggables.splice(currentIndex, 1);
    }

    // Don't use items that are being dragged as a reference, because
    // their element has been moved down to the bottom of the body.
    if (newPositionReference && !this._dragDropRegistry.isDragging(newPositionReference)) {
      const element = newPositionReference.getRootElement();
      element.parentElement!.insertBefore(placeholder, element);
      activeDraggables.splice(newIndex, 0, item);
    } else {
      coerceElement(this.element).appendChild(placeholder);
      activeDraggables.push(item);
    }

    // The transform needs to be cleared so it doesn't throw off the measurements.
    placeholder.style.transform = '';

    // Note that the positions were already cached when we called `start` above,
    // but we need to refresh them since the amount of items has changed.
    this._cacheItemPositions();
    this.entered.next({item, container: this, currentIndex: this.getItemIndex(item)});
  }
github angular / components / src / cdk / drag-drop / drop-list-ref.ts View on Github external
_startScrollingIfNecessary(pointerX: number, pointerY: number) {
    if (this.autoScrollDisabled) {
      return;
    }

    let scrollNode: HTMLElement | Window | undefined;
    let verticalScrollDirection = AutoScrollVerticalDirection.NONE;
    let horizontalScrollDirection = AutoScrollHorizontalDirection.NONE;

    // Check whether we should start scrolling the container.
    if (this._isPointerNearDropContainer(pointerX, pointerY)) {
      const element = coerceElement(this.element);

      [verticalScrollDirection, horizontalScrollDirection] =
          getElementScrollDirections(element, this._clientRect, pointerX, pointerY);

      if (verticalScrollDirection || horizontalScrollDirection) {
        scrollNode = element;
      }
    }

    // Otherwise check if we can start scrolling the viewport.
    if (!verticalScrollDirection && !horizontalScrollDirection) {
      const {width, height} = this._viewportRuler.getViewportSize();
      const clientRect = {width, height, top: 0, right: width, bottom: height, left: 0};
      verticalScrollDirection = getVerticalScrollDirection(clientRect, pointerY);
      horizontalScrollDirection = getHorizontalScrollDirection(clientRect, pointerX);
      scrollNode = window;
github NG-ZORRO / ng-zorro-antd / components / core / no-animation / nz-no-animation.directive.ts View on Github external
private updateClass(): void {
    const element = coerceElement(this.element);
    if (!element) {
      return;
    }
    if (this.nzNoAnimation || this.animationType === 'NoopAnimations') {
      this.renderer.addClass(element, DISABLED_CLASSNAME);
    } else {
      this.renderer.removeClass(element, DISABLED_CLASSNAME);
    }
  }
}
github atinc / ngx-tethys / src / drag-drop / drag-ref.ts View on Github external
withRootElement(rootElement: ElementRef | HTMLElement): this {
        const element = coerceElement(rootElement);
        this.rootElement = element;
        this.registerDragDropEvents();
        return this;
    }
github angular / components / src / cdk / drag-drop / drag-ref.ts View on Github external
withRootElement(rootElement: ElementRef | HTMLElement): this {
    const element = coerceElement(rootElement);

    if (element !== this._rootElement) {
      if (this._rootElement) {
        this._removeRootElementListeners(this._rootElement);
      }

      element.addEventListener('mousedown', this._pointerDown, activeEventListenerOptions);
      element.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
      this._initialTransform = undefined;
      this._rootElement = element;
    }

    return this;
  }
github angular / components / src / cdk / drag-drop / drop-list-ref.ts View on Github external
private _handleScroll = () => {
    if (!this.isDragging()) {
      return;
    }

    const element = coerceElement(this.element);
    this._updateAfterScroll(this._scrollPosition, element.scrollTop, element.scrollLeft);
  }
github dynatrace-oss / barista / components / core / src / viewport / element-in-viewport.ts View on Github external
? new Observable(observer => {
        const intersectionObserver = new IntersectionObserver(
          entries => {
            observer.next(entries);
          },
          { threshold },
        );
        intersectionObserver.observe(coerceElement(element));
        return () => {
          intersectionObserver.disconnect();
        };
      }).pipe(
        flatMap(entries => entries),
github angular / components / src / cdk / drag-drop / drop-list-ref.ts View on Github external
private _removeListeners() {
    coerceElement(this.element).removeEventListener('scroll', this._handleScroll);
    this._viewportScrollSubscription.unsubscribe();
  }