Class: Primer::OpenProject::Fieldset

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/fieldset.rb

Overview

A low-level component for building fieldsets with unopinionated styling.

This component is not designed to be used directly, but rather a primitive for authors of other components and form controls.

Defined Under Namespace

Classes: LegendComponent

Constant Summary

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(legend_text: nil, visually_hide_legend: false, **system_arguments) ⇒ Fieldset

Returns a new instance of Fieldset.

Parameters:

  • legend_text (String) (defaults to: nil)

    A legend should be short and concise. The String will also be read by assistive technology.

  • visually_hide_legend (Boolean) (defaults to: false)

    Controls if the legend is visible. If true, screen reader only text will be added.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/components/primer/open_project/fieldset.rb', line 21

def initialize(legend_text: nil, visually_hide_legend: false, **system_arguments) # rubocop:disable Lint/MissingSuper
  @legend_text = legend_text
  @visually_hide_legend = visually_hide_legend
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :fieldset

  deny_aria_key(
    :label,
    "instead of `aria-label`, include `legend_text` and set `visually_hide_legend` to `true` on the component initializer.",
    **@system_arguments
  )
end

Instance Attribute Details

#legend_textObject (readonly)

Returns the value of attribute legend_text.



12
13
14
# File 'app/components/primer/open_project/fieldset.rb', line 12

def legend_text
  @legend_text
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/components/primer/open_project/fieldset.rb', line 34

def render?
  content? && (legend_text.present? || legend?)
end