Class: CCS::Components::GovUK::Field::Input::TextInput::Fix

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/field/input/text_input/fix.rb

Overview

GOV.UK Text Input prefix/suffix

This is used to generate the prefix/suffix HTML for a text input

Constant Summary

Constants inherited from Base

Base::DEFAULT_ATTRIBUTES

Instance Method Summary collapse

Constructor Details

#initialize(text:, fix:, **options) ⇒ Fix

Returns a new instance of Fix.

Parameters:

  • text (String)

    the text for the prefix/suffix

  • fix (String)

    either “pre” or “suf”

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the prefix/suffix HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



31
32
33
34
35
36
37
38
# File 'lib/ccs/components/govuk/field/input/text_input/fix.rb', line 31

def initialize(text:, fix:, **options)
  super(**options)

  @options[:attributes][:class] = "govuk-input__#{fix}fix #{@options[:attributes][:class]}".rstrip
  (@options[:attributes][:aria] ||= {})[:hidden] = true

  @text = text
end

Instance Method Details

#render { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Text Input prefix/suffix

Yields:

  • the field HTML

Returns:

  • (ActiveSupport::SafeBuffer)


46
47
48
# File 'lib/ccs/components/govuk/field/input/text_input/fix.rb', line 46

def render
  tag.div(text, **options[:attributes])
end