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

CharacterCount doesn't render or initialise properly if maxlength or maxwords is not passed to the macro #2910

Closed
2 tasks done
romaricpascal opened this issue Oct 10, 2022 · 5 comments · Fixed by #2915
Closed
2 tasks done
Assignees
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) character count
Milestone

Comments

@romaricpascal
Copy link
Member

romaricpascal commented Oct 10, 2022

What

It's a two part thing:

First is the HTML part, before JS kicks in: if omitting the maxlength or maxwords option when calling the govukCharacterCount macro, the HTML rendered displays a "You can enter up to undefined characters" message.

CharacterCount component with faulty 'You can enter up to undefined characters' hint

Second is the JavaScript part: When initialising the component with a JavaScript maxlength or maxwords config, the message disappears, but doesn't get replace by a count of the remaining character.

CharacterCount component without message after JavaScript kicks in

This will be problematic for people looking to use the JavaScript configuration to set a blanket setting accross their service. For that to work, we need to render the component without a data-maxwords or data-maxlength attribute and fix the HTML part.

And then once that's through, we need to make sure the component initialises OK with a missing length.

Who needs to work on this

Developers

Who needs to review this

Developers

Done when

  • Library users can get a clean render of the count message when no maxwords or maxlength are provided
  • JavaScript initialises properly when running over a HTML generated by the macro without maxwords or maxlength
@romaricpascal romaricpascal added awaiting triage Needs triaging by team 🐛 bug Something isn't working the way it should (including incorrect wording in documentation) character count javascript squad and removed awaiting triage Needs triaging by team labels Oct 10, 2022
@romaricpascal romaricpascal added this to the v4.4.0 milestone Oct 11, 2022
@romaricpascal
Copy link
Member Author

This happens with the current version of govuk-frontend, in Firefox. Latest version's JavaScript handles things OK in terms of replacing the message 🥳

However the macro still outputs an untidy text and we could either hide it as I initially suggester (using govuk-visually-hidden like the JS does), or replace the default to "You can enter a limited number of characters".

@36degrees
Copy link
Contributor

Yeah, unfortunately I think this has been around a while – see also #1725. I think it'd be nice to fix this in v4.4.0, but I don't think this is a regression.

@romaricpascal
Copy link
Member Author

That was just something I noticed while preparing my demo yesterday juggling between the 4.3.1 and main versions, but I prefered flagging to keep track of it.

For the JavaScript bit, thinking about it, without any default for maxlength removing the message is probably fine. We can't really set a default anyway for that maxlength as a "generic number of charaters to limit a textarea" feels quite arbitrary.

Regarding the HTML from the macro, thanks for linking to the old issue. I think with the introduction of fallbackHintText for that component, that may solve the final user experience when the field is initialised without a maximum, letting developers provide a custom message..

@querkmachine
Copy link
Member

As a quick bit of background, we did some changes to the character counter functionality earlier this year to fix bugs and improve the screen reader experience in a number of browsers and technologies (see PR #2577 for the long read).

Consequentially, the counter is a bit of a complex web of visible (sometimes) and hidden (sometimes) elements. It may be best to avoid any solution that involves changing the visibility of elements, as this may have repercussions on those past changes, requiring some extensive re-testing!

@romaricpascal
Copy link
Member Author

Cheers, that's some handy stuff to be aware. I had noticed the separate visible and debounced screen-reader feedback in the JavaScript side. I think that part should be left alone indeed: no maxlength, no maxwords -> no extra feedback if you don't set one when configuring JavaScript sounds a fine way to do.

Regarding a HTML cleanup, I think there's all the options for whatever people want to do:

  • fallbackHintText lets you set some text
  • countMessage.classes lets you add a govuk-visually-hidden on the .govuk-character-count__message element, similarly to what the JS would do when it kicks in if you really want an empty area. You probably don't, though, to avoid a layout shift when the JS kicks in so we may not want to shout too much about that one. And if you never show a count message, might as well just use a plain textarea 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working the way it should (including incorrect wording in documentation) character count
Projects
Development

Successfully merging a pull request may close this issue.

3 participants