Skip to content

Commit 1b536e1

Browse files
authored
Merge pull request #533 from danice/v2-dev
Tabs with Icons
2 parents c8d916a + 655b58c commit 1b536e1

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

sass/components/_tabs.scss

+31-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444

4545
position: relative;
4646
overflow-x: auto;
47-
overflow-y: hidden;
48-
height: 48px;
47+
overflow-y: hidden;
4948
width: 100%;
5049
background-color: var(--md-sys-color-surface);
5150
margin: 0 auto;
@@ -56,11 +55,21 @@
5655
list-style-type: none;
5756
display: inline-block;
5857
text-align: center;
59-
line-height: 48px;
60-
height: 48px;
58+
line-height: 48px;
6159
padding: 0;
6260
margin: 0;
6361

62+
i.material-icons {
63+
position: relative;
64+
top: 8px;
65+
vertical-align: middle;
66+
}
67+
68+
span {
69+
height: 24px;
70+
line-height: 20px;
71+
}
72+
6473
a {
6574
&.active {
6675
background-color: transparent;
@@ -83,9 +92,11 @@
8392
}
8493

8594
color: var(--md-sys-color-on-surface-variant);
86-
display: block;
95+
display: flex;
96+
flex-direction: column;
8797
width: 100%;
8898
height: 100%;
99+
min-height: 48px; //needed for only-icons tabs
89100
padding: 0 24px;
90101
font-size: 14px;
91102
text-overflow: ellipsis;
@@ -112,6 +123,21 @@
112123
will-change: left, right;
113124
border-radius: 3px 3px 0 0;
114125
}
126+
127+
&.tabs-horizontal .tab {
128+
height: 48px;
129+
130+
a {
131+
display: block;
132+
}
133+
134+
i.material-icons {
135+
padding: 0 4px;
136+
position: relative;
137+
top: -2px;
138+
vertical-align: middle;
139+
}
140+
}
115141
}
116142

117143
/* Fixed Sidenav hide on smaller */

src/tabs.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,16 @@ export class Tabs extends Component<TabsOptions> {
131131
}
132132

133133
_handleTabClick = (e: MouseEvent) => {
134-
const tabLink = e.target as HTMLAnchorElement;
135-
const tab = tabLink.parentElement;
134+
let tabLink = e.target as HTMLAnchorElement;
135+
136+
if (!tabLink)
137+
return;
138+
var tab = tabLink.parentElement;
139+
while (tab && !tab.classList.contains('tab')) {
140+
tabLink = tabLink.parentElement as HTMLAnchorElement;
141+
tab = tab.parentElement;
142+
}
143+
136144
// Handle click on tab link only
137145
if (!tabLink || !tab.classList.contains('tab')) return;
138146
// is disabled?

0 commit comments

Comments
 (0)