Skip to content

Commit

Permalink
Merge pull request #86 from github/add-on-change-d-alias
Browse files Browse the repository at this point in the history
Add onChange and onChanged alias
  • Loading branch information
owenniblock authored Mar 8, 2024
2 parents 984ef06 + e1578c6 commit 3c74546
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
43 changes: 43 additions & 0 deletions custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
}
]
},
{
"kind": "field",
"name": "onChange"
},
{
"kind": "field",
"name": "onTabContainerChange"
Expand All @@ -161,6 +165,15 @@
"kind": "field",
"name": "onTabContainerChanged"
},
{
"kind": "field",
"name": "onChanged"
},
{
"kind": "field",
"name": "activeTab",
"readonly": true
},
{
"kind": "field",
"name": "activePanel",
Expand All @@ -179,6 +192,10 @@
}
]
},
{
"kind": "field",
"name": "selectedTabIndex"
},
{
"kind": "method",
"name": "selectTab",
Expand Down Expand Up @@ -356,6 +373,10 @@
}
]
},
{
"kind": "field",
"name": "onChange"
},
{
"kind": "field",
"name": "#onTabContainerChange",
Expand All @@ -382,12 +403,22 @@
"kind": "field",
"name": "onTabContainerChanged"
},
{
"kind": "field",
"name": "onChanged"
},
{
"kind": "field",
"name": "#tabList",
"privacy": "private",
"readonly": true
},
{
"kind": "field",
"name": "#tabListTabWrapper",
"privacy": "private",
"readonly": true
},
{
"kind": "field",
"name": "#beforeTabsSlot",
Expand Down Expand Up @@ -424,6 +455,11 @@
"privacy": "private",
"readonly": true
},
{
"kind": "field",
"name": "activeTab",
"readonly": true
},
{
"kind": "field",
"name": "activePanel",
Expand Down Expand Up @@ -507,6 +543,13 @@
}
]
},
{
"kind": "field",
"name": "selectedTabIndex",
"type": {
"text": "number"
}
},
{
"kind": "method",
"name": "selectTab",
Expand Down
16 changes: 16 additions & 0 deletions src/tab-container-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ export class TabContainerElement extends HTMLElement {
return this
}

get onChange() {
return this.onTabContainerChange
}

set onChange(listener: ((event: TabContainerChangeEvent) => void) | null) {
this.onTabContainerChange = listener
}

#onTabContainerChange: ((event: TabContainerChangeEvent) => void) | null = null
get onTabContainerChange() {
return this.#onTabContainerChange
Expand Down Expand Up @@ -67,6 +75,14 @@ export class TabContainerElement extends HTMLElement {
}
}

get onChanged() {
return this.onTabContainerChanged
}

set onChanged(listener: ((event: TabContainerChangeEvent) => void) | null) {
this.onTabContainerChanged = listener
}

static observedAttributes = ['vertical']

get #tabList() {
Expand Down
24 changes: 24 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ describe('tab-container', function () {
el.dispatchEvent(new Event('tab-container-changed'))
assert.equal(called, true)
})

it('has an onChange property that is aliased to onTabContainerChange', function () {
const el = document.createElement('tab-container')
let called = false
const listener = () => (called = true)
el.onChange = listener
assert.equal(el.onTabContainerChange, listener)
assert.equal(el.onChange, listener)
assert.equal(called, false)
el.dispatchEvent(new Event('tab-container-change'))
assert.equal(called, true)
})

it('has an onChanged property that is aliased to onTabContainerChanged', function () {
const el = document.createElement('tab-container')
let called = false
const listener = () => (called = true)
el.onChanged = listener
assert.equal(el.onTabContainerChanged, listener)
assert.equal(el.onChanged, listener)
assert.equal(called, false)
el.dispatchEvent(new Event('tab-container-changed'))
assert.equal(called, true)
})
})

describe('after tree insertion with aria-selected on second tab', function () {
Expand Down

0 comments on commit 3c74546

Please sign in to comment.