Skip to content

Commit

Permalink
fix(ld-tabs): emit tab change event from within the ld-tabs component
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur authored and renet committed Sep 20, 2021
1 parent 615f0b4 commit 6b31d70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/liquid/components/ld-tabs/ld-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class LdTab {
/**
* Emitted with the id of the selected tab.
*/
@Event() tabChange: EventEmitter<string>
@Event() tabSelect: EventEmitter<string>

private handleTabClick(ev) {
ev.preventDefault()
Expand All @@ -55,7 +55,7 @@ export class LdTab {
this.el
)

this.tabChange.emit(index)
this.tabSelect.emit(index)
}

render() {
Expand Down
21 changes: 18 additions & 3 deletions src/liquid/components/ld-tabs/ld-tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import '../../components' // type definitions for type checks and intelliSense
import { Component, Element, h, Host, Prop } from '@stencil/core'
import {
Component,
Element,
Event,
EventEmitter,
h,
Host,
Prop,
} from '@stencil/core'
import { getClassNames } from '../../utils/getClassNames'

let tabsCount = 0
Expand All @@ -25,6 +33,11 @@ export class LdTabs {
/** Sets border radii. */
@Prop() rounded?: 'all' | 'all-lg' | 'top' | 'top-lg'

/**
* Emitted with the id of the selected tab.
*/
@Event() tabChange: EventEmitter<string>

private idDescriber = `ld-tabs-${tabsCount++}`

private updateTabs(currentLdTab) {
Expand All @@ -50,10 +63,12 @@ export class LdTabs {
.classList.remove('ld-tabpanel--hidden')
}

private handleTabChange(ev) {
private handleTabSelect(ev) {
ev.stopImmediatePropagation()
const currentLdTab = ev.target
this.updateTabs(currentLdTab)
this.updateTabPanels(currentLdTab)
this.tabChange.emit(ev.detail)
}

componentDidRender() {
Expand Down Expand Up @@ -82,7 +97,7 @@ export class LdTabs {
render() {
return (
<Host
onTabChange={this.handleTabChange.bind(this)}
onTabSelect={this.handleTabSelect.bind(this)}
class={getClassNames([
'ld-tabs',
this.size && `ld-tabs--${this.size}`,
Expand Down
7 changes: 7 additions & 0 deletions src/liquid/components/ld-tabs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ document.getElementById('nuts_button_2').addEventListener('click', ev => {
| `size` | `size` | Size of the tabs. | `"lg" \| "sm"` | `undefined` |


## Events

| Event | Description | Type |
| ----------- | ---------------------------------------- | --------------------- |
| `tabChange` | Emitted with the id of the selected tab. | `CustomEvent<string>` |


----------------------------------------------


0 comments on commit 6b31d70

Please sign in to comment.