From 2feb94cf4e207f8ad7ad7df4cdc24149e5881d90 Mon Sep 17 00:00:00 2001 From: Matt Hinz Date: Fri, 28 Oct 2022 15:48:52 -0700 Subject: [PATCH 1/3] Update ARIA label for FileInput component When FileInput does not have a file added to it, ensure ARIA label includes the prompt to drag + drop a file. User testing found this was needed, as JAWS does not automatically read `aria-describedby` by default (it requires extra interaction). changelog: Improvements, Accessibility, Improve document upload screen reader text --- .../components/file-input.jsx | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app/javascript/packages/document-capture/components/file-input.jsx b/app/javascript/packages/document-capture/components/file-input.jsx index 346b5bd100e..1ffb008da35 100644 --- a/app/javascript/packages/document-capture/components/file-input.jsx +++ b/app/javascript/packages/document-capture/components/file-input.jsx @@ -159,6 +159,7 @@ function FileInput(props, ref) { const inputId = `file-input-${instanceId}`; const hintId = `${inputId}-hint`; const innerHintId = `${hintId}-inner`; + const labelId = `${inputId}-label`; /** * In response to a file input change event, confirms that the file is valid before calling @@ -194,17 +195,32 @@ function FileInput(props, ref) { } /** - * @param {string} fileLabel String velue of the label for input to display + * @param {string} fileLabel String value of the label for input to display * @param {Blob|string|null|undefined} fileValue File or string for which to generate label. + * @return {{'aria-label': string} | {'aria-labelledby': string}} */ - function getLabelFromValue(fileLabel, fileValue) { + function getAriaLabelPropsFromValue(fileLabel, fileValue) { + // aria-label={getLabelFromValue(label, value)} + // aria-labelledby={`${labelId} ${innerHintId}`} + if (fileValue instanceof window.File) { - return `${fileLabel} - ${fileValue.name}`; + return { + 'aria-label': `${fileLabel} - ${fileValue.name}`, + }; } + if (fileValue) { - return `${fileLabel} - ${t('doc_auth.forms.captured_image')}`; + return { + 'aria-label': `${fileLabel} - ${t('doc_auth.forms.captured_image')}`, + }; } - return ''; + + // When no file is selected, provide a slightly more verbose label + // including the actual