-
Notifications
You must be signed in to change notification settings - Fork 0
Define new helper for tab links, with aria #271
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e69f1fd
Define new helper for tab links, with aria
matt-bernhardt 2001287
Move spinner control to our javascript
matt-bernhardt f35d4ca
Eagerly update tab UI
matt-bernhardt b261749
Try walking back using an explicit spinner class
matt-bernhardt 65fe71e
Restore explicit control of spinner
matt-bernhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| // Update the tab UI to reflect the newly-requested state. This function is called | ||
| // by a click event handler in the tab UI. It follows a two-step process: | ||
| function swapTabs(new_target) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great call consolidating this logic into a function |
||
| // 1. Reset all tabs to base condition | ||
| document.querySelectorAll('.tab-link').forEach((tab) => { | ||
| tab.classList.remove('active'); | ||
| tab.removeAttribute('aria-current'); | ||
| }); | ||
| // 2. Add "active" class and aria-current attribute to the newly-active tab link | ||
| const currentTabLink = document.querySelector(`.tab-link[href*="tab=${new_target}"]`); | ||
| if (currentTabLink) { | ||
| currentTabLink.classList.add('active'); | ||
| currentTabLink.setAttribute('aria-current', 'page'); | ||
| } | ||
| } | ||
|
|
||
| // Loading spinner behavior for pagination (Turbo Frame updates) | ||
| document.addEventListener('turbo:frame-render', function(event) { | ||
| if (window.pendingFocusAction === 'pagination') { | ||
|
|
@@ -23,16 +39,8 @@ document.addEventListener('turbo:frame-render', function(event) { | |
| // console.log(`Updated tab input value to: ${queryParam}`); | ||
| } | ||
|
|
||
| // update active tab styling | ||
| // remove active class from all tabs | ||
| document.querySelectorAll('.tab-link').forEach((tab) => { | ||
| tab.classList.remove('active'); | ||
| }); | ||
| // add active class to current tab | ||
| const currentTabLink = document.querySelector(`.tab-link[href*="tab=${queryParam}"]`); | ||
| if (currentTabLink) { | ||
| currentTabLink.classList.add('active'); | ||
| } | ||
| // Remove the spinner now that things are ready | ||
| document.getElementById('search-results').classList.remove('spinner'); | ||
|
|
||
| // Clear the pending action | ||
| window.pendingFocusAction = null; | ||
|
|
@@ -51,7 +59,17 @@ document.addEventListener('click', function(event) { | |
|
|
||
| // Handle tab clicks | ||
| if (clickedElement.closest('.tab-navigation')) { | ||
| const clickedParams = new URLSearchParams(clickedElement.search); | ||
| const newTab = clickedParams.get('tab'); | ||
|
|
||
| // Throw the spinner on the search results immediately | ||
| document.getElementById('search-results').classList.add('spinner'); | ||
|
|
||
| // Position the window at the top of the results | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
|
|
||
| swapTabs(newTab); | ||
|
|
||
| window.pendingFocusAction = 'tab'; | ||
| } | ||
| }); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,8 @@ | ||
| <!-- Tab Navigation --> | ||
| <nav id="tabs" class="tab-navigation" aria-label="Result type navigation"> | ||
| <ul> | ||
| <li> | ||
| <%= link_to "Primo", results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: 'primo')), | ||
| class: "tab-link #{'active' if @active_tab == 'primo'}", | ||
| data: { turbo_frame: "search-results", turbo_action: "advance" } %></li> | ||
| <li> | ||
| <%= link_to "TIMDEX", results_path(params.permit(:q, :per_page, :booleanType, :tab).merge(tab: 'timdex')), | ||
| class: "tab-link #{'active' if @active_tab == 'timdex'}", | ||
| data: { turbo_frame: "search-results", turbo_action: "advance" } %></li> | ||
| <li><%= link_to_tab("Primo") %></li> | ||
| <li><%= link_to_tab("TIMDEX") %></li> | ||
| </ul> | ||
| </nav> | ||
|
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner in the view now and easier to test. ❤️