Skip to content

Commit f018def

Browse files
committed
feat(kbd shortcut): added submit keyboard shortcut for index page
1 parent 1991883 commit f018def

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

helpers/driverjsTutorials.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ const labelsTutorial: Tutorial[] = [
3030
},
3131
]
3232

33+
const submitShortcutTutorial: Tutorial[] = [
34+
{
35+
element: '#submitButton',
36+
popover: {
37+
title: 'New keyboard shortcut',
38+
description:
39+
'Now you can press <kbd>Cmd</kbd> + <kbd>Enter</kbd>/<kbd>Ctrl</kbd> + <kbd>Enter</kbd> to go to compare screen.',
40+
},
41+
},
42+
]
43+
3344
const actionBarTutorial: Tutorial[] = [
3445
{
3546
element: '#toggleScrollInSyncSection',
@@ -60,7 +71,7 @@ const backButtonTutorial: Tutorial[] = [
6071
popover: {
6172
title: 'Go back to edit screen',
6273
description:
63-
'Now your data persists between the page navigation. Only if you have clicked on "Compare" button',
74+
'Now your data persists between the page navigation. <br/> PS: Works only if you have clicked on "Compare" button',
6475
},
6576
},
6677
]
@@ -81,6 +92,10 @@ const tutorialsMetadata: TutorialsMetadata = {
8192
tutorial: labelsTutorial,
8293
cookieName: 'isSkipTutorial',
8394
},
95+
{
96+
tutorial: submitShortcutTutorial,
97+
cookieName: 'isSkipSubmitKbdShortcutTutorial',
98+
},
8499
],
85100
}
86101

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function () {
2+
const cookies = document.cookie.split(';')
3+
const cookieMap: {
4+
isSkipSubmitKbdShortcutTutorial?: string
5+
} = {
6+
isSkipSubmitKbdShortcutTutorial: 'false',
7+
}
8+
cookies.forEach((element) => {
9+
const [name, val] = element.split('=')
10+
const trimmedName = name.trim()
11+
if (trimmedName === 'isSkipSubmitKbdShortcutTutorial') {
12+
cookieMap[trimmedName] = val
13+
}
14+
})
15+
return cookieMap.isSkipSubmitKbdShortcutTutorial === 'true'
16+
}

pages/index.vue

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<button
6161
class="inline-flex items-center justify-center w-48 px-4 py-2 transition-transform transform bg-blue-600 rounded-md shadow-lg outline-none text-gray-50 focus:ring-4 active:scale-y-75"
6262
aria-label="Click here to compare the inputted text blocks"
63+
id="submitButton"
6364
>
6465
Compare
6566
</button>
@@ -85,6 +86,15 @@ export default Vue.extend({
8586
},
8687
mounted() {
8788
showTutorials(this.$cookies, this.$route.path, this.$cookies.isDarkMode)
89+
document.addEventListener('keydown', (event) => {
90+
const { metaKey, ctrlKey, key } = event
91+
if ((metaKey || ctrlKey) && key === 'Enter') {
92+
const button: HTMLButtonElement = document.getElementById(
93+
'submitButton'
94+
) as HTMLButtonElement
95+
button.click()
96+
}
97+
})
8898
},
8999
methods: {
90100
checkForm(e: Event) {

plugins/cookie-injector.client.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import isDarkModeCookie from '~/helpers/isDarkModeCookie'
33
import isSkipTutorialCookie from '~/helpers/isSkipTutorialCookie'
44
import isSkipScrollInSyncTutorial from '~/helpers/isSkipScrollInSyncTutorial'
55
import isSkipBackButtonPersistsDataTutorial from '~/helpers/isSkipBackButtonPersistsDataTutorial'
6+
import isSkipSubmitKbdShortcutTutorial from '~/helpers/isSkipSubmitKbdShortcutTutorial'
67

78
interface Cookies {
89
isDarkMode: boolean
910
isSkipTutorial: boolean
1011
isSkipScrollInSyncTutorial: boolean
1112
isSkipBackButtonPersistsDataTutorial: boolean
13+
isSkipSubmitKbdShortcutTutorial: boolean
1214
}
1315
declare module 'vue/types/vue' {
1416
interface Vue {
@@ -41,6 +43,7 @@ const cookieInjectorPlugin: Plugin = (_context, inject) => {
4143
isSkipScrollInSyncTutorial: isSkipScrollInSyncTutorial(),
4244
isSkipBackButtonPersistsDataTutorial:
4345
isSkipBackButtonPersistsDataTutorial(),
46+
isSkipSubmitKbdShortcutTutorial: isSkipSubmitKbdShortcutTutorial(),
4447
})
4548
}
4649

styles/global.scss

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ main {
4343
margin-top: 2rem;
4444
}
4545

46+
kbd {
47+
@apply bg-gray-100 dark:bg-gray-800 border bottom-1 dark:border-gray-600 border-gray-300 shadow rounded-sm text-gray-700 dark:text-gray-50 inline-block;
48+
font-size: 0.85em;
49+
font-weight: 700;
50+
line-height: 1;
51+
padding: 2px 4px;
52+
white-space: nowrap;
53+
}
54+
4655
/* custom scrollbar */
4756
::-webkit-scrollbar {
4857
width: 10px;

0 commit comments

Comments
 (0)