Skip to content

Commit

Permalink
allow action menu to auto overflow its contents
Browse files Browse the repository at this point in the history
  • Loading branch information
strackoverflow committed Nov 15, 2023
1 parent 97f0339 commit c6ec882
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/components/primer/alpha/action_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class ActionMenu < Primer::Component
# @param dynamic_label_prefix [String] If provided, the prefix is prepended to the dynamic label and displayed in the show button.
# @param select_variant [Symbol] <%= one_of(Primer::Alpha::ActionMenu::SELECT_VARIANT_OPTIONS) %>
# @param form_arguments [Hash] Allows an `ActionMenu` to act as a select list in multi- and single-select modes. Pass the `builder:` and `name:` options to this hash. `builder:` should be an instance of `ActionView::Helpers::FormBuilder`, which are created by the standard Rails `#form_with` and `#form_for` helpers. The `name:` option is the desired name of the field that will be included in the params sent to the server on form submission.
# @param overflow [Symbol] Control the overflow behavior of the menu. <%= one_of(Primer::Alpha::Overlay::OVERFLOW_OPTIONS) %>. Defaults to `<%= Primer::Alpha::Overlay::DEFAULT_OVERFLOW_STYLE %>`.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>.
def initialize(
menu_id: self.class.generate_id,
Expand All @@ -166,6 +167,7 @@ def initialize(
dynamic_label_prefix: nil,
select_variant: DEFAULT_SELECT_VARIANT,
form_arguments: {},
overflow: Primer::Alpha::Overlay::DEFAULT_OVERFLOW_STYLE,
**system_arguments
)
@menu_id = menu_id
Expand All @@ -188,7 +190,8 @@ def initialize(
visually_hide_title: true,
anchor_align: anchor_align,
anchor_side: anchor_side,
size: size
size: size,
overflow: overflow,
)

@list = Primer::Alpha::ActionMenu::List.new(
Expand Down
14 changes: 13 additions & 1 deletion app/components/primer/alpha/overlay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ class Overlay < Primer::Component

ROLE_OPTIONS = [:dialog, :menu, nil].freeze

DEFAULT_OVERFLOW_STYLE = :auto
OVERFLOW_MAPPINGS = {
DEFAULT_OVERFLOW_STYLE => "overflow-y-auto",
:scroll => "overflow-y-scroll",
:hidden => "overflow-y-hidden",
:visible => "overflow-y-visible"
}.freeze
OVERFLOW_OPTIONS = OVERFLOW_MAPPINGS.keys

# Optional button to open the Overlay.
#
# @param icon [String] Name of <%= link_to_octicons %> to use instead of text. If provided, a <%= link_to_component(Primer::Beta::IconButton) %> will be rendered. Otherwise a <%= link_to_component(Primer::Beta::Button) %> will be rendered.
Expand Down Expand Up @@ -135,6 +144,7 @@ class Overlay < Primer::Component
# @param allow_out_of_bounds [Boolean] Allow the Overlay to overflow its container.
# @param visually_hide_title [Boolean] If true will hide the heading title, while still making it available to Screen Readers.
# @param role [String] The ARIA role. <%= one_of(Primer::Alpha::Overlay::ROLE_OPTIONS) %>
# @param overflow [Symbol] Sets the overflow behavior of the Overlay wrapper. <%= one_of(Primer::Alpha::Overlay::OVERFLOW_OPTIONS) %>.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
title:,
Expand All @@ -150,6 +160,7 @@ def initialize(
allow_out_of_bounds: false,
visually_hide_title: false,
id: self.class.generate_id,
overflow: nil,
**system_arguments
)
@system_arguments = deny_tag_argument(**system_arguments)
Expand All @@ -159,7 +170,8 @@ def initialize(
@system_arguments[:id] = id.to_s
@wrapper_classes = class_names(
"Overlay",
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)]
SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE)],
OVERFLOW_MAPPINGS[fetch_or_fallback(OVERFLOW_OPTIONS, overflow, DEFAULT_OVERFLOW_STYLE)] => overflow.present?
)
@system_arguments[:tag] = "anchored-position"
@system_arguments[:anchor] = anchor || "overlay-show-#{@system_arguments[:id]}"
Expand Down

0 comments on commit c6ec882

Please sign in to comment.