-
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
Remove accordion icon added by JS and add to twig instead #200
Conversation
@AWearring I'm completely on-board with the idea: it'd make the whole accordion a lot simpler to style and adapt to individual designs. However, this change alters the markup by making the icon a sibling of the This has the potential break existing CSS customisation, and to silently introduce (visual) accessibility issues by breaking existing The approach I usually adopt for this kind of thing is something like this (simplified) code; {# Twig #}
<div class="accordion-pane__title">
{{ heading_text }}
{# The button starts out hidden #}
<button hidden aria-expanded="false" aria-controls="{{ control_id }}">
{{ heading_text }}
<span class='accordion-icon' aria-hidden="true"></span>
</button>
</div> // Javascript
init: function init(accordion, index) {
// Un-hide the button.
button.hidden = false;
// Rest of init() routine...
} Unfortunately, my approach is a thread that, if you tug at it, starts unraveling things: for example, we'd then need to sync the value of the button's If it's of interest, I've done a bit of work on a proof of concept that includes this component and solves this specific problem re: localgovdrupal/localgov_base#600 to try to address a related problem. There's no public code today, but I'm hoping to talk about it for a few minutes on Thursday's Technical Drop in call. |
@ctorgalson Thanks - I can see the issue and I can see it is much bigger than I first realised. The main reason for me looking into it is that on the 3 sites I maintain we already have an icon included in our twig templates and the pending v1.7.0 |
@ctorgalson {% block paragraph %}
<div{{ attributes.addClass(classes) }}>
{% block content %}
<div class="accordion-pane__title">
<{{ heading_level }}>
<button aria-expanded="false">
{{ heading_text }}
<span class='accordion-icon' aria-hidden='true'></span>
</button>
</{{ heading_level }}>
</div>
<div class="accordion-pane__content">
{{ content.localgov_body_text }}
</div>
{% endblock %}
</div>
{% endblock paragraph %} I believe this will work and not break any existing CSS customisation. |
@markconroy @ekes @finnlewis |
@AWearring I was just looking. I can't test until the morning, but I think this almost perfectly duplicates what the js does with two small remaining exceptions. The first omission is that the button is not hidden for users who might not have js enabled (or if some other js on the page breaks this script). This is a potential problem in that situation because the button has an As I mentioned above, I usually handle this by adding the The second thing, also very minor, is because of how the Accordion (and its javascript) is used alongside Tabs (and their javascript), it's necessary to un-do everything that you do in |
@ctorgalson Thanks for your comments
However, I'm not sure adding |
Your changes look good.
I can't take a look until tomorrow, but browsers do hide items with button { display: block; } ...and can be corrected with something like this: button:not([hidden]) { display: block; } |
@ctorgalson |
@ctorgalson .accordion-pane__title button {
display: inline-flex;
align-items: center;
justify-content: space-between;
} So maybe we need to have the opposite to your suggestion: .accordion-pane__title button[hidden] {
display: none;
} However the issue we'd then have with that is that we'd lose the Heading contained within the button too |
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.
@AWearring Good catch regarding the need to hide the title text. AFAIK, that's really the only solution in this situation.
It does reveal a couple of potential issues though (sorry!):
- lines 181-184 need to be removed altogether as no longer relevant (this would only have an effect if
.destroy()
ran--then the button would be hidden, but there would be no title text), - if a Twig template is in use where the heading title does not have that
span.accordion-pane__heading
wrapper, the javascript gets halfway through the first button/pane combo and then fails; I think the two suggestions I've made here fix that issue (this won't happen on sites that have not customized the template, but any site that has runs this risk).
button.hidden = false; | ||
|
||
// Hide default Heading text | ||
heading.hidden = true; |
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.
heading.hidden = true; | |
if (heading) { | |
heading.hidden = true; | |
} |
.removeAttribute('id'); | ||
|
||
// Hide buttons in accordion pane titles. | ||
button.hidden = true; |
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.
button.hidden = true; | |
button.hidden = true; | |
if (heading) { | |
heading.hidden = false; | |
} |
@ctorgalson |
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.
This all looks good to me with the caveat that some sites that have already customized the accordion pane template may see visible heading text alongside the buttons.
But as it's a reasonably minor side-effect, and quite easy to correct, I think this is a better solution overall than introducing more complexity to the js (like, e.g., detecting if the heading text is not already wrapped in a span, then wrapping/unwrapping it on create()
/destroy()
).
@ctorgalson Thanks for your input and assistance. In my testing using a copy the West Lindsey site which is using a customised Twig template, that is very close to the original only adding in a Font Awesome icon after the heading, the only visual issues are that all the panes are open and the Font Awesome icon is visible. I think I can live with that and as you say it is a fairly easy to correct. I believe this is better than the newly defined icons in |
This looks good to me. If we are moving to adding the icon via a twig template, I'd like us to add it as an inline SVG so we have more control over it with CSS. And maybe have the icon beside the button instead of inside the button, and the text inside the button instead of before the button ... but I think these are nice enhancements that we can consider in follow-up issues perhaps. Thanks to Big Blue Door for sponsoring my time to work on this. |
One vote slightly in favour of keeping the icon in the button for simplicity of styiing focus states (I know we can use |
Ideally, we could in the near-future remove all this JS and just use the |
The Accordion Pane icons are currently being added using Javascript, this strikes me as being bad practice therefore this PR removes them from being added via
localgov-accordion.js
and instead adds them via the Accordion Pane Twig file instead (paragraph--localgov-accordion-pane.html.twig
)See issue #199