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

Keep CreatePost mounted when updating URL, fixes focus resets. #2520

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

matc-pub
Copy link
Collaborator

@matc-pub matc-pub commented Jun 7, 2024

Clicking on another input element now moves the focus. Without this change the clicked input element is replaced with a new one during URL update.

@@ -121,6 +121,7 @@ export const routes: IRoutePropsWithFetch<RouteData, any, any>[] = [
component: CreatePost,
fetchInitialData: CreatePost.fetchInitialData,
getQueryParams: getCreatePostQueryParams,
mountedSameRouteNavKey: "create_post",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In App routes without that property get the location.key assigned as key, so that they unmount whenever the location changes. Before that property all routes behaved like that.

@@ -237,6 +249,7 @@ export class CreatePost extends Component<
<div id="createPostForm" className="col-12 col-lg-6 offset-lg-3 mb-4">
<h1 className="h4 mb-4">{I18NextService.i18n.t("create_post")}</h1>
<PostForm
key={this.state.resetCounter}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a key (outside of a collection) to prevent uneccessary rerenders. Clever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still has to render even when the key stays the same. But the when the key changes it has to be recreated and resets its state. I added it so that the "Create Post" link in the top navigation completely resets the form.

@SleeplessOne1917 SleeplessOne1917 merged commit 761cd7a into main Jun 7, 2024
2 checks passed
@SleeplessOne1917 SleeplessOne1917 deleted the fix_create_post_focus_issues branch June 7, 2024 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants