Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): read out submission confirmation for screen readers on success #4917

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const EndPageView = ({ ...props }: FlexProps): JSX.Element => {
w="100%"
>
<EndPageBlock
formTitle={form?.title}
endPage={endPage ?? { title: '', buttonText: '' }}
submissionData={{
id: form?._id ?? 'Submission ID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ export const EndPageBuilderInput = ({
isInvalid={!!errors.title}
>
<FormLabel isRequired>Title</FormLabel>
<Input {...register('title', { required: REQUIRED_ERROR })} />
<Input
autoFocus
{...register('title', { required: REQUIRED_ERROR })}
/>
<FormErrorMessage>{errors.title?.message}</FormErrorMessage>
</FormControl>
<FormControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FeedbackBlock, FeedbackFormInput } from './components/FeedbackBlock'
import { ThankYouSvgr } from './components/ThankYouSvgr'

export interface FormEndPageProps {
formTitle: FormDto['title']
endPage: FormDto['endPage']
submissionData: SubmissionData
handleSubmitFeedback: (inputs: FeedbackFormInput) => void
Expand All @@ -34,7 +35,11 @@ export const FormEndPage = ({
w="100%"
divider={<StackDivider />}
>
<EndPageBlock {...endPageProps} colorTheme={colorTheme} />
<EndPageBlock
focusOnMount
{...endPageProps}
colorTheme={colorTheme}
/>
{isFeedbackSubmitted ? null : (
<FeedbackBlock
colorTheme={colorTheme}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const FormEndPageContainer = ({
<FormEndPage
colorTheme={form.startPage.colorTheme}
submissionData={submissionData}
formTitle={form.title}
endPage={form.endPage}
isFeedbackSubmitted={isFeedbackSubmitted}
handleSubmitFeedback={handleSubmitFeedback}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, Flex, Stack, Text } from '@chakra-ui/react'
import { useEffect, useMemo, useRef } from 'react'
import { Box, Flex, Stack, Text, VisuallyHidden } from '@chakra-ui/react'

import { FormColorTheme, FormDto } from '~shared/types/form'

Expand All @@ -7,22 +8,45 @@ import Button from '~components/Button'
import { SubmissionData } from '~features/public-form/PublicFormContext'

export interface EndPageBlockProps {
formTitle: FormDto['title'] | undefined
endPage: FormDto['endPage']
submissionData: SubmissionData
colorTheme?: FormColorTheme
focusOnMount?: boolean
}

export const EndPageBlock = ({
formTitle,
endPage,
submissionData,
colorTheme = FormColorTheme.Blue,
focusOnMount,
}: EndPageBlockProps): JSX.Element => {
const focusRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (focusOnMount) {
focusRef.current?.focus()
}
}, [focusOnMount])

const submittedAriaText = useMemo(() => {
if (formTitle) {
return `You have successfully submitted your response for ${formTitle}.`
}
return 'You have successfully submitted your response.'
}, [formTitle])

return (
<Flex flexDir="column">
<Stack spacing="1rem">
<Text as="h2" textStyle="h2" textColor="secondary.700">
{endPage.title}
</Text>
<Stack tabIndex={-1} ref={focusRef} spacing="1rem">
<Box>
<VisuallyHidden aria-live="assertive">
{submittedAriaText}
</VisuallyHidden>
<Text as="h2" textStyle="h2" textColor="secondary.700">
{endPage.title}
</Text>
</Box>
{endPage.paragraph ? (
<Text
color="secondary.500"
Expand Down