Feature/2.x/72 module javascript needs improvement#131
Feature/2.x/72 module javascript needs improvement#131ctorgalson wants to merge 29 commits into2.xfrom
Conversation
This exactly duplicates the existing behavior and markup of the existing implementation, but makes the following improvements: - all strings are now translateable - nearly all HTML is themeable, including child markup for the <button> elements - improved accessibility via aria-pressed and Drupal.announce() for the show/hide all summaries button - much less DOM querying overall - less code repetition
- separates all-summaries toggle logic - declares variables where used - passes through prettier
|
@markconroy I know you've just gone off on holiday, but this was the PR I mentioned on #72. |
|
@ctorgalson There was some discussion about updating the step by step pattern so I think improving the mark up we currently have rather than wholesale changes is the right way to go for this particular MR. |
|
The problem is the javascript--it's currently creating the unthemeable, untranslatable markup, and it's much too tightly coupled to the existing twig markup. The least impactful change in terms of existing implementations is to fix the js so the things it does can be translated and themed. Fixing the twig markup (by e.g. outputting the buttons there) would be a great improvement, but would require a total rewrite of the js in that case too (making it much smaller and simpler on the way). The TL;DR is the js needs to be rewritten. This PR is the conservative approach, but I'd love it if we opted for a major version increment. That'd allow us to greatly simplify the script and handle 100% of the markup in twig. |
markconroy
left a comment
There was a problem hiding this comment.
I think this looks great. happy to approve it.
I'd also like a follow-up issue to rewrite the JS and template (as a new major release perhaps) so it does all the things we want.
Great work. Thanks.
|
@ctorgalson to look at test failures. Looks as though behat complains about a change of label. |
tonypaulbarker
left a comment
There was a problem hiding this comment.
Marking as changes requested for addressing the tests
|
Fixing tests will rely on an upstream issue with Essentially, I need to run the tests locally to see what DOM structure gets created and why that behat test complains, and I can't correctly run the tests locally with that issue outstanding (afaict, the test is wrong about the result, but I can't prove it 😁)... Edited to add much later: I changed the tests to dump HTML when they fail, and ran them here. |
|
Some merge conflicts to review |
|
Keen to pick this up again. We just merged the ESLint fixes. Can we resolve these conflicts then incorporate these changes? @markconroy @tonypaulbarker perhaps we can review in the next week or two. |
I *think* this unusual requirement is because the function actually returns in some circumstances, so the @return is needed.
Eslint makes things much more complex.
|
@finnlewis, @markconroy, @tonypaulbarker I got the tests to pass. There was a sneaky regression in there. The tests will also now dump the @markconroy this includes the identical behaviour from your recent patch. |
|
@msayoung I've made one major and one minor accessibility change here that it'd be good for an expert to review. Major: remove
|
Closes #72
What does this change?
TL;DR: this addresses the accessibility, translatability, and theming issues in #72 without altering the themeable markup:
NOTE: if we we're willing to accept breaking changes (mainly to the markup), this could be rewritten much more efficiently.
Drupal.t()(sometimes via theme functions),Drupal.themefunctions that can be overridden by themes,Drupal.themefunctions,aria-expandedattribute from "Show summaries" button,aria-controlsattribute to "Show summaries" button,aria-controlsattributes on summaries, and a correspondingidattribute on the individual "Show summaries" buttons,Drupal.announce()to say "All summaries expanded" or "All summaries collapsed' when the "Show summaries" button is used,How to test
How can we measure success?
With the following exceptions, there should be no differences in behaviour from the current implementation:
aria-expandedremoved)Have we considered potential risks?
There are few risks as the rewrite goes to great lengths to preserve the prior version's markup.
Images
No changes.
Accessibility