Class: Primer::Alpha::ActionMenu::List

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

Overview

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

Constant Summary collapse

DEFAULT_ITEM_TAG =
:button
ITEM_TAG_OPTIONS =
[:a, :"clipboard-copy", DEFAULT_ITEM_TAG].freeze

Constants inherited from Primer::Alpha::ActionList

Primer::Alpha::ActionList::DEFAULT_MENU_ITEM_ROLE, Primer::Alpha::ActionList::DEFAULT_ROLE, Primer::Alpha::ActionList::DEFAULT_SCHEME, Primer::Alpha::ActionList::DEFAULT_SELECT_VARIANT, Primer::Alpha::ActionList::MENU_ROLE, Primer::Alpha::ActionList::SCHEME_MAPPINGS, Primer::Alpha::ActionList::SCHEME_OPTIONS, Primer::Alpha::ActionList::SELECT_VARIANT_OPTIONS, Primer::Alpha::ActionList::SELECT_VARIANT_ROLE_MAP

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

#id, #role, #select_variant

Instance Method Summary collapse

Methods inherited from Primer::Alpha::ActionList

#acts_as_form_input?, #acts_as_menu?, #allows_selection?, #before_render, #build_avatar_item, #build_item, custom_element_name, #custom_element_name, #multi_select?, #required_form_arguments_given?, #single_select?, #will_add_item, #with_divider

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, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Constructor Details

#initialize(menu_id:, **system_arguments, &block) ⇒ List

Returns a new instance of List.

Parameters:

  • menu_id (String)

    ID of the parent menu.

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList) %>



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/primer/alpha/action_menu/list.rb', line 44

def initialize(menu_id:, **system_arguments, &block)
  @menu_id = menu_id

  system_arguments[:aria] = merge_aria(
    system_arguments,
    { aria: { labelledby: "#{@menu_id}-button" } }
  )

  system_arguments[:role] = :menu
  system_arguments[:scheme] = :inset
  system_arguments[:id] = "#{@menu_id}-list"

  super(**system_arguments, &block)
end

Instance Method Details

#with_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, data: {}, avatar_arguments: {}, **system_arguments, &block) ⇒ Object

Adds an avatar item to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image.

Parameters:

  • src (String)

    The source url of the avatar image.

  • username (String)

    The username associated with the avatar.

  • full_name (String) (defaults to: nil)

    Optional. The user’s full name.

  • full_name_scheme (Symbol) (defaults to: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME)

    Optional. How to display the user’s full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %>

  • data (Hash) (defaults to: {})

    When the menu is used as a form input (see the <%= link_to_component(Primer::Alpha::ActionMenu) %> docs), the label is submitted to the server by default. However, if the ‘data: { value: }` or `“data-value”:` attribute is provided, it will be sent to the server instead.

  • avatar_arguments (Hash) (defaults to: {})

    Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>.

  • system_arguments (Hash)

    These arguments are forwarded to <%= link_to_component(Primer::Alpha::ActionList::Item) %>, or whatever class is passed as the ‘component_klass` argument.



34
35
36
37
38
39
40
# File 'app/components/primer/alpha/action_menu/list.rb', line 34

def with_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, data: {}, avatar_arguments: {}, **system_arguments, &block)
  system_arguments = organize_arguments(data: data, **system_arguments)

  super(src: src, username: username, full_name: full_name, full_name_scheme: full_name_scheme, avatar_arguments: avatar_arguments, **system_arguments) do |item|
    evaluate_block(item, &block)
  end
end

#with_item(data: {}, **system_arguments, &block) ⇒ Object

Adds a new item to the list.

Parameters:

  • data (Hash) (defaults to: {})

    When the menu is used as a form input (see the <%= link_to_component(Primer::Alpha::ActionMenu) %> docs), the label is submitted to the server by default. However, if the ‘data: { value: }` or `“data-value”:` attribute is provided, it will be sent to the server instead.

  • system_arguments (Hash)

    These arguments are forwarded to <%= link_to_component(Primer::Alpha::ActionList::Item) %>, or whatever class is passed as the ‘component_klass` argument.



17
18
19
20
21
22
23
# File 'app/components/primer/alpha/action_menu/list.rb', line 17

def with_item(data: {}, **system_arguments, &block)
  system_arguments = organize_arguments(data: data, **system_arguments)

  super(**system_arguments) do |item|
    evaluate_block(item, &block)
  end
end