Skip to content

Commit 88f76e9

Browse files
committed
Added events to tabs
1 parent 27d701b commit 88f76e9

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h1>Tab Group</h1>
5656
<wc-tab name="tab-buttons">Buttons</wc-tab>
5757
<wc-tab name="tab-badges">Badges</wc-tab>
5858
<wc-tab name="tab-icons">Icons</wc-tab>
59-
<wc-tab name="tab-diabled">Disabled</wc-tab>
59+
<wc-tab name="tab-disabled" disabled>Disabled</wc-tab>
6060
</wc-tab-group>
6161
</div>
6262
<hr>

src/nav/TabElement.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ export class TabElement extends LitElement {
7070

7171
render() {
7272
return html`
73-
<li class=${this.className || nothing}><slot></slot></li>
73+
<li class=${this.className || nothing} @click=${this.onClick}><slot></slot></li>
7474
`;
7575
}
76+
77+
onClick() {
78+
if (!this.disabled) {
79+
this.dispatchEvent(new CustomEvent(Event.EVENT_CLICK, {
80+
bubbles: true,
81+
composed: true,
82+
detail: this.name || this.textContent,
83+
}));
84+
}
85+
}
7686
}

src/nav/TabGroupElement.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export class TabGroupElement extends LitElement {
7777
.bg-color-dark ::slotted(wc-tab) {
7878
background-color: var(--dark-color);
7979
color: var(--light-color);
80+
border-width: 1px;
81+
border-style: solid;
82+
border-bottom: none;
8083
border-color: var(--grey-80-color);
8184
}
8285
.bg-color-dark ::slotted(wc-tab:hover) {
@@ -91,12 +94,15 @@ export class TabGroupElement extends LitElement {
9194
9295
/* light theme */
9396
ul.bg-color-light {
94-
border-bottom: 1px solid var(--grey-20-color);
97+
border-bottom: 1px solid var(--grey-40-color);
9598
}
9699
.bg-color-light ::slotted(wc-tab) {
97100
background-color: var(--light-color);
98101
color: var(--dark-color);
99-
border-color: var(--grey-20-color);
102+
border-width: 1px;
103+
border-style: solid;
104+
border-bottom: none;
105+
border-color: var(--grey-40-color);
100106
}
101107
.bg-color-light ::slotted(wc-tab:hover) {
102108
background-color: var(--primary-color);
@@ -126,4 +132,30 @@ export class TabGroupElement extends LitElement {
126132
<ul class=${this.className || nothing}><slot></slot></ul>
127133
`;
128134
}
135+
136+
firstUpdated() {
137+
this.addEventListener(Event.EVENT_CLICK, (evt) => this.onClick(evt));
138+
}
139+
140+
select(name) {
141+
const tabs = this.querySelectorAll('wc-tab');
142+
tabs.forEach((tab) => {
143+
if (tab.name === name && !tab.disabled) {
144+
if (!tab.selected) {
145+
console.log('SELECT', tab.name);
146+
tab.selected = true;
147+
}
148+
} else if (tab.selected) {
149+
console.log('DESELECT', tab.name);
150+
tab.selected = false;
151+
}
152+
});
153+
}
154+
155+
// eslint-disable-next-line class-methods-use-this
156+
onClick(event) {
157+
if (event.target && event.target.name && !event.target.disabled) {
158+
this.select(event.target.name);
159+
}
160+
}
129161
}

0 commit comments

Comments
 (0)