-
Notifications
You must be signed in to change notification settings - Fork 338
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
Add helper for creating DOM elements #2894
Comments
Linking @36degrees' comment on the PR that sparked the creation of this issue: https://github.com/alphagov/govuk-frontend/pull/2887/files#r983699156. |
A further note that the dom-helpers.mjs file has gained a second helper to create a DocumentFragment out of an HTML String to scaffold larger structures, that's worth discussing at the same time: export function createFragmentFromHTML (html) {
const template = document.createElement('template')
template.innerHTML = html
return template.content.cloneNode(true)
} |
Waiting for further discussion about abstraction in #2894
Waiting for further discussion about abstraction in #2894
Waiting for further discussion about abstraction in #2894
Waiting for further discussion about abstraction in #2894
Waiting for further discussion about abstraction in #2894
Missed to share that I had explored the concept of creating elements in a more thorough way outside of govuk-frontend at the time. There may be useful code in there we could look at. |
Having spent a bit of time looking at the JavaScript for the accordion recently I can see more of a need for this than maybe I appreciated before. I've pushed a branch with a commit that shows what it might look like in practise (although just accepting attributes for now) in case it's useful in the future: 13ef8cd |
Probably one step too far, but given our tool chain has Babel set up to compile our sources, we could use the transform-react-jsx plugin to automatically transform JSX markup into a |
What
Add a
createElement
(naming up for discussion) helper function to act as a shortcut for creating elements and assigning them attributes, props and/or children (scope to be defined). Something along the lines of the following (in a syntax more adapted to the browsers we support):Why
A lightweight version of such helper has been added to de-clutter tests for the CharacterCount internationalisation: https://github.com/alphagov/govuk-frontend/blob/character-count-i18n/lib/dom-helpers.mjs. The Accordion and CharacterCount create a few elements themselves when initialised which would get a bit leaner.
Who needs to work on this
Developers
Who needs to review this
Developers
Done when
The text was updated successfully, but these errors were encountered: