From 434da06579f8a2664e5caed618f2e63fcc544dd0 Mon Sep 17 00:00:00 2001 From: splincode Date: Tue, 17 Oct 2023 15:15:05 +0300 Subject: [PATCH] fix(core): use correct host portal viewport for dropdown position --- .../core/directives/dropdown/dropdown-position.directive.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/projects/core/directives/dropdown/dropdown-position.directive.ts b/projects/core/directives/dropdown/dropdown-position.directive.ts index fb3e26dad3987..28f18556b6480 100644 --- a/projects/core/directives/dropdown/dropdown-position.directive.ts +++ b/projects/core/directives/dropdown/dropdown-position.directive.ts @@ -44,15 +44,17 @@ export class TuiDropdownPositionDirective extends TuiPositionAccessor { top: hostRect.top - 2 * offset - viewport.top, bottom: viewport.bottom - hostRect.bottom - 2 * offset, } as const; + const left = + hostRect.left + width < viewport.right - offset ? hostRect.left : right; const position = { top: hostRect.top - offset - height, bottom: hostRect.bottom + offset, - right, + right: viewport.left > right ? viewport.left : right, center: hostRect.left + hostRect.width / 2 + width / 2 < viewport.right - offset ? hostRect.left + hostRect.width / 2 - width / 2 : right, - left: hostRect.left + width < viewport.right - offset ? hostRect.left : right, + left: viewport.left > left ? viewport.left : left, } as const; const better = available.top > available.bottom ? 'top' : 'bottom';