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

Reset focus to top on each account step #973

Merged
merged 5 commits into from
Aug 30, 2023
Merged
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
14 changes: 13 additions & 1 deletion lib/components/user/sequential-pane-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class SequentialPaneDisplay<T> extends Component<Props<T>> {
routeTo(`${parentPath}/${nextId}`)
}

h1Ref = React.createRef<HTMLHeadingElement>()

_focusHeader = () => {
this.h1Ref?.current?.focus()
}

_handleToNextPane = async (e: MouseEvent<Button>) => {
const { activePane, activePaneIndex, panes } = this.props
const { invalid, invalidMessage } = activePane
Expand All @@ -70,6 +76,7 @@ class SequentialPaneDisplay<T> extends Component<Props<T>> {
this._routeTo(nextId)
}
}
this._focusHeader()
}

_handleToPrevPane = () => {
Expand All @@ -78,6 +85,11 @@ class SequentialPaneDisplay<T> extends Component<Props<T>> {
const prevId = panes[activePaneIndex - 1].id
prevId && this._routeTo(prevId)
}
this._focusHeader()
}

componentDidMount(): void {
this._focusHeader()
}

render() {
Expand All @@ -86,7 +98,7 @@ class SequentialPaneDisplay<T> extends Component<Props<T>> {

return (
<>
<h1>
<h1 aria-live="assertive" ref={this.h1Ref} tabIndex={-1}>
<StepNumber>
<FormattedMessage
id="components.SequentialPaneDisplay.stepNumber"
Expand Down
Loading