Skip to content

Commit

Permalink
Merge pull request #2552 from kirbydesign/bug/2500-dropdown-opening-d…
Browse files Browse the repository at this point in the history
…irection

Fix dropdown opening direction when button intersects bottom of viewport
  • Loading branch information
mark-drastrup authored Oct 25, 2022
2 parents 0838445 + e863478 commit 93d2218
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ViewChildren,
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { DesignTokenHelper } from '../../helpers';

import { ButtonComponent } from '../button/button.component';
import { CardComponent } from '../card/card.component';
Expand Down Expand Up @@ -277,8 +278,15 @@ export class DropdownComponent implements AfterViewInit, OnDestroy, ControlValue
private initializeAlignment() {
if (this.usePopover) return;
if (!this.intersectionObserverRef) {
// Get the design token size of the button. In the button stylesheet a medium button height is utils.size(xl)
// and a small button height is utils.size("l")
const designTokenSizeHeight = this.size === 'md' ? 'xl' : 'l';

// Setting the rootMargin equal to the height of the button
// allows the Intersection Observer Callback to be called
// even if the dropdown button is intersecting with the viewport
const options = {
rootMargin: '0px',
rootMargin: DesignTokenHelper.size(designTokenSizeHeight),
};
const callback: IntersectionObserverCallback = (entries) => {
// Only apply alignment when opening:
Expand Down

0 comments on commit 93d2218

Please sign in to comment.