Skip to content

Commit 148fbca

Browse files
committed
fix(dropdown): make the dropdown.service offset configurable
1 parent bb165b1 commit 148fbca

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/dropdown/dropdown.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
9191
@Input() type: "single" | "multi" = "single";
9292
/**
9393
* `light` or `dark` dropdown theme
94-
* @memberof Dropdown
9594
*/
9695
@Input() theme: "light" | "dark" = "dark";
9796
/**
@@ -209,6 +208,8 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
209208
if (this.view) {
210209
this.view.type = this.type;
211210
}
211+
// add -40 to the top position to account for carbon styles
212+
this.dropdownService.offset = { top: -40 };
212213
}
213214

214215
/**
@@ -492,7 +493,7 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
492493
}
493494

494495
/**
495-
* Add scroll event listenter if scrollableContainer is provided
496+
* Add scroll event listener if scrollableContainer is provided
496497
*/
497498
addScrollEventListener() {
498499
if (this.scrollableContainer) {

src/dropdown/dropdown.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ import { fromEvent, Subscription } from "rxjs";
44
import { throttleTime } from "rxjs/operators";
55
import position from "./../utils/position";
66

7+
const defaultOffset = { top: 0, left: 0 };
8+
79
@Injectable()
810
export class DropdownService {
11+
12+
public set offset(value: { top?: number, left?: number }) {
13+
this._offset = Object.assign({}, defaultOffset, value);
14+
}
15+
16+
public get offset() {
17+
return this._offset;
18+
}
919
/**
1020
* reference to the body appended menu
1121
*/
@@ -17,6 +27,8 @@ export class DropdownService {
1727
*/
1828
protected resize: Subscription;
1929

30+
protected _offset = defaultOffset;
31+
2032
constructor(protected placeholderService: PlaceholderService) {}
2133

2234
/**
@@ -84,8 +96,7 @@ export class DropdownService {
8496

8597
protected positionDropdown(parentRef, menuRef) {
8698
let pos = position.findAbsolute(parentRef, menuRef, "bottom");
87-
// add -40 to the top position to account for carbon styles
88-
pos = position.addOffset(pos, -40, 0);
99+
pos = position.addOffset(pos, this.offset.top, this.offset.left);
89100
position.setElement(menuRef, pos);
90101
}
91102
}

0 commit comments

Comments
 (0)