From a76213dd1f84e5a0db2497e89e13eaa26ead364d Mon Sep 17 00:00:00 2001 From: VardanHakobyan Date: Thu, 17 Jun 2021 13:36:39 +0400 Subject: [PATCH] feat: change `label` to `button` for better accessibility, let users to import backup by keyboard as well --- .../components/AccountMenu/DataBackup.tsx | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/components/AccountMenu/DataBackup.tsx b/app/assets/javascripts/components/AccountMenu/DataBackup.tsx index 81dcf0af8..bf023490b 100644 --- a/app/assets/javascripts/components/AccountMenu/DataBackup.tsx +++ b/app/assets/javascripts/components/AccountMenu/DataBackup.tsx @@ -7,7 +7,7 @@ import { StringImportError } from '@/strings'; import { BackupFile } from '@standardnotes/snjs'; -import { useState } from 'preact/hooks'; +import { useRef, useState } from 'preact/hooks'; import { WebApplication } from '@/ui_models/application'; import { JSXInternal } from 'preact/src/jsx'; import TargetedEvent = JSXInternal.TargetedEvent; @@ -24,6 +24,7 @@ const DataBackup = observer(({ appState }: Props) => { + const fileInputRef = useRef(null); const [isImportDataLoading, setIsImportDataLoading] = useState(false); const { isBackupEncrypted, isEncryptionEnabled, setIsBackupEncrypted } = appState.accountMenu; @@ -97,6 +98,24 @@ const DataBackup = observer(({ } }; + // Whenever "Import Backup" is either clicked or key-pressed, proceed the import + const handleImportFile = (event: TargetedEvent | KeyboardEvent) => { + if (event instanceof KeyboardEvent) { + const { code } = event; + + // Process only when "Enter" or "Space" keys are pressed + if (code !== 'Enter' && code !== 'Space') { + return; + } + // In case "space" is pressed, don't allow scrolling + if (code === 'Space') { + event.preventDefault(); + } + } + + (fileInputRef.current as HTMLInputElement).click(); + }; + return ( <> {isImportDataLoading ? ( @@ -130,14 +149,20 @@ const DataBackup = observer(({
-
{isDesktopApplication() && (