Skip to content

Commit 9b846f2

Browse files
authored
Merge pull request #432 from cal-smith/master
fix(dropdown): make the dropdown.service offset configurable
2 parents ea5db26 + 846ca09 commit 9b846f2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ 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+
public set offset(value: { top?: number, left?: number }) {
12+
this._offset = Object.assign({}, defaultOffset, value);
13+
}
14+
15+
public get offset() {
16+
return this._offset;
17+
}
918
/**
1019
* reference to the body appended menu
1120
*/
@@ -17,6 +26,8 @@ export class DropdownService {
1726
*/
1827
protected resize: Subscription;
1928

29+
protected _offset = defaultOffset;
30+
2031
constructor(protected placeholderService: PlaceholderService) {}
2132

2233
/**
@@ -84,8 +95,7 @@ export class DropdownService {
8495

8596
protected positionDropdown(parentRef, menuRef) {
8697
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);
98+
pos = position.addOffset(pos, this.offset.top, this.offset.left);
8999
position.setElement(menuRef, pos);
90100
}
91101
}

0 commit comments

Comments
 (0)