Skip to content

Commit 04c305e

Browse files
authored
Support empty string as value of option (#26)
* Support empty string as value of option * Use isNone instead of isBlank * Test to validate empty string as value
1 parent 83f945a commit 04c305e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

addon/components/select-light.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Component from '@glimmer/component';
2-
import { isPresent } from '@ember/utils';
2+
import { isNone } from '@ember/utils';
33

44
const noop = () => {};
55

@@ -13,9 +13,9 @@ export default class extends Component {
1313
}
1414

1515
get hasDetailedOptions() {
16-
return [ // Returns a boolean if all data is available for a { label: foo, value: bar } style list of options
16+
return ![ // Returns a boolean if all data is available for a { label: foo, value: bar } style list of options
1717
this.args.options?.[0][this.valueKey],
1818
this.args.options?.[0][this.displayKey],
19-
].every(isPresent);
19+
].some(isNone);
2020
}
2121
}

tests/integration/components/select-light-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,28 @@ module('Integration | Component | select-light', function(hooks) {
161161
assert.dom('select option').includesText(options[0].description);
162162
});
163163

164+
test('should render options correctly when value is an empty string', async function(assert) {
165+
let options = [
166+
{ value: '', label: 'None' },
167+
{ value: 'mako', label: 'Mako Shark' },
168+
];
169+
let value = options[1].value;
170+
this.setProperties({
171+
options,
172+
value,
173+
});
174+
175+
await render(hbs`
176+
<SelectLight
177+
@options={{this.options}}
178+
@value={{this.value}} />`);
179+
180+
assert.dom('select option').exists({ count: options.length });
181+
assert.dom('select option').hasAttribute('value', options[0].value);
182+
assert.dom('select option').includesText(options[0].label);
183+
assert.dom('select').hasValue(value);
184+
});
185+
164186
test('should fire change when user chooses option, mut with yield', async function(assert) {
165187
this.set('myValue', null);
166188

0 commit comments

Comments
 (0)