@@ -140,6 +140,7 @@ class PfeTabs extends PFElement {
140140 this . _linked = false ;
141141
142142 this . _onSlotChange = this . _onSlotChange . bind ( this ) ;
143+ this . _onClick = this . _onClick . bind ( this ) ;
143144
144145 this . _tabSlot = this . shadowRoot . querySelector ( 'slot[name="tab"]' ) ;
145146 this . _panelSlot = this . shadowRoot . querySelector ( 'slot[name="panel"]' ) ;
@@ -152,7 +153,7 @@ class PfeTabs extends PFElement {
152153 super . connectedCallback ( ) ;
153154
154155 this . addEventListener ( "keydown" , this . _onKeyDown ) ;
155- this . addEventListener ( "click" , this . _onClick ) ;
156+ // this.addEventListener("click", this._onClick);
156157
157158 if ( ! this . hasAttribute ( "role" ) ) {
158159 this . setAttribute ( "role" , "tablist" ) ;
@@ -163,14 +164,14 @@ class PfeTabs extends PFElement {
163164 }
164165
165166 Promise . all ( [
166- customElements . whenDefined ( RhTab . tag ) ,
167- customElements . whenDefined ( RhTabPanel . tag )
167+ customElements . whenDefined ( PfeTab . tag ) ,
168+ customElements . whenDefined ( PfeTabPanel . tag )
168169 ] ) . then ( ( ) => this . _linkPanels ( ) ) ;
169170 }
170171
171172 disconnectedCallback ( ) {
172173 this . removeEventListener ( "keydown" , this . _onKeyDown ) ;
173- this . removeEventListener ( "click" , this . _onClick ) ;
174+ this . _allTabs ( ) . forEach ( tab => tab . removeEventListener ( "click" , this . _onClick ) )
174175 }
175176
176177 attributeChangedCallback ( attr , oldValue , newValue ) {
@@ -203,8 +204,8 @@ class PfeTabs extends PFElement {
203204
204205 case "selected-index" :
205206 Promise . all ( [
206- customElements . whenDefined ( RhTab . tag ) ,
207- customElements . whenDefined ( RhTabPanel . tag )
207+ customElements . whenDefined ( PfeTab . tag ) ,
208+ customElements . whenDefined ( PfeTabPanel . tag )
208209 ] ) . then ( ( ) => {
209210 this . _linkPanels ( ) ;
210211 this . selectIndex ( newValue ) ;
@@ -265,6 +266,8 @@ class PfeTabs extends PFElement {
265266
266267 tab . setAttribute ( "aria-controls" , panel . id ) ;
267268 panel . setAttribute ( "aria-labelledby" , tab . id ) ;
269+
270+ tab . addEventListener ( "click" , this . _onClick ) ;
268271 } ) ;
269272
270273 this . _linked = true ;
@@ -408,15 +411,15 @@ class PfeTabs extends PFElement {
408411 }
409412
410413 _onClick ( event ) {
411- if ( event . target . getAttribute ( "role" ) !== "tab" ) {
414+ if ( event . currentTarget . getAttribute ( "role" ) !== "tab" ) {
412415 return ;
413416 }
414417
415- this . selectedIndex = this . _getTabIndex ( event . target ) ;
418+ this . selectedIndex = this . _getTabIndex ( event . currentTarget ) ;
416419 }
417420}
418421
419- class RhTab extends PFElement {
422+ class PfeTab extends PFElement {
420423 static get tag ( ) {
421424 return "pfe-tab" ;
422425 }
@@ -434,16 +437,16 @@ class RhTab extends PFElement {
434437 }
435438
436439 constructor ( ) {
437- super ( RhTab ) ;
438-
439- if ( ! this . id ) {
440- this . id = `${ RhTab . tag } -${ generateId ( ) } ` ;
441- }
440+ super ( PfeTab ) ;
442441 }
443442
444443 connectedCallback ( ) {
445444 super . connectedCallback ( ) ;
446445
446+ if ( ! this . id ) {
447+ this . id = `${ PfeTab . tag } -${ generateId ( ) } ` ;
448+ }
449+
447450 this . setAttribute ( "role" , "tab" ) ;
448451 this . setAttribute ( "aria-selected" , "false" ) ;
449452 this . setAttribute ( "tabindex" , - 1 ) ;
@@ -468,7 +471,7 @@ class RhTab extends PFElement {
468471 }
469472}
470473
471- class RhTabPanel extends PFElement {
474+ class PfeTabPanel extends PFElement {
472475 static get tag ( ) {
473476 return "pfe-tab-panel" ;
474477 }
@@ -482,23 +485,23 @@ class RhTabPanel extends PFElement {
482485 }
483486
484487 constructor ( ) {
485- super ( RhTabPanel ) ;
486-
487- if ( ! this . id ) {
488- this . id = `${ RhTabPanel . tag } -${ generateId ( ) } ` ;
489- }
488+ super ( PfeTabPanel ) ;
490489 }
491490
492491 connectedCallback ( ) {
493492 super . connectedCallback ( ) ;
494493
494+ if ( ! this . id ) {
495+ this . id = `${ PfeTabPanel . tag } -${ generateId ( ) } ` ;
496+ }
497+
495498 this . setAttribute ( "role" , "tabpanel" ) ;
496499 this . setAttribute ( "tabindex" , 0 ) ;
497500 }
498501}
499502
500- PFElement . create ( RhTab ) ;
501- PFElement . create ( RhTabPanel ) ;
503+ PFElement . create ( PfeTab ) ;
504+ PFElement . create ( PfeTabPanel ) ;
502505PFElement . create ( PfeTabs ) ;
503506
504507export { PfeTabs as default } ;
0 commit comments