Commit Graph

7 Commits

Author SHA1 Message Date
Ryan Ahearn
bb2d57b27b Update tests to use most recent jest and supporting libraries 2022-10-27 11:12:39 -04:00
Tom Byers
2b91d1d524 Fix mis-spelling of aria-describedby
This is currently spelt incorrectly though it
seemed to work nonetheless. Can only assume this
is a common error, for this attribute or all
attribute names, so browsers work it out.

This makes the spelling match the spec:

https://www.w3.org/TR/wai-aria/#aria-describedby
2021-10-19 11:09:37 +01:00
Chris Hill-Scott
43e57b7089 Handle textbox without existing aria-described-by
jQuery.attr returns `undefined` if an element does not have an
attribute. We want an empty string, rather than the default of coercing
`undefined` to the string `'undefined'`.
2021-01-08 16:05:55 +00:00
Chris Hill-Scott
6f514ef019 Describe example textbox by hint not label
The `<textarea>` should have its existing `aria-describedby` point to a
hint. Pointing to the label is bad practice as it would duplicate the
accessible name into the accessible description. It’s good not to have
that in the tests in case anyone copies the code elsewhere.
2021-01-08 12:53:06 +00:00
Chris Hill-Scott
d452c0081d Add throttling to AJAX calls
The endpoint that count characters should be pretty low-load because it
won’t talk to the database (unless, on the first request, the user and
service aren’t cached in Redis).

The response size is also very small, only one line of text wrapped in a
single `<span>`, so won’t be as CPU-intensive to render as a whole page.

Still, we don’t want to completely hammer the server if a user types
very quickly.

This commit adds some throttling, so that we wait until there’s a
certain amount of delay between keystrokes before firing off the request
to the backend.

I’ve set the delay at 150ms. At normal typing speed this makes the lag
feel fairly imperceptible – it feels like you get an updated count in
response to most keystrokes. It’s only if you really mash the keyboard
that the count won’t update until you take a breath.
2021-01-08 12:49:05 +00:00
Chris Hill-Scott
c3b6c03411 Add ARIA attributes from Design System component
This commit copies the same ARIA attributes that are added to the
character count component[1] in the GOV.UK Design System.

This means that screen reader users will hear the count message when
they stop typing.

1. https://design-system.service.gov.uk/components/character-count/
2021-01-07 17:14:12 +00:00
Chris Hill-Scott
3fdaa29f35 Fetch template length message as user types
This commit adds some Javascript that makes AJAX requests as the users
changes the content of their template.

It then takes the content returned by the backend and inserts it in the
page.
2021-01-07 17:11:43 +00:00