Skip to content

Commit 25b567a

Browse files
committed
Fix DAP issues for overflow
1 parent 6d12104 commit 25b567a

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

src/dialog/overflow-menu/overflow-menu-option.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ import {
2323
<button
2424
class="bx--overflow-menu-options__btn"
2525
role="menuitem"
26+
tabindex="-1"
27+
(focus)="onFocus()"
28+
(blur)="onBlur()"
2629
[disabled]="disabled"
27-
[tabindex]="(disabled ? -1 : null)"
2830
[title]="(titleEnabled ? content : '')">
2931
<ng-content></ng-content>
3032
</button>
3133
`
3234
})
3335
export class OverflowMenuOption {
3436
@HostBinding("class") optionClass = "bx--overflow-menu-options__option";
35-
@HostBinding("attr.role") role = "presentation";
37+
@HostBinding("attr.role") role = "none";
3638

3739
@HostBinding("class.bx--overflow-menu-options__option--danger")
3840
public get isDanger(): Boolean {
@@ -73,4 +75,12 @@ export class OverflowMenuOption {
7375
get content(): string {
7476
return this.elementRef.nativeElement.querySelector("button").textContent;
7577
}
78+
79+
onFocus() {
80+
this.elementRef.nativeElement.querySelector("button").tabIndex = "0";
81+
}
82+
83+
onBlur() {
84+
this.elementRef.nativeElement.querySelector("button").tabIndex = "-1";
85+
}
7686
}

src/dialog/overflow-menu/overflow-menu-pane.component.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, ViewChild, HostListener, ElementRef } from "@angular/core";
1+
import { OverflowMenuOption } from "./overflow-menu-option.component";
2+
import { Component, HostListener, ElementRef, QueryList, AfterViewInit } from "@angular/core";
23
import { Dialog } from "../dialog.component";
34
import { position } from "../../utils/position";
45
import { isFocusInLastItem, isFocusInFirstItem } from "./../../common/tab.service";
@@ -13,19 +14,18 @@ import { I18n } from "./../../i18n/i18n.module";
1314
selector: "ibm-overflow-menu-pane",
1415
template: `
1516
<ul
17+
class="bx--overflow-menu-options bx--overflow-menu-options--open"
1618
role="menu"
17-
[attr.aria-label]="dialogConfig.menuLabel"
18-
#dialog
19-
class="bx--overflow-menu-options bx--overflow-menu-options--open">
19+
(focusout)="clickClose($event)"
20+
[attr.aria-label]="dialogConfig.menuLabel">
2021
<ng-template
2122
[ngTemplateOutlet]="dialogConfig.content"
2223
[ngTemplateOutletContext]="{overflowMenu: this}">
2324
</ng-template>
2425
</ul>
2526
`
2627
})
27-
export class OverflowMenuPane extends Dialog {
28-
@ViewChild("dialog") dialog;
28+
export class OverflowMenuPane extends Dialog implements AfterViewInit {
2929

3030
constructor(protected elementRef: ElementRef, protected i18n: I18n) {
3131
super(elementRef);
@@ -86,10 +86,22 @@ export class OverflowMenuPane extends Dialog {
8686
event.preventDefault();
8787
listItems[listItems.length - 1].focus();
8888
break;
89+
90+
case "Tab":
91+
this.doClose();
92+
}
93+
}
94+
95+
clickClose(event) {
96+
if (event.target === this.dialogConfig.parentRef.nativeElement.firstChild ||
97+
this.listItems().some(button => button === (event.relatedTarget)) ||
98+
(event.type === "focusout" && event.relatedTarget === this.dialogConfig.parentRef.nativeElement)) {
99+
return;
89100
}
101+
this.doClose();
90102
}
91103

92104
private listItems() {
93-
return Array.from<any>(this.dialog.nativeElement.querySelectorAll(".bx--overflow-menu-options__btn:not([disabled])"));
105+
return Array.from<any>(this.elementRef.nativeElement.querySelectorAll(".bx--overflow-menu-options__btn:not([disabled])"));
94106
}
95107
}

src/dialog/overflow-menu/overflow-menu.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { I18n } from "./../../i18n/i18n.module";
2121
[ngClass]="{'bx--overflow-menu--open': open === true}"
2222
[attr.aria-label]="buttonLabel"
2323
class="bx--overflow-menu"
24-
role="button"
2524
placement="bottom"
2625
style="display: block;"
2726
tabindex="0">

src/dialog/overflow-menu/overflow-menu.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ storiesOf("Overflow Menu", module)
1818
</ibm-overflow-menu-option>
1919
<ibm-overflow-menu-option>Option 2</ibm-overflow-menu-option>
2020
<li class="bx--overflow-menu-options__option">
21-
<button class="bx--overflow-menu-options__btn">A fully custom option</button>
21+
<button class="bx--overflow-menu-options__btn" tabindex="-1">A fully custom option</button>
2222
</li>
2323
<ibm-overflow-menu-option>Option 4</ibm-overflow-menu-option>
2424
<ibm-overflow-menu-option disabled="true">Disabled</ibm-overflow-menu-option>

0 commit comments

Comments
 (0)