1
1
import {
2
2
LitElement , html , css , nothing ,
3
3
} from 'lit' ;
4
+ import { TabElement } from './TabElement' ;
4
5
5
6
/**
6
7
* TabGroupElement
@@ -29,7 +30,6 @@ export class TabGroupElement extends LitElement {
29
30
30
31
static get properties ( ) {
31
32
return {
32
-
33
33
/**
34
34
* Background color of the tab group, one of primary, secondary, light, white, dark, black
35
35
*
@@ -104,15 +104,19 @@ export class TabGroupElement extends LitElement {
104
104
border-bottom: none;
105
105
border-color: var(--grey-40-color);
106
106
}
107
- .bg-color-light ::slotted(wc-tab:hover) {
107
+ .bg-color-light ::slotted(wc-tab:hover),::slotted(wc-tab:active),::slotted(wc-tab[selected]) {
108
108
background-color: var(--primary-color);
109
109
color: var(--white-color);
110
110
}
111
111
.bg-color-light ::slotted(wc-tab:active) {
112
- background-color: var(--primary-color);
113
- color: var(--white-color);
114
112
font-weight: var(--font-weight-bold);
115
- }
113
+ }
114
+ .bg-color-light ::slotted(wc-tab[disabled]) {
115
+ background-color: inherit;
116
+ font-weight: inherit;
117
+ color: var(--grey-40-color);
118
+ cursor: inherit;
119
+ }
116
120
` ;
117
121
}
118
122
@@ -137,23 +141,35 @@ export class TabGroupElement extends LitElement {
137
141
this . addEventListener ( Event . EVENT_CLICK , ( evt ) => this . onClick ( evt ) ) ;
138
142
}
139
143
144
+ /**
145
+ * Select a tab by name, and deselect all other tabs
146
+ * @param {String } name: The name of the tab to select
147
+ * @returns The node that was selected, or null
148
+ */
140
149
select ( name ) {
141
150
const tabs = this . querySelectorAll ( 'wc-tab' ) ;
151
+ let selectedNode = null ;
142
152
tabs . forEach ( ( tab ) => {
143
- if ( tab . name === name && ! tab . disabled ) {
144
- if ( ! tab . selected ) {
145
- tab . setAttribute ( 'selected' , true ) ;
146
- }
147
- } else if ( tab . selected ) {
148
- tab . selected = false ;
153
+ if ( tab . name === name && ! tab . selected ) {
154
+ tab . setAttribute ( 'selected' , 'selected' ) ;
155
+ selectedNode = tab ;
156
+ } else if ( tab . name !== name && tab . selected ) {
157
+ tab . removeAttribute ( 'selected' ) ;
149
158
}
150
159
} ) ;
160
+ return selectedNode ;
151
161
}
152
162
153
- // eslint-disable-next-line class-methods-use-this
154
163
onClick ( event ) {
155
- if ( event . target && event . target . name && ! event . target . disabled ) {
156
- this . select ( event . target . name ) ;
164
+ if ( event . target && event . target . name ) {
165
+ const selected = this . select ( event . target . name ) ;
166
+ if ( selected ) {
167
+ this . dispatchEvent ( new CustomEvent ( Event . EVENT_CLICK , {
168
+ bubbles : true ,
169
+ composed : true ,
170
+ detail : selected . name || selected . textContent ,
171
+ } ) ) ;
172
+ }
157
173
}
158
174
}
159
175
}
0 commit comments