Skip to content

Commit 9c23375

Browse files
authored
Merge pull request #486 from youda97/overflow-links
feat(overflow-menu): Add overflow with links
2 parents 5a975ff + 79e2ba6 commit 9c23375

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
selector: "ibm-overflow-menu-option",
2525
template: `
2626
<button
27+
*ngIf="!href"
2728
class="bx--overflow-menu-options__btn"
2829
role="menuitem"
2930
[tabindex]="tabIndex"
@@ -32,8 +33,26 @@ import {
3233
(click)="onClick($event)"
3334
[disabled]="disabled"
3435
[attr.title]="title">
35-
<ng-content></ng-content>
36+
<ng-container *ngTemplateOutlet="tempOutlet"></ng-container>
3637
</button>
38+
39+
<a
40+
*ngIf="href"
41+
class="bx--overflow-menu-options__btn"
42+
role="menuitem"
43+
[tabindex]="tabIndex"
44+
(focus)="tabIndex = 0"
45+
(blur)="tabIndex = -1"
46+
(click)="onClick($event)"
47+
[attr.disabled]="disabled"
48+
[href]="href"
49+
[attr.title]="title">
50+
<ng-container *ngTemplateOutlet="tempOutlet"></ng-container>
51+
</a>
52+
53+
<ng-template #tempOutlet>
54+
<ng-content></ng-content>
55+
</ng-template>
3756
`
3857
})
3958
export class OverflowMenuOption implements AfterViewInit {
@@ -58,6 +77,8 @@ export class OverflowMenuOption implements AfterViewInit {
5877
*/
5978
@Input() disabled = false;
6079

80+
@Input() href: string;
81+
6182
@Output() selected: EventEmitter<any> = new EventEmitter();
6283

6384
public tabIndex = -1;
@@ -72,9 +93,9 @@ export class OverflowMenuOption implements AfterViewInit {
7293
}
7394

7495
ngAfterViewInit() {
75-
const button = this.elementRef.nativeElement.querySelector("button");
96+
const button = this.elementRef.nativeElement.querySelector("button, a");
7697
if (button.scrollWidth > button.offsetWidth) {
77-
this.title = this.elementRef.nativeElement.querySelector("button").textContent;
98+
this.title = button.textContent;
7899
}
79100
}
80101
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export class OverflowMenuPane extends Dialog implements AfterViewInit {
119119
}
120120

121121
protected listItems() {
122-
return Array.from<any>(this.elementRef.nativeElement.querySelectorAll(".bx--overflow-menu-options__btn:not([disabled])"));
122+
const selector = ".bx--overflow-menu-options__option:not([disabled]) .bx--overflow-menu-options__btn";
123+
return Array.from<HTMLElement>(this.elementRef.nativeElement.querySelectorAll(selector));
123124
}
124125
}

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,28 @@ storiesOf("Overflow Menu", module)
4949
props: {
5050
click: () => console.log("click"),
5151
selected: () => console.log("selected"),
52-
flip: boolean("Flip overflow to open on the left", false)
52+
flip: boolean("Flipped", false)
53+
}
54+
}))
55+
.add("With links", () => ({
56+
template: `
57+
<app-experimental-component></app-experimental-component>
58+
<ibm-overflow-menu [flip]="flip" >
59+
<ibm-overflow-menu-option href="https://www.ibm.com" (selected)="selected($event)" (click)="click($event)">
60+
An example option that is really long to show what should be done to handle long text
61+
</ibm-overflow-menu-option>
62+
<ibm-overflow-menu-option href="https://www.ibm.com" (selected)="selected($event)">Option 2</ibm-overflow-menu-option>
63+
<ibm-overflow-menu-option href="https://www.ibm.com" (selected)="selected($event)">Option 3</ibm-overflow-menu-option>
64+
<ibm-overflow-menu-option href="https://www.ibm.com" (selected)="selected($event)">Option 4</ibm-overflow-menu-option>
65+
<ibm-overflow-menu-option href="https://www.ibm.com" disabled="true" (selected)="selected($event)">Disabled</ibm-overflow-menu-option>
66+
<ibm-overflow-menu-option href="https://www.ibm.com" type="danger" (selected)="selected($event)">Danger option</ibm-overflow-menu-option>
67+
</ibm-overflow-menu>
68+
<ibm-placeholder></ibm-placeholder>
69+
`,
70+
props: {
71+
click: () => console.log("click"),
72+
selected: () => console.log("selected"),
73+
flip: boolean("Flipped", false)
5374
}
5475
}))
5576
.add("Dynamic", () => ({

0 commit comments

Comments
 (0)