Class: CCS::Components::GovUK::Field::Input::PasswordInput::ShowHideButton
- Inherits:
-
Object
- Object
- CCS::Components::GovUK::Field::Input::PasswordInput::ShowHideButton
- Includes:
- ActionView::Context, ActionView::Helpers, ActionView::Helpers::FormTagHelper
- Defined in:
- lib/ccs/components/govuk/field/input/password_input/show_hide_button.rb
Overview
GOV.UK Password input show/hide button
This is used to generate the password input show/hide button
Instance Method Summary collapse
-
#initialize(attribute:, context:, button: {}, after_input: nil, **options) ⇒ ShowHideButton
constructor
A new instance of ShowHideButton.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Password input show/hide button.
Constructor Details
#initialize(attribute:, context:, button: {}, after_input: nil, **options) ⇒ ShowHideButton
Returns a new instance of ShowHideButton.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ccs/components/govuk/field/input/password_input/show_hide_button.rb', line 38 def initialize(attribute:, context:, button: {}, after_input: nil, **) [:classes] = "govuk-button--secondary govuk-password-input__toggle govuk-js-password-input-toggle #{[:classes]}".rstrip [:attributes] = { type: :button, aria: { controls: .dig(:attributes, :id) || field_id([:form]&.object_name, attribute), label: [:show_password_aria_label_text] || 'Show password' }, hidden: { value: true, optional: true } } @show_hide_button = Button.new(text: [:show_password_text] || 'Show', context: context, classes: [:classes], attributes: [:attributes]) @after_input = after_input end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Password input show/hide button
60 61 62 63 64 65 |
# File 'lib/ccs/components/govuk/field/input/password_input/show_hide_button.rb', line 60 def render capture do concat(.render) concat(after_input) if after_input end end |