Skip to content

Commit

Permalink
Merge pull request #33 from github/add-committed-event
Browse files Browse the repository at this point in the history
Add `text-expander-committed` event
  • Loading branch information
Cbodfield authored Oct 28, 2022
2 parents fb4fc53 + fd03764 commit 5b5f7ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ expander.addEventListener('text-expander-value', function(event) {
})
```
**`text-expander-committed`** is fired after the underlying `input` value has been updated in the DOM. In `event.detail` you can find:
- `input`: The `HTMLInputElement` or `HTMLTextAreaElement` that just had `value` changes committed to the DOM.
```js
const expander = document.querySelector('text-expander')
expander.addEventListener('text-expander-committed', function(event) {
const {input} = event.detail
})
```
## Browser support
Browsers without native [custom element support][support] require a [polyfill][].
Expand Down
4 changes: 4 additions & 0 deletions src/text-expander-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class TextExpander {
this.input.selectionEnd = cursor
this.lookBackIndex = cursor
this.match = null

this.expander.dispatchEvent(
new CustomEvent('text-expander-committed', {cancelable: false, detail: {input: this.input}})
)
}

private onBlur() {
Expand Down

0 comments on commit 5b5f7ad

Please sign in to comment.