diff --git a/packages/language-select/src/language-select.js b/packages/language-select/src/language-select.js index 21d87172c459d9c01c77318ab82d7c6b6c52841b..da63a77414e764cf34736c087b1e581ec32cc717 100644 --- a/packages/language-select/src/language-select.js +++ b/packages/language-select/src/language-select.js @@ -21,14 +21,22 @@ class LanguageSelect extends LitElement { i18n.t('en-action'); } - _getNextLanguage() { - var index = this.languages.indexOf(this.lang); + _getNextLanguage(lang) { + var index = this.languages.indexOf(lang); var next = this.languages[index + 1]; if (typeof next === 'undefined') next = this.languages[0]; return next; } + _getPreviousLanguage(lang) { + var index = this.languages.indexOf(lang); + var prev = this.languages[index - 1]; + if (typeof prev === 'undefined') + prev = this.languages[this.languages.length - 1]; + return prev; + } + static get properties() { return { lang: {type: String}, @@ -63,10 +71,11 @@ class LanguageSelect extends LitElement { } set next(value) { + this.lang = this._getPreviousLanguage(value); } get next() { - return this._getNextLanguage(); + return this._getNextLanguage(this.lang); } static get styles() { diff --git a/packages/language-select/test/unit.js b/packages/language-select/test/unit.js index 3511aa8aa474549fc6b813d51afd5d05a7dff810..1ac3cc0c04b54d1a7b7dbbf56129f3e9191e0e36 100644 --- a/packages/language-select/test/unit.js +++ b/packages/language-select/test/unit.js @@ -34,6 +34,16 @@ describe('vpu-language-select basics', () => { expect(node.next).to.equal('en'); expect(events.length).to.equal(2); }); + + it('change next', () => { + node.lang = 'en'; + expect(node.next).to.equal('de'); + expect(node.lang).to.equal('en'); + node.next = 'en'; + expect(node.next).to.equal('en'); + expect(node.lang).to.equal('de'); + expect(events.length).to.equal(2); + }); }); describe('vpu-language-select demo', () => {