Skip to content

Commit

Permalink
Merge pull request #68 from github/add-keys-setter
Browse files Browse the repository at this point in the history
Add keys setter
  • Loading branch information
keithamus authored Oct 10, 2024
2 parents 38af472 + e606cd1 commit 4d6e63e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/text-expander-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ export default class TextExpanderElement extends HTMLElement {
return keys.map(key => ({key, multiWord: globalMultiWord || multiWord.includes(key)}))
}

set keys(value: string) {
this.setAttribute('keys', value)
}

connectedCallback(): void {
const input = this.querySelector('input[type="text"], textarea')
if (!(input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement)) return
Expand Down
22 changes: 22 additions & 0 deletions test/text-expander-element-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ describe('text-expander element', function () {
)
})

it('sets keys', function () {
const expander = document.querySelector('text-expander')
assert.deepEqual(
[
{key: '@', multiWord: false},
{key: '#', multiWord: true},
{key: '[[', multiWord: true}
],
expander.keys
)

expander.keys = '@ [['

assert.deepEqual(
[
{key: '@', multiWord: false},
{key: '[[', multiWord: true}
],
expander.keys
)
})

it('dispatches change event for multi-word', async function () {
const expander = document.querySelector('text-expander')
const input = expander.querySelector('textarea')
Expand Down

0 comments on commit 4d6e63e

Please sign in to comment.