-
Notifications
You must be signed in to change notification settings - Fork 5
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
Remove accordion icon added by JS and add to twig instead #200
Merged
finnlewis
merged 10 commits into
2.x
from
fix/2.x/199/remove-icon-added-by-js-and-add-to-twig-instead
Oct 1, 2024
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c7f6e0
Remove accordion icon added by JS and add to twig instead
AWearring 27ff3e6
Moved button from JS to Twig
AWearring 68495da
Removed un-needed commented code
AWearring ac68b5a
Removed more commented code
AWearring 65dbc63
Updated button to hidden in twig and un-hidden by JS and updated dest…
AWearring dd04fd4
Corrected button selector code
AWearring 2509009
Removed unrequired class from button
AWearring 916fd2d
Hide the button in CSS when it has attribute "hidden"
AWearring e62b48a
Added default heading text, hide in JS
AWearring 52b8cc9
If heading or buttons don't exist
AWearring 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 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 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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -117,20 +117,19 @@ | |||||||||||||
const pane = accordionPanes[i]; | ||||||||||||||
const content = pane.querySelectorAll('.accordion-pane__content'); | ||||||||||||||
const title = pane.querySelectorAll('.accordion-pane__title'); | ||||||||||||||
const titleText = title[0].textContent; | ||||||||||||||
const button = document.createElement('button'); | ||||||||||||||
const text = document.createTextNode(titleText); | ||||||||||||||
const button = title[0].querySelector('button'); | ||||||||||||||
const heading = title[0].querySelector('.accordion-pane__heading'); | ||||||||||||||
const id = `accordion-content-${index}-${i}`; | ||||||||||||||
|
||||||||||||||
// Add id attribute to all pane content elements. | ||||||||||||||
content[0].setAttribute('id', id); | ||||||||||||||
|
||||||||||||||
// Add show/hide button to each accordion title. | ||||||||||||||
button.appendChild(text); | ||||||||||||||
// Add an initially hidden icon which can be used if required to make accordions fit GDS standard | ||||||||||||||
button.innerHTML += "<span class='accordion-icon' aria-hidden='true'></span>"; | ||||||||||||||
button.setAttribute('aria-expanded', 'false'); | ||||||||||||||
// Add aria-controls id to button and un-hide | ||||||||||||||
button.setAttribute('aria-controls', id); | ||||||||||||||
button.hidden = false; | ||||||||||||||
|
||||||||||||||
// Hide default Heading text | ||||||||||||||
heading.hidden = true; | ||||||||||||||
|
||||||||||||||
// Add click event listener to the show/hide button. | ||||||||||||||
button.addEventListener('click', e => { | ||||||||||||||
|
@@ -188,13 +187,20 @@ | |||||||||||||
|
||||||||||||||
const destroy = () => { | ||||||||||||||
for (let i = 0; i < numberOfPanes; i++) { | ||||||||||||||
// Remove buttons from accordion pane titles. | ||||||||||||||
// Remove id attributes from buttons in accordion pane titles. | ||||||||||||||
const button = accordion | ||||||||||||||
.querySelectorAll('.accordion-pane__title') | ||||||||||||||
[i].querySelectorAll('button'); | ||||||||||||||
if (button.length > 0) { | ||||||||||||||
button[0].outerHTML = button[0].innerHTML; | ||||||||||||||
} | ||||||||||||||
.querySelectorAll('.accordion-pane__title')[i] | ||||||||||||||
.querySelector('button') | ||||||||||||||
.removeAttribute('id'); | ||||||||||||||
|
||||||||||||||
// Hide buttons in accordion pane titles. | ||||||||||||||
button.hidden = true; | ||||||||||||||
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.
Suggested change
|
||||||||||||||
|
||||||||||||||
// Un-hide default heading text | ||||||||||||||
accordion | ||||||||||||||
.querySelectorAll('.accordion-pane__title')[i] | ||||||||||||||
.querySelector('.accordion-pane__heading') | ||||||||||||||
.hidden = false | ||||||||||||||
|
||||||||||||||
// Remove id attributes from pane content elements. | ||||||||||||||
accordionPanes[i] | ||||||||||||||
|
This file contains 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 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.