Skip to content

Commit

Permalink
8.2. active key state
Browse files Browse the repository at this point in the history
  • Loading branch information
ApayRus committed Jun 26, 2022
1 parent 3c24e6d commit f5ab715
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 11 additions & 5 deletions components/Key.js
Expand Up @@ -24,12 +24,18 @@ const getKeyLabels = keyContent => {

const Key = {
template: `
<div class="key">
<div class="main">{{main}}</div>
<div class="shifted">{{shifted}}</div>
</div>`,
<div
:class="[
'key',
{active: activeKey.code === keyContent.code}
]"
>
<div class="main">{{main}}</div>
<div class="shifted">{{shifted}}</div>
</div>`,
props: {
keyContent: Object
keyContent: Object,
activeKey: Object
},
computed: {
main() {
Expand Down
7 changes: 6 additions & 1 deletion components/Keyboard.js
Expand Up @@ -10,7 +10,8 @@ const Keyboard = {
>
<vue-key
v-for="keyContent in row"
:keyContent="keyContent"
:keyContent="keyContent"
:activeKey="activeKey"
/>
</div>
</div>`,
Expand Down Expand Up @@ -41,6 +42,10 @@ const Keyboard = {
const { code, key, shiftKey } = event
/* write event parts to the state: */
this.activeKey = { code, key, shiftKey }
/* if there was old timeout, we clear it*/
clearTimeout(this.timeout)
/* store a new timeout for the last pressed key */
this.timeout = setTimeout(() => (this.activeKey = { code: '' }), 1000)
})
},

Expand Down

0 comments on commit f5ab715

Please sign in to comment.