diff --git a/addon/components/one-way-select.js b/addon/components/one-way-select.js index acc4fad..b2bb597 100644 --- a/addon/components/one-way-select.js +++ b/addon/components/one-way-select.js @@ -1,7 +1,7 @@ import Component from '@ember/component'; import { A as emberArray, isArray } from '@ember/array'; import EmberObject, { computed, get, set } from '@ember/object'; -import { alias, empty, not, or } from '@ember/object/computed' +import { alias, not, or } from '@ember/object/computed' import { isBlank, isNone, isPresent } from '@ember/utils'; import { w } from '@ember/string'; @@ -62,7 +62,9 @@ const OneWaySelectComponent = Component.extend(DynamicAttributeBindings, { set(this, 'options', emberArray(options)); }, - nothingSelected: empty('selectedValue'), + nothingSelected: computed('selectedValue', function() { + return !this._findOption(this.get('selectedValue')); + }), promptIsDisabled: not('promptIsSelectable'), hasGrouping: or('optionsArePreGrouped', 'groupLabelPath'), computedOptionValuePath: or('optionValuePath', 'optionTargetPath'), diff --git a/tests/integration/components/one-way-select-test.js b/tests/integration/components/one-way-select-test.js index ee3df25..06600b2 100644 --- a/tests/integration/components/one-way-select-test.js +++ b/tests/integration/components/one-way-select-test.js @@ -402,3 +402,9 @@ test('allows to select blank without throwing', async function(assert) { assert.equal([...findAll('option')].find((o) => o.selected).textContent.trim(), 'myDefaultPrompt'); assert.deepEqual(updates, ['one', undefined]); }); + +test('Prompt is selected if value is not an option', function(assert) { + this.set('value', 'doesntexist'); + this.render(hbs`{{one-way-select value=value options=options prompt="Select one"}}`); + assert.equal([...findAll('option')].find((o) => o.selected).textContent.trim(), 'Select one', 'Prompt is selected'); +});