Class: Primer::Alpha::ActionMenu
- Defined in:
- app/components/primer/alpha/action_menu.rb,
app/components/primer/alpha/action_menu/list.rb
Overview
ActionMenu is used for actions, navigation, to display secondary options, or single/multi select lists. They appear when users interact with buttons, actions, or other controls.
The only allowed elements for the Item components are: :a, :button, and :clipboard-copy. The default is :button.
Defined Under Namespace
Classes: List
Constant Summary collapse
- DEFAULT_PRELOAD =
false- DEFAULT_SELECT_VARIANT =
:none- SELECT_VARIANT_OPTIONS =
[ :single, :multiple, DEFAULT_SELECT_VARIANT ].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
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 collapse
-
#list ⇒ Object
readonly
Returns the value of attribute list.
-
#preload ⇒ Object
(also: #preload?)
readonly
Returns the value of attribute preload.
Instance Method Summary collapse
-
#initialize(menu_id: self.class.generate_id, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE, size: Primer::Alpha::Overlay::DEFAULT_SIZE, src: nil, preload: DEFAULT_PRELOAD, dynamic_label: false, dynamic_label_prefix: nil, select_variant: DEFAULT_SELECT_VARIANT, form_arguments: {}, **system_arguments) ⇒ ActionMenu
constructor
A new instance of ActionMenu.
-
#with_divider(**system_arguments, &block) ⇒ Object
Adds a divider to the list.
-
#with_item(**system_arguments, &block) ⇒ Object
Adds a new item to the list.
-
#with_show_button(**system_arguments, &block) ⇒ Object
Button to activate the menu.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Constructor Details
#initialize(menu_id: self.class.generate_id, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE, size: Primer::Alpha::Overlay::DEFAULT_SIZE, src: nil, preload: DEFAULT_PRELOAD, dynamic_label: false, dynamic_label_prefix: nil, select_variant: DEFAULT_SELECT_VARIANT, form_arguments: {}, **system_arguments) ⇒ ActionMenu
Returns a new instance of ActionMenu.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'app/components/primer/alpha/action_menu.rb', line 310 def initialize( menu_id: self.class.generate_id, anchor_align: Primer::Alpha::Overlay::DEFAULT_ANCHOR_ALIGN, anchor_side: Primer::Alpha::Overlay::DEFAULT_ANCHOR_SIDE, size: Primer::Alpha::Overlay::DEFAULT_SIZE, src: nil, preload: DEFAULT_PRELOAD, dynamic_label: false, dynamic_label_prefix: nil, select_variant: DEFAULT_SELECT_VARIANT, form_arguments: {}, **system_arguments ) = @src = src @preload = fetch_or_fallback_boolean(preload, DEFAULT_PRELOAD) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:preload] = true if @src.present? && preload? select_variant = fetch_or_fallback(SELECT_VARIANT_OPTIONS, select_variant, DEFAULT_SELECT_VARIANT) @system_arguments[:tag] = :"action-menu" @system_arguments[:"data-select-variant"] = select_variant @system_arguments[:"data-dynamic-label"] = "" if dynamic_label @system_arguments[:"data-dynamic-label-prefix"] = dynamic_label_prefix if dynamic_label_prefix.present? = Primer::Alpha::Overlay.new( id: "#{@menu_id}-overlay", title: "Menu", visually_hide_title: true, anchor_align: anchor_align, anchor_side: anchor_side, size: size ) @list = Primer::Alpha::ActionMenu::List.new( menu_id: , select_variant: select_variant, form_arguments: form_arguments ) end |
Instance Attribute Details
#list ⇒ Object (readonly)
Returns the value of attribute list.
26 27 28 |
# File 'app/components/primer/alpha/action_menu.rb', line 26 def list @list end |
#preload ⇒ Object (readonly) Also known as: preload?
Returns the value of attribute preload.
26 27 28 |
# File 'app/components/primer/alpha/action_menu.rb', line 26 def preload @preload end |
Instance Method Details
#with_divider(**system_arguments, &block) ⇒ Object
Adds a divider to the list.
382 383 384 |
# File 'app/components/primer/alpha/action_menu.rb', line 382 def with_divider(**system_arguments, &block) @list.with_divider(**system_arguments, &block) end |
#with_item(**system_arguments, &block) ⇒ Object
Adds a new item to the list.
375 376 377 |
# File 'app/components/primer/alpha/action_menu.rb', line 375 def with_item(**system_arguments, &block) @list.with_item(**system_arguments, &block) end |
#with_show_button(**system_arguments, &block) ⇒ Object
Button to activate the menu.
362 363 364 |
# File 'app/components/primer/alpha/action_menu.rb', line 362 def (**system_arguments, &block) .(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list", &block) end |