Skip to content

Commit f9ef805

Browse files
committed
Make adding a bit more usable.
1 parent 1cade9c commit f9ef805

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/BoardAdd.vue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
</div>
1111
<div class="three columns">
1212
<label for="name">Name</label>
13-
<input name="name" type="text" v-model="name" @keyup.enter="add">
13+
<input name="name" type="text" ref="name" v-model="name" @keyup.enter="add">
1414
</div>
1515
<div class="one columns">
16-
<button class="button-primary" @click="add">Add</button>
16+
<button class="button-primary" :disabled="blankName" @click="add">Add</button>
1717
</div>
1818
</div>
1919
</template>
@@ -26,13 +26,24 @@ module.exports = {
2626
type: 'dice',
2727
}
2828
},
29+
computed: {
30+
blankName: function() {
31+
return this.name.trim().length == 0
32+
}
33+
},
2934
methods: {
3035
add: function () {
31-
this.$emit('add', {
32-
name: this.name,
33-
type: this.type
34-
})
36+
if (!this.blankName) {
37+
this.$emit('add', {
38+
name: this.name.trim(),
39+
type: this.type
40+
})
41+
this.name = ''
42+
}
3543
}
44+
},
45+
mounted: function() {
46+
this.$refs.name.focus()
3647
}
3748
}
3849
</script>
@@ -45,4 +56,11 @@ module.exports = {
4556
button {
4657
margin-top: 2.9rem;
4758
}
59+
button[disabled] {
60+
opacity: 0.5;
61+
}
62+
button[disabled]:hover {
63+
background-color: #33C3F0;
64+
border-color: #33C3F0;
65+
}
4866
</style>

0 commit comments

Comments
 (0)