Repository navigation
Auto-hide navigation on link click - #1238
Merged
Merged
Conversation
st0012
force-pushed
the
auto-hide-nav-on-link-click
branch
from
December 15, 2024 13:37
94ef2b5 to
e1a6d3f
Compare
st0012
reviewed
Dec 15, 2024
sunblaze
force-pushed
the
auto-hide-nav-on-link-click
branch
from
December 16, 2024 21:09
e1a6d3f to
1bdd6eb
Compare
st0012
reviewed
Dec 17, 2024
st0012
reviewed
Dec 17, 2024
Member
|
I think we can simplify the implementation to this: --- a/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js
@@ -103,19 +103,18 @@ function hookSidebar() {
if (isSmallViewport) {
navigation.hidden = true;
navigationToggle.ariaExpanded = false;
- }
-}
-function hookAnchorLinks() {
- document.addEventListener('click', (e) => {
- const anchor = e.target.closest('#navigation a[href^="#"]');
- if (anchor && window.matchMedia("(max-width: 1023px)").matches) {
- const navigation = document.querySelector('#navigation');
- const navigationToggle = document.querySelector('#navigation-toggle');
- navigation.hidden = true;
- navigationToggle.ariaExpanded = false;
- }
- });
+ // hide navigation on link click when on small viewport
+ // this saves the user from having to click the toggle button again to hide the navigation
+ document.addEventListener('click', (e) => {
+ if (e.target.closest('#navigation a[href]')) {
+ const navigation = document.querySelector('#navigation');
+ const navigationToggle = document.querySelector('#navigation-toggle');
+ navigation.hidden = true;
+ navigationToggle.ariaExpanded = false;
+ }
+ });
+ }
}
document.addEventListener('DOMContentLoaded', function() {
@@ -123,5 +122,4 @@ document.addEventListener('DOMContentLoaded', function() {
hookSearch();
hookFocus();
hookSidebar();
- hookAnchorLinks();
});Basically, we can register the event using the same small viewport check to make sure the condition is shared. WDYT? |
Contributor
Author
|
Yes, your simplification should work too. But you can also get rid of these lines as well since they're already defined const navigation = document.querySelector('#navigation');
const navigationToggle = document.querySelector('#navigation-toggle'); |
Hide navigation sidebar when clicking anchor links on mobile devices. Previously, anchor links would change the page but the navigation sidebar would block the view.
sunblaze
force-pushed
the
auto-hide-nav-on-link-click
branch
from
December 17, 2024 23:35
1bdd6eb to
1d8ae26
Compare
st0012
approved these changes
Dec 18, 2024
st0012
left a comment
Member
There was a problem hiding this comment.
This is a great quality-of-life improvement. Thank you!
st0012
added a commit
to Shopify/ruby
that referenced
this pull request
Dec 18, 2024
I was meant to merge this before the auto-syncing stops but was late a little bit. It's a frontend change for RDoc so ideally we'd want to test it on docs.ruby-lang.org for a few days before the 3.4 release.
hsbt
pushed a commit
to hsbt/ruby
that referenced
this pull request
Dec 18, 2024
(ruby/rdoc#1238) Hide navigation sidebar when clicking anchor links on mobile devices. Previously, anchor links would change the page but the navigation sidebar would block the view. ruby/rdoc@f12a96b7fa
hsbt
pushed a commit
to ruby/ruby
that referenced
this pull request
Dec 18, 2024
(ruby/rdoc#1238) Hide navigation sidebar when clicking anchor links on mobile devices. Previously, anchor links would change the page but the navigation sidebar would block the view. ruby/rdoc@f12a96b7fa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hide navigation sidebar when clicking anchor links on mobile devices. Previously, anchor links would change the page but the navigation sidebar would block the view.