Files
notifications-admin/app/templates/components/copy-to-clipboard.html
Chris Hill-Scott c6fb0e6694 Remove whitespace from copy to clipboard component
If there is whitespace in the element containing the value to be copied
then Firefox[1] includes that space in the value it puts in the clipboard.

This is obviously annoying since `foo-bar` might be a valid API key where
`foo-bar ` is not.

This commit fixes that by using the `-` in Jinja to gobble whitespace.

I also looked at doing this in the Javascript, but the browser API for
selecting some text and copying it doesn’t give an obvious place for
using `String.prototype.trim()`.

1. Tested with Firefox 100.0 on Mac OS 12.2.1
2022-05-05 15:42:05 +01:00

14 lines
557 B
HTML

{% macro copy_to_clipboard(value, name, thing) %}
{% if name|lower == thing|lower %}
<h2 class="copy-to-clipboard__name">
{{ name }}
</h2>
{% endif %}
<div data-module="copy-to-clipboard" data-value="{{ value }}" data-thing="{{ thing }}" data-name="{{ name }}">
<span class="copy-to-clipboard__value">
{%- if name|lower != thing|lower %}<span class="govuk-visually-hidden">{{ thing }}: </span>{% endif %}{{ value -}}
</span>
<span class="copy-to-clipboard__notice" aria-live="assertive"></span>
</div>
{% endmacro %}