-
Notifications
You must be signed in to change notification settings - Fork 320
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88b3f07
Add `govuk-` prefix namespace to data-modules
NickColley 8a7e275
Target namespaced data-module selectors when initialising components
NickColley 89a8453
Update full page examples test data-modules selectors
NickColley cf6e023
Update error summary test to target new namespaced data-module selector
NickColley 4e6531c
Update button component to initialise consistently with a data-module…
NickColley b447eff
fixup better place comment about shim
NickColley fde872b
Update details component to initialise consistently with a data-modul…
NickColley 77ee1be
Update details component comment to remove usage instructions
NickColley 9f18649
Update character count initialisation variable to be consistent
NickColley 77d91ac
Update documentation to use new prefixed data-modules selector
NickColley 19fc174
Add CHANGELOG entry
NickColley 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,77 @@ | |
|
||
([PR #1376](https://github.com/alphagov/govuk-frontend/pull/1376)) | ||
|
||
- Ensure GOV.UK Frontend component selectors cannot conflict when initialised | ||
|
||
Components which have JavaScript functionality include a data attribute called `[data-module]`, | ||
we have added the `govuk-` prefix as a namespace. | ||
|
||
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. | ||
|
||
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. | ||
|
||
For example the accordion component selector has changed from `[data-module="accordion"]` to `[data-module="govuk-accordion"]`. | ||
|
||
```html | ||
<div class="govuk-accordion" data-module="govuk-accordion"> | ||
<!-- ... --> | ||
</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: | ||
|
||
```javascript | ||
var $accordions = document.querySelector('[data-module="govuk-accordion"]') | ||
``` | ||
|
||
([PR #1443](https://github.com/alphagov/govuk-frontend/pull/1443)) | ||
|
||
|
||
- Button and details components are now initialised consistently | ||
|
||
The button and details components now use the `[data-module]` selector to initialise them. | ||
|
||
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. | ||
|
||
### Button component | ||
|
||
The button component now is initialised with the `[data-module="govuk-button"]` selector instead of globally based on the document. | ||
|
||
If you are using HTML, you need to add the `[data-module="govuk-button"]` attribute to your buttons: | ||
|
||
```html | ||
<button ... data-module="govuk-button">...</button> | ||
``` | ||
|
||
If you are initialising the button component manually, you will need to reference this `[data-module]` attribute: | ||
|
||
```javascript | ||
var $buttons = document.querySelector('[data-module="govuk-button"]') | ||
``` | ||
|
||
### Details component | ||
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. Is there a way to avoid the duplication here? I duplicated it to be really clear but it makes it lengthy |
||
|
||
The details component now is initialised with the `[data-module="govuk-details"]` selector instead of `details` globally. | ||
|
||
If you are using the Nunjucks macro no changes is needed. | ||
|
||
If you are using HTML, you need to add the `[data-module="govuk-details"]` attribute to your details: | ||
|
||
```html | ||
<details ... data-module="govuk-details">...</details> | ||
``` | ||
|
||
If you are initialising the button component manually, you will need to reference this `[data-module]` attribute: | ||
|
||
```javascript | ||
var $details = document.querySelector('[data-module="govuk-details"]') | ||
``` | ||
|
||
([PR #1443](https://github.com/alphagov/govuk-frontend/pull/1443)) | ||
|
||
- Pull Request Title goes here | ||
|
||
Description goes here (optional) | ||
|
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
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
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
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
Oops, something went wrong.
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.
@m-green would be good to get your thoughts on this