Skip to content

Commit 574a09e

Browse files
committed
Add focus to dialog with tabbable content inside
1 parent c7fec8b commit 574a09e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/dialog/dialog.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { throttleTime } from "rxjs/operators";
2020
// the AbsolutePosition is required to import the declaration correctly
2121
import position, { AbsolutePosition } from "./../utils/position";
22-
import { cycleTabs } from "./../common/tab.service";
22+
import { cycleTabs, getFocusElementList } from "./../common/tab.service";
2323
import { DialogConfig } from "./dialog-config.interface";
2424

2525

@@ -146,6 +146,9 @@ export class Dialog implements OnInit, AfterViewInit, OnDestroy {
146146
}
147147
}
148148
this.placeDialog();
149+
if (getFocusElementList(this.dialog.nativeElement).length > 0) {
150+
dialogElement.focus();
151+
}
149152
const parentEl: HTMLElement = this.dialogConfig.parentRef.nativeElement;
150153
let node = parentEl;
151154
let observables = [];

src/dialog/tooltip/tooltip.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import {
22
Component,
33
TemplateRef,
44
HostBinding,
5-
HostListener
5+
HostListener,
6+
Input
67
} from "@angular/core";
8+
import { getFocusElementList } from "./../../common/tab.service";
9+
710
import { Dialog } from "./../dialog.component";
811

912
/**
@@ -14,6 +17,7 @@ import { Dialog } from "./../dialog.component";
1417
template: `
1518
<div
1619
#dialog
20+
[tabindex]="tabIndex"
1721
[id]="dialogConfig.compID"
1822
role="tooltip"
1923
class="bx--tooltip bx--tooltip--shown">
@@ -37,10 +41,13 @@ export class Tooltip extends Dialog {
3741
*/
3842
public hasContentTemplate = false;
3943

44+
@Input() tabIndex;
4045
/**
4146
* Check whether there is a template for the `Tooltip` content.
4247
*/
4348
onDialogInit() {
4449
this.hasContentTemplate = this.dialogConfig.content instanceof TemplateRef;
50+
51+
this.tabIndex = getFocusElementList(this.dialog.nativeElement).length > 0 ? 0 : -1;
4552
}
4653
}

0 commit comments

Comments
 (0)