Class: Primer::Alpha::ActionMenu::SubMenuItem

Inherits:
Primer::Alpha::ActionList::Item show all
Defined in:
app/components/primer/alpha/action_menu/sub_menu_item.rb

Overview

This component is part of <%= link_to_component(Primer::Alpha::ActionMenu) %> and should not be used as a standalone component.

Constant Summary

Constants inherited from Primer::Alpha::ActionList::Item

Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, Primer::Alpha::ActionList::Item::DEFAULT_SCHEME, Primer::Alpha::ActionList::Item::DEFAULT_SIZE, Primer::Alpha::ActionList::Item::DEFAULT_TRUNCATION_BEHAVIOR, Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_MAPPINGS, Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS, Primer::Alpha::ActionList::Item::SCHEME_MAPPINGS, Primer::Alpha::ActionList::Item::SCHEME_OPTIONS, Primer::Alpha::ActionList::Item::SIZE_MAPPINGS, Primer::Alpha::ActionList::Item::SIZE_OPTIONS, Primer::Alpha::ActionList::Item::TRUNCATION_BEHAVIOR_MAPPINGS, Primer::Alpha::ActionList::Item::TRUNCATION_BEHAVIOR_OPTIONS

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 Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Attribute Summary

Attributes inherited from Primer::Alpha::ActionList::Item

#active, #disabled, #href, #id, #item_id, #list, #parent

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 Primer::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(content_arguments: {}, form_arguments: {}, **system_arguments) ⇒ SubMenuItem

Returns a new instance of SubMenuItem.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 11

def initialize(content_arguments: {}, form_arguments: {}, **system_arguments)
  # We extract form_arguments from system_arguments here to avoid passing them to the
  # ActionList::Item base class or to the SubMenu instance. Doing so prevents a form
  # input from being emitted for sub-menu items, which prevents an extra empty value
  # from being sent to the server on form submit.
  @sub_menu = SubMenu.allocate
  system_arguments = @sub_menu.send(:initialize, **system_arguments)
  system_arguments[:id] = "#{@sub_menu.menu_id}-button"

  @form_arguments = form_arguments

  content_arguments[:tag] = :button
  content_arguments[:popovertarget] = "#{@sub_menu.menu_id}-overlay"

  content_arguments[:aria] = merge_aria(
    content_arguments, {
      aria: {
        controls: "#{@sub_menu.menu_id}-list",
        haspopup: true
      }
    }
  )

  super
end

Instance Method Details

#with_avatar_item(**system_arguments, &block) ⇒ Object



45
46
47
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 45

def with_avatar_item(**system_arguments, &block)
  @sub_menu.with_avatar_item(form_arguments: @form_arguments, **system_arguments, &block)
end

#with_divider(**system_arguments, &block) ⇒ Object



41
42
43
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 41

def with_divider(**system_arguments, &block)
  @sub_menu.with_divider(form_arguments: @form_arguments, **system_arguments, &block)
end

#with_group(**system_arguments, &block) ⇒ Object



53
54
55
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 53

def with_group(**system_arguments, &block)
  @sub_menu.with_group(form_arguments: @form_arguments, **system_arguments, &block)
end

#with_item(**system_arguments, &block) ⇒ Object



37
38
39
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 37

def with_item(**system_arguments, &block)
  @sub_menu.with_item(form_arguments: @form_arguments, **system_arguments, &block)
end

#with_sub_menu_item(**system_arguments, &block) ⇒ Object



49
50
51
# File 'app/components/primer/alpha/action_menu/sub_menu_item.rb', line 49

def with_sub_menu_item(**system_arguments, &block)
  @sub_menu.with_sub_menu_item(form_arguments: @form_arguments, **system_arguments, &block)
end