Class: Yattho::Beta::AutoComplete::Item

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/auto_complete/item.rb

Overview

Use ‘AutoCompleteItem` to list results of an auto-completed search.

Constant Summary collapse

ALLOWED_DESCRIPTION_VARIANTS =
[:inline, :block].freeze

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

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

Constructor Details

#initialize(value:, selected: false, disabled: false, description_variant: :block, **system_arguments) ⇒ Item

Returns a new instance of Item.

Examples:

Default

<%= render(Yattho::Beta::AutoComplete::Item.new(selected: true, value: "value")) do %>
  Selected
<% end %>
<%= render(Yattho::Beta::AutoComplete::Item.new(value: "value")) do %>
  Not selected
<% end %>

Parameters:

  • value (String)

    Value of the item.

  • selected (Boolean) (defaults to: false)

    Whether the item is selected.

  • disabled (Boolean) (defaults to: false)

    Whether the item is disabled.

  • description_variant (Hash) (defaults to: :block)

    Changes the description style. Allowed values are :inline, :block

  • description (String)

    Display description text below label

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/components/yattho/beta/auto_complete/item.rb', line 51

def initialize(value:, selected: false, disabled: false, description_variant: :block, **system_arguments)
  @description_variant = ALLOWED_DESCRIPTION_VARIANTS.include?(description_variant) ? description_variant : :block

  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :li
  @system_arguments[:role] = :option
  @system_arguments[:'data-autocomplete-value'] = value

  @system_arguments[:'aria-selected'] = true if selected
  @system_arguments[:'aria-disabled'] = true if disabled

  @system_arguments[:classes] = class_names(
    "ActionList-item",
    system_arguments[:classes]
  )
end

Instance Method Details

#description_variant_classObject

Description variant class.



69
70
71
72
73
74
75
76
# File 'app/components/yattho/beta/auto_complete/item.rb', line 69

def description_variant_class
  case @description_variant
  when :block
    "ActionList-item-blockDescription"
  when :inline
    "ActionList-item-descriptionWrap--inline"
  end
end