-
Notifications
You must be signed in to change notification settings - Fork 336
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
Ensure GOV.UK Frontend component selectors cannot conflict when initialised #1443
Conversation
This ensures that the components cannot accidentally conflict with other components with the same name.
… selector We want to make sure we're only adding JavaScript enhancements to buttons that clearly have the `[data-module="govuk-button"]` attribute. This will allow us to fix an issue where we want to be able to scope the 'prevent double click' feature from failing on multiple buttons.
…e selector We want to make sure we're only adding JavaScript enhancements to details elements that clearly have the `[data-module="govuk-details"]` attribute. This makes sure the GOV.UK Frontend is future friendly and makes this component consistent with the rest of the components.
These are now consistent with all components
govuk-
and initialise button and details components with [data-module] selectors
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.
Needs a changelog entry
govuk-
and initialise button and details components with [data-module] selectorsvar $buttons = document.querySelector('[data-module="govuk-buttons"]') | ||
``` | ||
|
||
### Details component |
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.
Is there a way to avoid the duplication here? I duplicated it to be really clear but it makes it lengthy
@@ -268,6 +268,77 @@ | |||
|
|||
([PR #1376](https://github.com/alphagov/govuk-frontend/pull/1376)) | |||
|
|||
- Ensure GOV.UK Frontend component selectors cannot conflict when initialised |
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.
@m-green would be good to get your thoughts on this
CHANGELOG.md
Outdated
|
||
If you're using Nunjucks macros, and are [using the `initAll` function](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md#option-1-include-javascript) you will not be affected. | ||
|
||
If you are using HTML, you will need to add the `govuk-` prefix to any `[data-module]` attributes referencing GOV.UK Frontend components. |
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.
I wonder if
referencing GOV.UK Frontend components.
is clear? Could we say
any
[data-module]
attributes on GOV.UK Frontend component HTML
We could add
and any
[data-module]
attributes referencing GOV.UK Frontend scripts in your custom components
although it seems like a fairly unlikely scenario.
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.
Or alternatively
any
[data-module]
attributes in HTML which reference GOV.UK Frontend Javascript
🤷♀
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.
Will try and make this clearer thanks Hanna :)
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.
I've moved the example around and adjusted the wording so it hopefully makes it clearer, lemme know what you think.
CHANGELOG.md
Outdated
|
||
If you are using HTML, you will need to add the `govuk-` prefix to any `[data-module]` attributes referencing GOV.UK Frontend components. | ||
|
||
If you are initialising components manually, you will need to add the `govuk-` prefix to any selectors referencing GOV.UK Frontend components: |
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.
any Javascript selectors
to make it super clear.
91b17ff
to
b61e331
Compare
b61e331
to
19fc174
Compare
Hi @NickColley - I think I've managed to use sections to combine this in a way that avoids duplication (and means that each type of user - HTML/Javascript - gets their guidance in one go). And it's much shorter! Let me know what you think. |
CHANGELOG.md
Outdated
@@ -268,72 +268,47 @@ | |||
|
|||
([PR #1376](https://github.com/alphagov/govuk-frontend/pull/1376)) | |||
|
|||
- Ensure GOV.UK Frontend component selectors cannot conflict when initialised | |||
- Update and add the data-module attribute |
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.
I think this title is too vague now
CHANGELOG.md
Outdated
|
||
Components which have JavaScript functionality include a data attribute called `[data-module]`, | ||
we have added the `govuk-` prefix as a namespace. | ||
The `[data-module]` attribute in components now has a `gov-uk` namespace prefix. This is to avoid conflicts between attribute names, and make the attributes consistent with our style for class names. |
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.
gov-uk
-> govuk-
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.
Conflicts with what? Before it was clear what it was conflicting with I think.
CHANGELOG.md
Outdated
|
||
This ensures the component's name does not conflict with other service level components | ||
with the same name, which is consistent with our CSS class name convention. | ||
The [button](https://design-system.service.gov.uk/components/button/#start-buttons) and [details](https://design-system.service.gov.uk/components/details/) components now also have the `[data-module]` attribute. |
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.
'now have' -> 'now use'?
CHANGELOG.md
Outdated
|
||
If you're using Nunjucks macros, and are [using the `initAll` function](https://github.com/alphagov/govuk-frontend/blob/master/docs/installation/installing-with-npm.md#option-1-include-javascript) you will not be affected. | ||
You'll need to update your CSS or JavaScript code, to make sure that JavaScript can find and initalise the components. |
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.
I'm not sure CSS is relevant to this.
'JavaScript', 'your JavaScript'
CHANGELOG.md
Outdated
</div> | ||
``` | ||
|
||
If you are initialising components manually, you will need to add the `govuk-` prefix to any CSS selectors used to find GOV.UK Frontend components: | ||
You'll also need to add `data-module="govuk-button"` to each: |
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 is incorrect since we don't want to add 'govuk-button' to the details component
CHANGELOG.md
Outdated
For example the accordion component selector has changed from `[data-module="accordion"]` to `[data-module="govuk-accordion"]`. | ||
-- If you're using HTML and CSS | ||
|
||
You'll need to add the `govuk-` prefix to the `[data-module]` attribute in each CSS selector. |
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.
Simplifying this to 'CSS' selector means this is no longer correct, as we want to help people using JavaScript not CSS
5b0025b
to
19fc174
Compare
Spoke to Mark and we're going to try and simplify the CHANGELOG later in the release notes so we can unblock other work. We need to pair on this to get it right... |
The GOV.UK Design System V3 has introduced a data module for buttons[0] that allows JavaScript events to be registered. As per the documentation it's now present by default [0] alphagov/govuk-frontend#1443
This change is required due to new approach to namespacing[0] in V3.0 of the GOV.UK Design System [0] alphagov/govuk-frontend#1443
This change is required due to new approach to namespacing[0] in V3.0 of the GOV.UK Design System [0] alphagov/govuk-frontend#1443
This is for compatibility with [version 3.0.0](https://github.com/alphagov/govuk-frontend/releases/tag/v3.0.0) of the govuk-frontend, which addes a prefix to `data-module` attributes to avoid namespacing conflicts. See [issue 1443](alphagov/govuk-frontend#1443)
This is for compatibility with [version 3.0.0](https://github.com/alphagov/govuk-frontend/releases/tag/v3.0.0) of the govuk-frontend, which addes a prefix to `data-module` attributes to avoid namespacing conflicts. See [issue 1443](alphagov/govuk-frontend#1443)
The GOV.UK Design System V3 has introduced a data module for buttons[0] that allows JavaScript events to be registered. As per the documentation it's now present by default [0] alphagov/govuk-frontend#1443
This change is required due to new approach to namespacing[0] in V3.0 of the GOV.UK Design System [0] alphagov/govuk-frontend#1443
This change is required due to new approach to namespacing[0] in V3.0 of the GOV.UK Design System [0] alphagov/govuk-frontend#1443
This change introduces to main changes:
govuk-
prefix to all[data-module]
selectors to avoid conflicts.We have found users using the same name without a prefix which results in a conflicts that break components: Namespacing [data-module] to avoid conflicts #1218
Initialising the button and details component with a
[data-module]
selector so all components are initialised consistently.Doing this for the button is important as it unblocks a bugfix for the 'prevent double click' feature: #1433
It will allow us to fix this issue without adding JavaScript behaviour to all buttons on pages, which could result in performance or conflict issues.
Closes #1218