Skip to content

Commit

Permalink
a11y: set focus after submitting survey (github#24666)
Browse files Browse the repository at this point in the history
* Set focus after submitting survey

* Add role=status to success message
  • Loading branch information
rsese authored Jan 26, 2022
1 parent 8bb47c3 commit 850aa34
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion components/page-footer/Survey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export const Survey = () => {
setState(ViewState.START)
}, [asPath])

useEffect(() => {
// After the form is submitted we need to manually set the focus since we
// remove the form inputs after submit. The privacy policy link is the
// next focusable element in the footer so we focus that.
if (state === ViewState.END) {
document
.querySelector<HTMLAnchorElement>(
'footer a[href="/github/site-policy/github-privacy-statement"]'
)
?.focus()
}
}, [state])

function vote(state: ViewState) {
return () => {
trackEvent(getFormData())
Expand Down Expand Up @@ -176,7 +189,7 @@ export const Survey = () => {
)}

{state === ViewState.END && (
<p className="color-fg-muted f6" data-testid="survey-end">{t`feedback`}</p>
<p role="status" className="color-fg-muted f6" data-testid="survey-end">{t`feedback`}</p>
)}

<Link
Expand Down

0 comments on commit 850aa34

Please sign in to comment.