@cuby-ui/core 0.0.617 → 0.0.618

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3286,7 +3286,6 @@ class CuiDropdownDirective {
3286
3286
  this.document = inject(DOCUMENT);
3287
3287
  this.viewContainerRef = inject(ViewContainerRef);
3288
3288
  this.target = inject(ElementRef).nativeElement;
3289
- this.window = inject(CUI_WINDOW);
3290
3289
  this.SPACE_BETWEEN_TARGET_AND_LIST = 5;
3291
3290
  this.CONTAINER_SELECTOR = 'cui-dropdowns';
3292
3291
  this.DROPDOWN_SELECTOR = 'cui-dropdown';
@@ -3383,45 +3382,54 @@ class CuiDropdownDirective {
3383
3382
  }
3384
3383
  calculateDropdownPosition() {
3385
3384
  this.element.style.visibility = 'hidden';
3386
- setTimeout(() => {
3387
- const targetRect = this.target.getBoundingClientRect();
3388
- const container = this.findScrollableContainer(this.target);
3389
- const containerRect = container.getBoundingClientRect();
3390
- const { clientHeight, clientWidth } = this.document.documentElement;
3391
- const visibleTop = Math.max(targetRect.top, containerRect.top);
3392
- const visibleBottom = Math.min(targetRect.bottom, containerRect.bottom);
3393
- const dropdownHeight = this.element.offsetHeight;
3394
- const windowScrollY = !cuiCheckFixedPosition(this.target) ? this.window.scrollY : 0;
3395
- const shouldListOpenAbove = clientHeight - visibleBottom < dropdownHeight;
3396
- const shouldListAlignLeft = targetRect.left + dropdownHeight > clientWidth;
3397
- const orientation = this.orientation ?? (shouldListAlignLeft ? 'left' : 'right');
3398
- this.changePositionY({ shouldListOpenAbove, visibleTop, visibleBottom, dropdownHeight, windowScrollY });
3399
- this.changePositionX(orientation, clientWidth, targetRect);
3400
- this.element.style.visibility = 'visible';
3401
- });
3385
+ setTimeout(() => this.updateDropdownPosition());
3386
+ }
3387
+ updateDropdownPosition() {
3388
+ const targetRect = this.target.getBoundingClientRect();
3389
+ const containerRect = this.findScrollableContainer(this.target).getBoundingClientRect();
3390
+ const { clientHeight, clientWidth } = this.document.documentElement;
3391
+ const visibleTop = Math.max(targetRect.top, containerRect.top);
3392
+ const visibleBottom = Math.min(targetRect.bottom, containerRect.bottom);
3393
+ const shouldListAlignLeft = targetRect.left + this.element.offsetHeight > clientWidth;
3394
+ const orientation = this.orientation ?? (shouldListAlignLeft ? 'left' : 'right');
3395
+ this.changePositionX(orientation, clientWidth, targetRect);
3396
+ const dropdownHeight = this.element.offsetHeight;
3397
+ const shouldListOpenAbove = clientHeight - visibleBottom < dropdownHeight;
3398
+ this.changePositionY({ shouldListOpenAbove, visibleTop, visibleBottom, dropdownHeight });
3399
+ this.element.style.visibility = 'visible';
3402
3400
  }
3403
3401
  changePositionX(orientation, clientWidth, targetRect) {
3404
3402
  switch (orientation) {
3405
3403
  case 'right':
3406
3404
  this.element.style.left = 'auto';
3407
- this.element.style.right = `${clientWidth - targetRect.right}px`;
3405
+ this.changePositionRight(targetRect.right, clientWidth);
3408
3406
  break;
3409
3407
  case 'stretch':
3410
- this.element.style.left = `${targetRect.left}px`;
3411
- this.element.style.right = `${clientWidth - targetRect.right}px`;
3408
+ this.changePositionLeft(targetRect.left);
3409
+ this.changePositionRight(targetRect.right, clientWidth);
3412
3410
  break;
3413
3411
  default:
3414
3412
  this.element.style.right = 'auto';
3415
- this.element.style.left = `${targetRect.left}px`;
3413
+ this.changePositionLeft(targetRect.left);
3416
3414
  }
3417
3415
  }
3418
- changePositionY({ shouldListOpenAbove, visibleTop, visibleBottom, dropdownHeight, windowScrollY }) {
3416
+ changePositionLeft(left) {
3417
+ this.element.style.left = `${left}px`;
3418
+ const offsetLeft = this.element.getBoundingClientRect().left - left;
3419
+ this.element.style.left = `${left - offsetLeft}px`;
3420
+ }
3421
+ changePositionRight(right, clientWidth) {
3422
+ const position = clientWidth - right;
3423
+ this.element.style.right = `${position}px`;
3424
+ const offsetRight = this.element.getBoundingClientRect().right - right;
3425
+ this.element.style.right = `${position + offsetRight}px`;
3426
+ }
3427
+ changePositionY({ shouldListOpenAbove, visibleTop, visibleBottom, dropdownHeight }) {
3419
3428
  const offset = this.SPACE_BETWEEN_TARGET_AND_LIST;
3420
- if (shouldListOpenAbove) {
3421
- this.element.style.top = `${windowScrollY + visibleTop - dropdownHeight - offset}px`;
3422
- return;
3423
- }
3424
- this.element.style.top = `${windowScrollY + visibleBottom + offset}px`;
3429
+ const top = shouldListOpenAbove ? visibleTop - dropdownHeight - offset : visibleBottom + offset;
3430
+ this.element.style.top = `${top}px`;
3431
+ const offsetTop = this.element.getBoundingClientRect().top - top;
3432
+ this.element.style.top = `${top - offsetTop}px`;
3425
3433
  }
3426
3434
  findScrollableContainer(element) {
3427
3435
  let parent = element.parentElement;
@@ -4298,8 +4306,16 @@ class CuiSelectComponent {
4298
4306
  const distanceToBottom = viewport.clientHeight - target.bottom - this.SPACE_BETWEEN_BUTTON_AND_OPTIONS;
4299
4307
  const left = Math.max(this.VIEWPORT_PADDING, Math.min(target.left, viewport.clientWidth - optionsList.width - this.VIEWPORT_PADDING));
4300
4308
  this.isOptionsListAbove = distanceToBottom < optionsList.height && target.top > distanceToBottom;
4301
- node.style.left = window.scrollX + left + 'px';
4302
- node.style.top = window.scrollY + this.getOptionsListTop(target, optionsList) + 'px';
4309
+ this.changeOptionsListPosition(node, left, this.getOptionsListTop(target, optionsList));
4310
+ }
4311
+ changeOptionsListPosition(node, left, top) {
4312
+ node.style.left = `${left}px`;
4313
+ node.style.top = `${top}px`;
4314
+ const position = node.getBoundingClientRect();
4315
+ const offsetLeft = position.left - left;
4316
+ const offsetTop = position.top - top;
4317
+ node.style.left = `${left - offsetLeft}px`;
4318
+ node.style.top = `${top - offsetTop}px`;
4303
4319
  }
4304
4320
  getOptionsListTop(target, optionsList) {
4305
4321
  if (this.isOptionsListAbove) {