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: navbar should close when user click anywhere on screen #565

Merged
merged 4 commits into from
Apr 1, 2024

Conversation

lalitkumawat1m
Copy link
Contributor

What kind of change does this PR introduce?

Issue Number:

Screenshots/videos:

JSON.Schema.-.Personal.-.Microsoft.Edge.2024-03-20.18-07-05.mp4

If relevant, did you update the documentation?
No

Summary

Does this PR introduce a breaking change?
No

@lalitkumawat1m lalitkumawat1m requested a review from a team as a code owner March 20, 2024 12:48
@lalitkumawat1m lalitkumawat1m changed the title fix navbar close when click anywhere on screen Fix: navbar should close when user click anywhere on screen Mar 20, 2024
Copy link
Member

@DarhkVoyd DarhkVoyd left a comment

Choose a reason for hiding this comment

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

Hey, I am unsure about using document.addEventListener and directly interacting with the DOM, I suggest we probably use some react event handler such as onBlur instead.

Normally you shouldn’t need to do this with React: you need to manually locate the elements using refs, which kinda breaks how React should work.

@lalitkumawat1m
Copy link
Contributor Author

Hey @DarhkVoyd, I appreciate your suggestion but Could you please guide me how this can be done without manipulating dom and using onblur?

@DarhkVoyd
Copy link
Member

DarhkVoyd commented Mar 21, 2024

Hey @lalitkumawat1m So, after thinking more about it, I think that your approach is the better way. I was earlier thinking about making the navbar focusable and then using onBlur listener to handle blur cases but I realised it would be unnecessary. I understand now that the use of document.addEventListener is valid in this case.

@DarhkVoyd
Copy link
Member

DarhkVoyd commented Mar 21, 2024

The one thing I am still confused about is the use of showMobileNav in useEffect dependencies array. Wouldn't mobileNavRef be a more valid dependency instead of the showMobileNav.

@benjagm
Copy link
Collaborator

benjagm commented Mar 22, 2024

Hi Lalit. Can you please check the comments done by DV?

@lalitkumawat1m
Copy link
Contributor Author

lalitkumawat1m commented Mar 22, 2024

Hey @benjagm @DarhkVoyd I have made the requested changes. Please have a look

@DarhkVoyd
Copy link
Member

Looks mostly good. just some suggestions,

  1. The issue proposed to close navbar when user clicks anywhere outside the navbar. Now, the implementation and PR are focused on closing the navbar if user clicks anywhere, even on the navbar. But, still the function is named handleClickOutside, maintaining consistency would help keep things clear. Also, is this intentional?
  2. A general practice suggestion, commit messages descriptive of changes introduced in code are better. This enhances the readability of the project's history. For example, instead of Made requested changes, a commit message like Update useEffect dependency from showMobileNav to mobileNavRef provides a clearer note of the change.

@lalitkumawat1m
Copy link
Contributor Author

lalitkumawat1m commented Mar 23, 2024

Hey @DarhkVoyd,

  1. Should I rename the handleClickOutside function to handleCloseNavbar ?

  2. I will update my commit msg to meaningfully commit msg.

@DarhkVoyd
Copy link
Member

Sure

@lalitkumawat1m
Copy link
Contributor Author

I have made the changes.

@benjagm benjagm requested a review from DarhkVoyd March 26, 2024 13:25
Copy link
Collaborator

@benjagm benjagm left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for fixing this!

Copy link
Member

@DarhkVoyd DarhkVoyd left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@benjagm benjagm merged commit 2934547 into json-schema-org:main Apr 1, 2024
2 checks passed
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.

✨ Enhancement: Top Navbar should close when user clicks anywhere on the screen
3 participants