govuk-frontend icon indicating copy to clipboard operation
govuk-frontend copied to clipboard

Add an icon next to an input using the govukInput macro

Open dashouse opened this issue 7 years ago • 3 comments

I was trying to replicate this design with the Input macro:

screen shot 2018-07-23 at 12 49 09

In the end I did this with HTML like this

<div class="govuk-form-group">
  <label class="govuk-label govuk-label--s" for="cvv">
    Card security code
  </label>
  <span id="cvv-hint" class="govuk-hint">
    The last 3 digits on the back of the card
  </span>
  <input class="govuk-input govuk-input--width-4 govuk-!-display-inline-block" id="cvv" name="post-code" type="text">
  <span class="govuk-!-display-inline-block" style="vertical-align: middle; height: 40px;">
    <img alt="image of the back of a bank card" src="https://png.icons8.com/ios/1600/bank-card-back-side.png" style="height: 40px;">
  </span>
</div>

My expectation was that I would be able to import the label, hint, error and input components separately, add in an additional image and wrap it in govuk-form-group - This works, however I was unable to remove the second govuk-form-group that comes with the govukInput macro.

dashouse avatar Jul 23 '18 12:07 dashouse

if we added caller to the input, the macro would look like that:

{% call govukInput({
    label: {
      text: 'Card security code',
      classes: 'govuk-label--s'
    },
    hint: {
      text: 'The last 3 digits on the back of the card'
    },
    classes: 'govuk-input--width-4 govuk-!-display-inline-block',
    id: 'cvv'
  }) %}
   <span class="govuk-!-display-inline-block" style="vertical-align: middle; height: 40px;">
    <img alt="image of the back of a bank card" src="https://png.icons8.com/ios/1600/bank-card-back-side.png" style="height: 40px;">
  </span>
{% endcall %}

not sure this is much better than using plain html

Position of the caller depends where the custom content is in relation to the defined output. So in this case you can't magically prepend the image left of the input

kr8n3r avatar Jul 31 '18 15:07 kr8n3r

I guess one pseudo code could be:

{% call fieldset() %}
    {{ label() }}
    {{ hint() }}
    {{ input() }}
    <span class="govuk-!-display-inline-block" style="vertical-align: middle; height: 40px;">
        <img alt="image of the back of a bank card" src="https://png.icons8.com/ios/1600/bank-card-back-side.png" style="height: 40px;">
    </span>
{% endcall %}

Of course this would depend on the components being less coupled

NickColley avatar Jul 31 '18 16:07 NickColley

yeah that's the alternative. then the question is what is the default output of say {{ input() }} ? if it's just the input and they would need to manually supply the id of it to the label's for attribute, then we're not doing much to help them build stuff over plain html.

sure, no need to specify classes.

kr8n3r avatar Jul 31 '18 17:07 kr8n3r

I'm going to close this one since we merged support for custom before/after content today 🎉

  • https://github.com/alphagov/govuk-frontend/pull/4567

colinrotherham avatar Feb 08 '24 09:02 colinrotherham