Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Nov 26, 2020
1 parent 505eba8 commit 5980446
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,11 @@ export default class ElementWrapper extends Wrapper {
// handle edge cases for elements
if (this.node.name === 'select') {
const dependencies = new Set<string>();
for (const attr of this.attributes) {
const value_or_spread = this.attributes.filter(attr =>
attr.node.type === 'Spread' || attr.node.name === 'value'
);

for (const attr of value_or_spread) {
for (const dep of attr.node.dependencies) {
dependencies.add(dep);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
solo: true,
async test({ assert, component, target }) {
const select = target.querySelector('select');
const [option1, option2] = select.childNodes;

let selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 2);
assert.ok(selections.includes(option1));
assert.ok(selections.includes(option2));

component.required = true;
selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 2, 'required');
assert.ok(selections.includes(option1));
assert.ok(selections.includes(option2));
assert.ok(select.required);

component.spread = { id: 'id' };
selections = Array.from(select.selectedOptions);
assert.equal(selections.length, 2, 'spread');
assert.ok(selections.includes(option1));
assert.ok(selections.includes(option2));
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
export let value = ['Hello', 'World'];
export let spread = {};
export let required;
</script>

<select multiple {required} {value} {...spread}>
<option>Hello</option>
<option>World</option>
</select>

0 comments on commit 5980446

Please sign in to comment.