Sha256: d9cf190d63415c267c3aa02f57424e9e9e2ac2a22081b1bbb498816adc1f6037

Contents?: true

Size: 1.4 KB

Versions: 83

Compression:

Stored size: 1.4 KB

Contents

<%
  options ||= []
  id ||= false
  label ||= false
  full_width ||= false
  name ||= id
  heading_size = false unless ['s', 'm', 'l', 'xl'].include?(heading_size)
  error_message ||= nil
  error_id ||= nil

  if error_message || error_id
    error_id = "error-#{SecureRandom.hex(4)}" unless error_id
    aria_describedby = { describedby: error_id }
  end

  css_classes = %w(govuk-form-group gem-c-select)
  css_classes << "govuk-form-group--error" if error_message

  select_classes = %w(govuk-select)
  select_classes << "gem-c-select__select--full-width" if full_width
  select_classes << "govuk-select--error" if error_id

  label_classes = %w(govuk-label)
  label_classes << "govuk-label--#{heading_size}" if heading_size

  select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
  data_module = { module: "track-select-change" } unless select_helper.data_tracking?.eql?(false)
%>
<% if options.any? && id && label %>
  <%= content_tag :div, class: css_classes do %>
    <%= label_tag(id, label, class: label_classes) %>

    <% if error_message %>
      <%= render "govuk_publishing_components/components/error_message", {
        id: error_id,
        text: error_message
      } %>
    <% end %>

    <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_classes, data: data_module, aria: aria_describedby %>
  <% end %>
<% end %>

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
govuk_publishing_components-21.49.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.48.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.47.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.46.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.45.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.44.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.43.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.42.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.41.4 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.41.3 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.41.2 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.41.1 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.41.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.40.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.39.0 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.38.5 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.38.4 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.38.3 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.38.2 app/views/govuk_publishing_components/components/_select.html.erb
govuk_publishing_components-21.38.1 app/views/govuk_publishing_components/components/_select.html.erb