Skip to content

Commit ba82d73

Browse files
authored
Merge pull request #293 from cal-smith/master
fix(overflow-menu): positioning bugs
2 parents f9afd41 + 8693437 commit ba82d73

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

package-lock.json

Lines changed: 7 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"@types/node": "8.5.2",
9797
"angular2-template-loader": "0.6.2",
9898
"babel-loader": "8.0.4",
99-
"carbon-components": "9.42.3",
99+
"carbon-components": "9.56.2",
100100
"codelyzer": "4.5.0",
101101
"commitizen": "2.10.1",
102102
"core-js": "2.5.5",

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ export class OverflowMenuPane extends Dialog implements AfterViewInit {
3636

3737
onDialogInit() {
3838
/**
39-
* -20 shifts the menu up to compensate for the
40-
* extra offset generated by the wrapper component.
41-
*
4239
* 60 shifts the menu right to align the arrow.
4340
* (position service trys it's best to center everything,
4441
* so we need to add some compensation)
4542
*/
4643
this.addGap["bottom"] = pos => {
4744
if (this.dialogConfig.flip) {
48-
return position.addOffset(pos, -20, -60);
45+
return position.addOffset(pos, 0, -60);
4946
}
50-
return position.addOffset(pos, -20, 60);
47+
return position.addOffset(pos, 0, 60);
5148
};
5249

5350
if (!this.dialogConfig.menuLabel) {
@@ -103,15 +100,19 @@ export class OverflowMenuPane extends Dialog implements AfterViewInit {
103100
}
104101

105102
ngAfterViewInit() {
106-
const focusElementList = this.listItems();
107-
focusElementList.forEach(button => {
108-
// Allows user to set tabindex to 0.
109-
if (button.getAttribute("tabindex") === null) {
110-
button.tabIndex = -1;
111-
}
103+
// wait for the menu to exist in the DOM before setting focus
104+
// TODO: work on a more elegant solution (afterDialogInit hook maybe?)
105+
setTimeout(() => {
106+
const focusElementList = this.listItems();
107+
focusElementList.forEach(button => {
108+
// Allows user to set tabindex to 0.
109+
if (button.getAttribute("tabindex") === null) {
110+
button.tabIndex = -1;
111+
}
112+
});
113+
focusElementList[0].tabIndex = 0;
114+
focusElementList[0].focus();
112115
});
113-
focusElementList[0].tabIndex = 0;
114-
focusElementList[0].focus();
115116
super.ngAfterViewInit();
116117
}
117118

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Component, ElementRef, Input } from "@angular/core";
1+
import {
2+
Component,
3+
ElementRef,
4+
Input,
5+
ViewEncapsulation
6+
} from "@angular/core";
27
import { I18n } from "./../../i18n/i18n.module";
38

49
/**
@@ -40,7 +45,20 @@ import { I18n } from "./../../i18n/i18n.module";
4045
.bx--overflow-menu--open {
4146
opacity: 1
4247
}
43-
`]
48+
49+
/*
50+
Rotate the overflow menu container as well as the icon, since
51+
we calculate our menu position based on the container, not the icon.
52+
*/
53+
.bx--data-table-v2 .bx--overflow-menu {
54+
transform: rotate(90deg);
55+
}
56+
57+
.bx--data-table-v2 .bx--overflow-menu__icon {
58+
transform: rotate(180deg);
59+
}
60+
`],
61+
encapsulation: ViewEncapsulation.None
4462
})
4563
export class OverflowMenu {
4664

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { storiesOf, moduleMetadata } from "@storybook/angular";
2-
import { withKnobs, boolean, number } from "@storybook/addon-knobs/angular";
2+
import { withKnobs, boolean, number } from "@storybook/addon-knobs";
33

44
import { DialogModule } from "../../";
55

@@ -60,7 +60,8 @@ storiesOf("Overflow Menu", module)
6060
.add("Dynamic", () => ({
6161
template: `
6262
<span>
63-
Dynamic <code style="font-family: monospace;">OverflowMenu</code>, using the <code style="font-family: monospace;">optionCount</code> knob <br/>
63+
Dynamic <code style="font-family: monospace;">OverflowMenu</code>,
64+
using the <code style="font-family: monospace;">optionCount</code> knob <br/>
6465
to change the number of menu options
6566
</span>
6667
<ibm-overflow-menu>

0 commit comments

Comments
 (0)