Skip to content
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

Allow CharacterCount to receive configuration via JavaScript #2883

Merged
merged 8 commits into from
Sep 29, 2022

Conversation

romaricpascal
Copy link
Member

@romaricpascal romaricpascal commented Sep 27, 2022

The configuration spree continues! CharacterCount needs its own little behaviour when it comes to merging the data attributes and JavaScript configuration:

maxwords takes precedence over maxlength. This means we need to clear some of the JavaScript configuration if any of these options are set through data attributes to avoid a maxwords set in JavaScript always winning against a data-maxlength attribute:

new CharacterCount($element, {maxwords: 150}).init();
<div class="govuk-character-count" data-module="govuk-character-count" data-maxlength="200">
  <!-- Omitted for clarity -->
</div>

Commits should paint a step-by-step picture of how things happened.

Keeping this as draft for now as I'm on the fence of whether to rework the tests as unit tests checking that the right values end up in this.config rather than run in a browser. Opening to review with puppeteer tests so further work on internationalisation can be carried on. Tests will likely be reworked soon when/if creating a base component in 5.0.

Closes #2837

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2883 September 27, 2022 17:06 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2883 September 27, 2022 17:09 Inactive
@romaricpascal romaricpascal marked this pull request as ready for review September 28, 2022 09:51
Thanks to the introduction of the dataset polyfill for configuration/i18n, we can now use element.dataset directly
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2883 September 28, 2022 13:43 Inactive
@romaricpascal romaricpascal requested a review from a team September 29, 2022 09:27
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2883 September 29, 2022 10:59 Inactive
Copy link
Member

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@romaricpascal romaricpascal merged commit 0cbe83f into main Sep 29, 2022
@romaricpascal romaricpascal deleted the character-count-config branch September 29, 2022 13:33
@romaricpascal romaricpascal mentioned this pull request Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants