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

fix(Authenticator): clicking on current tab switches tabs #5912

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

hbuchel
Copy link
Contributor

@hbuchel hbuchel commented Oct 16, 2024

Description of changes

Fixes an issue where clicking on the currently open Authenticator tab switches to the other tab. i.e. clicking on the "Sign in" tab while it is already active will no longer cause the "Create account" tab to open.

before

CleanShot.2024-10-17.at.14.25.53.mp4

after

CleanShot.2024-10-17.at.14.26.22.mp4

Issue #, if available

Fixes: #5911

Description of how you validated changes

Verified in local docs examples

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, e2e, examples, or other private packages.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

changeset-bot bot commented Oct 16, 2024

🦋 Changeset detected

Latest commit: 21e1e12

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@aws-amplify/ui-react Patch
@aws-amplify/ui-react-auth Patch
@aws-amplify/ui-react-liveness Patch
@aws-amplify/ui-react-notifications Patch
@aws-amplify/ui-react-storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hbuchel hbuchel changed the title fix clicking on current tab switching tabs fix(Authenticator): clicking on current tab switches tabs Oct 16, 2024
onValueChange={() => (route === 'signIn' ? toSignUp() : toSignIn())}
onValueChange={(prevRoute) => {
if (prevRoute !== route) {
route === 'signIn' ? toSignUp() : toSignIn();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why, but this is hurting my brain. Is the route the tab I clicked on or the route I'm currently at? So if I click any tab then it will essentially toggle to the other one? Why is comparing the prevRoute to the current route necessary?

Copy link
Member

@jordanvn jordanvn Oct 17, 2024

Choose a reason for hiding this comment

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

I think these variable names are switched. It looks like route is the active tab and prevRoute is the clicked tab.

So the old logic was just "if Sign In is the active tab go to Sign Up, otherwise go to Sign In", which results in always going to the other tab no matter what is clicked.

And the new logic is just adding the check of "if the clicked tab isn't the active tab...", which prevents changing tabs if you click on the already active tab, but is still just setting the tab without using the value from what was clicked. I think that logic still makes sense for the component, but imo prevRoute should just be changed to something like nextRoute, newRoute, etc.

Copy link
Member

Choose a reason for hiding this comment

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

newRoute might be the more consistent name, since TabContainer's setActiveTab() is using the name newValue for the argument passed to onValueChange()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in latest to use newRoute instead, that makes more sense for the actual logic happening.

jordanvn
jordanvn previously approved these changes Oct 17, 2024
Copy link
Member

@jordanvn jordanvn left a comment

Choose a reason for hiding this comment

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

LGTM

reesscot
reesscot previously approved these changes Oct 17, 2024
@hbuchel hbuchel dismissed stale reviews from reesscot and jordanvn via 21e1e12 October 17, 2024 19:51
Copy link
Contributor

@reesscot reesscot left a comment

Choose a reason for hiding this comment

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

LGTM

@hbuchel hbuchel merged commit 6fea94b into main Oct 17, 2024
34 checks passed
@hbuchel hbuchel deleted the FixAuthenticatorTabs branch October 17, 2024 20:37
@github-actions github-actions bot mentioned this pull request Oct 17, 2024
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.

Bug(Authenticator): Clicking the Sign in tab when already on the Sign In tab opens the
3 participants