Class: CCS::Components::GovUK::ErrorMessage
- Defined in:
- lib/ccs/components/govuk/error_message.rb
Overview
GOV.UK Error Message
This is used to generate the error message component from the GDS - Components - Error message
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the error message
{ class: 'govuk-error-message' }.freeze
Instance Method Summary collapse
-
#initialize(message:, attribute:, **options) ⇒ ErrorMessage
constructor
A new instance of ErrorMessage.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Error message component.
Constructor Details
#initialize(message:, attribute:, **options) ⇒ ErrorMessage
Returns a new instance of ErrorMessage.
33 34 35 36 37 38 39 40 41 |
# File 'lib/ccs/components/govuk/error_message.rb', line 33 def initialize(message:, attribute:, **) super(**) @options[:attributes][:id] ||= "#{attribute}-error" if attribute @message = @attribute = attribute @visually_hidden_text = @options[:visually_hidden_text] || 'Error' end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Error message component
47 48 49 50 51 52 53 54 55 |
# File 'lib/ccs/components/govuk/error_message.rb', line 47 def render tag.p(**[:attributes]) do if visually_hidden_text.present? concat(tag.span("#{visually_hidden_text}:", class: 'govuk-visually-hidden')) concat(' ') end concat() end end |