Skip to content

Commit 5b5e9dd

Browse files
authored
Merge branch 'master' into tooltip-ie
2 parents 43afb4f + e03194f commit 5b5e9dd

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

src/dialog/dialog.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
135135
*/
136136
ngOnInit() {
137137
// fix for safari hijacking clicks
138-
document.body.firstElementChild.addEventListener("click", () => null, true);
138+
this.dialogService.singletonClickListen();
139139

140140
// bind events for hovering or clicking the host
141141
if (this.trigger === "hover" || this.trigger === "mouseenter") {

src/dialog/dialog.service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { PlaceholderService } from "./../placeholder/placeholder.module";
1818
*/
1919
@Injectable()
2020
export class DialogService {
21+
/**
22+
* Used in `singletonClickListen`, don't count on its existence and values.
23+
*/
24+
private static listeningForBodyClicks = false;
25+
2126
/**
2227
* Reflects the open or closed state of the `Dialog`.
2328
* @memberof DialogService
@@ -157,4 +162,23 @@ export class DialogService {
157162
}
158163
}
159164
}
165+
166+
/**
167+
* Fix for safari hijacking clicks.
168+
*
169+
* Runs on `ngOnInit` of every dialog. Ensures we don't have multiple listeners
170+
* because having many of them could degrade performance in certain cases (and is
171+
* not necessary for our use case)
172+
*
173+
* This is an internally used function, can change at any point (even get removed)
174+
* and changes to it won't be considered a breaking change. Use at your own risk.
175+
*/
176+
singletonClickListen() {
177+
console.log("singleton");
178+
if (!DialogService.listeningForBodyClicks) {
179+
console.log("singleton click");
180+
document.body.firstElementChild.addEventListener("click", () => null, true);
181+
DialogService.listeningForBodyClicks = true;
182+
}
183+
}
160184
}

src/dropdown/dropdown.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
390390
*/
391391
_appendToBody() {
392392
const positionDropdown = () => {
393-
let pos = position.findAbsolute(this.elementRef.nativeElement, this.dropdownWrapper, "bottom");
393+
let pos = position.findAbsolute(this.dropdownButton.nativeElement, this.dropdownWrapper, "bottom");
394394
// add -40 to the top position to account for carbon styles
395395
pos = position.addOffset(pos, -40, 0);
396396
pos = position.addOffset(pos, window.scrollY, window.scrollX);
@@ -399,7 +399,7 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
399399
this.dropdownMenu.nativeElement.style.display = "block";
400400
this.dropdownWrapper = document.createElement("div");
401401
this.dropdownWrapper.className = `dropdown ${this.elementRef.nativeElement.className}`;
402-
this.dropdownWrapper.style.width = this.elementRef.nativeElement.offsetWidth + "px";
402+
this.dropdownWrapper.style.width = this.dropdownButton.nativeElement.offsetWidth + "px";
403403
this.dropdownWrapper.style.position = "absolute";
404404
this.dropdownWrapper.appendChild(this.dropdownMenu.nativeElement);
405405
document.body.appendChild(this.dropdownWrapper);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
2+
import { ComponentFixture, TestBed } from "@angular/core/testing";
3+
import { StaticIconModule } from "../icon/static-icon.module";
4+
5+
import { TabHeaders } from "./tab-headers.component";
6+
7+
describe("TabHeadersComponent", () => {
8+
let component: TabHeaders;
9+
let fixture: ComponentFixture<TabHeaders>;
10+
11+
beforeEach(() => {
12+
TestBed.configureTestingModule({
13+
declarations: [TabHeaders],
14+
imports: [BrowserAnimationsModule, StaticIconModule],
15+
providers: []
16+
});
17+
18+
fixture = TestBed.createComponent(TabHeaders);
19+
component = fixture.componentInstance;
20+
});
21+
22+
it("should work", () => {
23+
expect(component instanceof TabHeaders).toBe(true);
24+
});
25+
});

src/tabs/tab-headers.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ import { Tab } from "./tab.component";
5353
'bx--tabs__nav-item--selected': tab.active
5454
}"
5555
class="bx--tabs__nav-item"
56-
role="presentation">
56+
role="presentation"
57+
(click)="selectTab(tabref, tab, i)">
5758
<a
5859
[attr.aria-selected]="tab.active"
5960
[attr.tabindex]="(tab.active?0:-1)"
6061
[attr.aria-controls]="tab.id"
61-
(click)="selectTab(tabref, tab, i)"
6262
(focus)="onTabFocus(tabref, i)"
6363
draggable="false"
6464
id="{{tab.id}}-header"

0 commit comments

Comments
 (0)