openproject-primer_view_components 0.11.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +110 -0
  3. data/app/assets/javascripts/app/components/primer/alpha/tool_tip.d.ts +1 -0
  4. data/app/assets/javascripts/app/components/primer/primer.d.ts +1 -1
  5. data/app/assets/javascripts/primer_view_components.js +1 -1
  6. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  7. data/app/assets/styles/primer_view_components.css +1 -1
  8. data/app/assets/styles/primer_view_components.css.map +1 -1
  9. data/app/components/primer/alpha/action_bar/item.rb +7 -4
  10. data/app/components/primer/alpha/action_bar.rb +2 -2
  11. data/app/components/primer/alpha/action_bar_element.js +9 -4
  12. data/app/components/primer/alpha/action_bar_element.ts +9 -2
  13. data/app/components/primer/alpha/action_list/form_wrapper.html.erb +4 -2
  14. data/app/components/primer/alpha/action_list/form_wrapper.rb +20 -9
  15. data/app/components/primer/alpha/action_menu/action_menu_element.js +162 -86
  16. data/app/components/primer/alpha/action_menu/action_menu_element.ts +197 -82
  17. data/app/components/primer/alpha/action_menu/list.rb +0 -2
  18. data/app/components/primer/alpha/action_menu.rb +120 -3
  19. data/app/components/primer/alpha/check_box_group.rb +2 -0
  20. data/app/components/primer/alpha/dialog/header.rb +12 -0
  21. data/app/components/primer/alpha/dialog.rb +1 -1
  22. data/app/components/primer/alpha/modal_dialog.js +10 -13
  23. data/app/components/primer/alpha/modal_dialog.ts +10 -13
  24. data/app/components/primer/alpha/nav_list/divider.rb +2 -5
  25. data/app/components/primer/alpha/nav_list/group.rb +2 -98
  26. data/app/components/primer/alpha/nav_list/heading.rb +2 -27
  27. data/app/components/primer/alpha/nav_list/item.rb +2 -147
  28. data/app/components/primer/alpha/nav_list.rb +2 -205
  29. data/app/components/primer/alpha/overlay.css +1 -1
  30. data/app/components/primer/alpha/overlay.css.map +1 -1
  31. data/app/components/primer/alpha/overlay.pcss +1 -7
  32. data/app/components/primer/alpha/overlay.rb +6 -4
  33. data/app/components/primer/alpha/radio_button_group.rb +2 -0
  34. data/app/components/primer/alpha/segmented_control/item.html.erb +1 -8
  35. data/app/components/primer/alpha/segmented_control/item.rb +38 -4
  36. data/app/components/primer/alpha/segmented_control.css +1 -1
  37. data/app/components/primer/alpha/segmented_control.css.json +14 -13
  38. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  39. data/app/components/primer/alpha/segmented_control.pcss +75 -66
  40. data/app/components/primer/alpha/segmented_control.rb +10 -0
  41. data/app/components/primer/alpha/text_field.css +1 -1
  42. data/app/components/primer/alpha/text_field.css.json +4 -1
  43. data/app/components/primer/alpha/text_field.css.map +1 -1
  44. data/app/components/primer/alpha/text_field.pcss +18 -3
  45. data/app/components/primer/alpha/tool_tip.d.ts +1 -0
  46. data/app/components/primer/alpha/tool_tip.js +26 -93
  47. data/app/components/primer/alpha/tool_tip.ts +25 -91
  48. data/app/components/primer/alpha/tooltip.rb +3 -1
  49. data/app/components/primer/beta/base_button.rb +4 -0
  50. data/app/components/primer/beta/button.css +1 -1
  51. data/app/components/primer/beta/button.css.json +2 -0
  52. data/app/components/primer/beta/button.css.map +1 -1
  53. data/app/components/primer/beta/button.pcss +17 -5
  54. data/app/components/primer/beta/icon_button.html.erb +1 -1
  55. data/app/components/primer/beta/icon_button.rb +8 -1
  56. data/app/components/primer/beta/link.css +1 -1
  57. data/app/components/primer/beta/link.css.json +1 -0
  58. data/app/components/primer/beta/link.css.map +1 -1
  59. data/app/components/primer/beta/link.pcss +5 -0
  60. data/app/components/primer/beta/link.rb +2 -2
  61. data/app/components/primer/beta/nav_list/divider.rb +14 -0
  62. data/app/components/primer/beta/nav_list/group.rb +107 -0
  63. data/app/components/primer/beta/nav_list/heading.rb +36 -0
  64. data/app/components/primer/beta/nav_list/item.rb +156 -0
  65. data/app/components/primer/beta/nav_list.rb +212 -0
  66. data/app/components/primer/focus_group.js +30 -4
  67. data/app/components/primer/focus_group.ts +29 -2
  68. data/app/components/primer/open_project/flex_layout.html.erb +23 -0
  69. data/app/components/primer/open_project/flex_layout.rb +52 -0
  70. data/app/components/primer/open_project/grid_layout/area.rb +38 -0
  71. data/app/components/primer/open_project/grid_layout.html.erb +11 -0
  72. data/app/components/primer/open_project/grid_layout.rb +34 -0
  73. data/app/components/primer/open_project/page_header.css +1 -1
  74. data/app/components/primer/open_project/page_header.css.map +1 -1
  75. data/app/components/primer/open_project/page_header.pcss +4 -0
  76. data/app/components/primer/primer.d.ts +1 -1
  77. data/app/components/primer/primer.js +1 -1
  78. data/app/components/primer/primer.ts +1 -1
  79. data/app/helpers/primer/form_helper.rb +10 -0
  80. data/lib/primer/accessibility.rb +3 -1
  81. data/lib/primer/deprecations.yml +20 -0
  82. data/lib/primer/forms/check_box_group.html.erb +3 -0
  83. data/lib/primer/forms/dsl/check_box_group_input.rb +1 -5
  84. data/lib/primer/forms/dsl/check_box_input.rb +5 -0
  85. data/lib/primer/forms/dsl/radio_button_input.rb +5 -0
  86. data/lib/primer/forms/form_control.html.erb +1 -4
  87. data/lib/primer/forms/radio_button_group.html.erb +3 -0
  88. data/lib/primer/forms/utils.rb +2 -0
  89. data/lib/primer/forms/validation_message.html.erb +4 -0
  90. data/lib/primer/forms/validation_message.rb +14 -0
  91. data/lib/primer/forms.rb +16 -0
  92. data/lib/primer/static/generate_info_arch.rb +86 -5
  93. data/lib/primer/view_components/version.rb +1 -1
  94. data/lib/primer/yard/component_manifest.rb +4 -0
  95. data/previews/primer/alpha/action_menu_preview/single_select_form_items.html.erb +31 -0
  96. data/previews/primer/alpha/action_menu_preview/with_actions.html.erb +6 -5
  97. data/previews/primer/alpha/action_menu_preview.rb +10 -1
  98. data/previews/primer/alpha/check_box_group_preview.rb +13 -0
  99. data/previews/primer/alpha/check_box_preview.rb +1 -0
  100. data/previews/primer/alpha/dialog_preview/autofocus_element.html.erb +8 -0
  101. data/previews/primer/alpha/dialog_preview/with_header.html.erb +5 -0
  102. data/previews/primer/alpha/dialog_preview.rb +22 -0
  103. data/previews/primer/alpha/overlay_preview.rb +1 -1
  104. data/previews/primer/alpha/radio_button_group_preview.rb +13 -0
  105. data/previews/primer/alpha/radio_button_preview.rb +2 -1
  106. data/previews/primer/alpha/segmented_control_preview.rb +35 -0
  107. data/previews/primer/alpha/text_field_preview/input_group_leading_action_menu.html.erb +21 -0
  108. data/previews/primer/alpha/text_field_preview/input_group_leading_button.html.erb +18 -0
  109. data/previews/primer/alpha/text_field_preview/input_group_trailing_button.html.erb +18 -0
  110. data/previews/primer/alpha/text_field_preview.rb +21 -0
  111. data/previews/primer/alpha/tooltip_preview/tooltip_with_dialog_moving_focus_to_input.html.erb +23 -0
  112. data/previews/primer/alpha/tooltip_preview.rb +6 -1
  113. data/previews/primer/beta/button_group_preview.rb +6 -6
  114. data/previews/primer/beta/button_preview.rb +21 -3
  115. data/previews/primer/beta/icon_button_preview.rb +3 -0
  116. data/previews/primer/{alpha → beta}/nav_list_preview/trailing_action.html.erb +1 -1
  117. data/previews/primer/{alpha → beta}/nav_list_preview.rb +5 -5
  118. data/previews/primer/open_project/flex_layout_preview.rb +73 -0
  119. data/previews/primer/open_project/grid_layout_preview.rb +37 -0
  120. data/static/arguments.json +278 -7
  121. data/static/audited_at.json +8 -0
  122. data/static/classes.json +15 -0
  123. data/static/constants.json +47 -1
  124. data/static/info_arch.json +1338 -632
  125. data/static/previews.json +271 -167
  126. data/static/statuses.json +13 -5
  127. metadata +33 -319
  128. /data/app/assets/javascripts/app/components/primer/{alpha → beta}/nav_list.d.ts +0 -0
  129. /data/app/components/primer/{alpha → beta}/nav_list/group.html.erb +0 -0
  130. /data/app/components/primer/{alpha → beta}/nav_list/item.html.erb +0 -0
  131. /data/app/components/primer/{alpha → beta}/nav_list.d.ts +0 -0
  132. /data/app/components/primer/{alpha → beta}/nav_list.html.erb +0 -0
  133. /data/app/components/primer/{alpha → beta}/nav_list.js +0 -0
  134. /data/app/components/primer/{alpha → beta}/nav_list.ts +0 -0
@@ -7,14 +7,17 @@ module Primer
7
7
  class ActionBar
8
8
  # ActionBar::Item is an internal component that wraps the items in a div with the `ActionBar-item` class.
9
9
  class Item < Primer::Component
10
- def initialize(item_content)
10
+ # @param item_content [String] The content to render inside the item.
11
+ # @param item_arguments [Hash] <%= link_to_system_arguments_docs %>
12
+ def initialize(item_content, **item_arguments)
11
13
  @system_arguments = {
12
- tag: :div,
14
+ tag: item_arguments[:tag] || :div,
13
15
  data: {
14
16
  targets: "action-bar.items"
15
- },
16
- classes: "ActionBar-item"
17
+ }.merge(item_arguments[:data] || {}),
18
+ classes: class_names("ActionBar-item", item_arguments[:classes])
17
19
  }
20
+
18
21
  @item_content = item_content
19
22
  end
20
23
 
@@ -16,14 +16,14 @@ module Primer
16
16
  SIZE_OPTIONS = SIZE_MAPPINGS.keys.freeze
17
17
 
18
18
  renders_many :items, types: {
19
- icon_button: lambda { |icon:, label:, **system_arguments|
19
+ icon_button: lambda { |icon:, label:, item_arguments: {}, **system_arguments|
20
20
  item_id = self.class.generate_id
21
21
 
22
22
  with_menu_item(id: item_id, label: label) do |c|
23
23
  c.with_leading_visual_icon(icon: icon)
24
24
  end
25
25
 
26
- Item.new(Primer::Beta::IconButton.new(id: item_id, icon: icon, "aria-label": label, size: @size, scheme: :invisible, **system_arguments))
26
+ Item.new(Primer::Beta::IconButton.new(id: item_id, icon: icon, "aria-label": label, size: @size, scheme: :invisible, **system_arguments), **item_arguments)
27
27
  },
28
28
  divider: lambda {
29
29
  @action_menu.with_divider(hidden: true) if @overflow_menu
@@ -15,7 +15,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
16
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
17
  };
18
- var _ActionBarElement_instances, _ActionBarElement_initialBarWidth, _ActionBarElement_previousBarWidth, _ActionBarElement_focusZoneAbortController, _ActionBarElement_itemGap, _ActionBarElement_availableSpace, _ActionBarElement_menuSpace, _ActionBarElement_shrink, _ActionBarElement_grow, _ActionBarElement_showItem, _ActionBarElement_hideItem, _ActionBarElement_menuItems_get;
18
+ var _ActionBarElement_instances, _ActionBarElement_initialBarWidth, _ActionBarElement_previousBarWidth, _ActionBarElement_focusZoneAbortController, _ActionBarElement_isVisible, _ActionBarElement_itemGap, _ActionBarElement_availableSpace, _ActionBarElement_menuSpace, _ActionBarElement_shrink, _ActionBarElement_grow, _ActionBarElement_showItem, _ActionBarElement_hideItem, _ActionBarElement_menuItems_get;
19
19
  import { controller, targets, target } from '@github/catalyst';
20
20
  import { focusZone, FocusKeys } from '@primer/behaviors';
21
21
  const instersectionObserver = new IntersectionObserver(entries => {
@@ -90,16 +90,21 @@ let ActionBarElement = class ActionBarElement extends HTMLElement {
90
90
  if (__classPrivateFieldGet(this, _ActionBarElement_focusZoneAbortController, "f")) {
91
91
  __classPrivateFieldGet(this, _ActionBarElement_focusZoneAbortController, "f").abort();
92
92
  }
93
- __classPrivateFieldSet(this, _ActionBarElement_focusZoneAbortController, focusZone(this.itemContainer, {
93
+ __classPrivateFieldSet(this, _ActionBarElement_focusZoneAbortController, focusZone(this, {
94
94
  bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
95
95
  focusOutBehavior: 'wrap',
96
96
  focusableElementFilter: element => {
97
- return !element.closest('.ActionBar-item[hidden]');
97
+ return __classPrivateFieldGet(this, _ActionBarElement_instances, "m", _ActionBarElement_isVisible).call(this, element);
98
98
  }
99
99
  }), "f");
100
100
  }
101
101
  };
102
- _ActionBarElement_initialBarWidth = new WeakMap(), _ActionBarElement_previousBarWidth = new WeakMap(), _ActionBarElement_focusZoneAbortController = new WeakMap(), _ActionBarElement_instances = new WeakSet(), _ActionBarElement_itemGap = function _ActionBarElement_itemGap() {
102
+ _ActionBarElement_initialBarWidth = new WeakMap(), _ActionBarElement_previousBarWidth = new WeakMap(), _ActionBarElement_focusZoneAbortController = new WeakMap(), _ActionBarElement_instances = new WeakSet(), _ActionBarElement_isVisible = function _ActionBarElement_isVisible(element) {
103
+ // Safari doesn't support `checkVisibility` yet.
104
+ if (typeof element.checkVisibility === 'function')
105
+ return element.checkVisibility();
106
+ return Boolean(element.offsetParent || element.offsetWidth || element.offsetHeight);
107
+ }, _ActionBarElement_itemGap = function _ActionBarElement_itemGap() {
103
108
  var _a;
104
109
  return parseInt((_a = window.getComputedStyle(this.itemContainer)) === null || _a === void 0 ? void 0 : _a.columnGap, 10) || 0;
105
110
  }, _ActionBarElement_availableSpace = function _ActionBarElement_availableSpace() {
@@ -82,15 +82,22 @@ class ActionBarElement extends HTMLElement {
82
82
  if (this.#focusZoneAbortController) {
83
83
  this.#focusZoneAbortController.abort()
84
84
  }
85
- this.#focusZoneAbortController = focusZone(this.itemContainer, {
85
+ this.#focusZoneAbortController = focusZone(this, {
86
86
  bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
87
87
  focusOutBehavior: 'wrap',
88
88
  focusableElementFilter: element => {
89
- return !element.closest('.ActionBar-item[hidden]')
89
+ return this.#isVisible(element)
90
90
  }
91
91
  })
92
92
  }
93
93
 
94
+ #isVisible(element: HTMLElement): boolean {
95
+ // Safari doesn't support `checkVisibility` yet.
96
+ if (typeof element.checkVisibility === 'function') return element.checkVisibility()
97
+
98
+ return Boolean(element.offsetParent || element.offsetWidth || element.offsetHeight)
99
+ }
100
+
94
101
  #itemGap(): number {
95
102
  return parseInt(window.getComputedStyle(this.itemContainer)?.columnGap, 10) || 0
96
103
  }
@@ -1,7 +1,9 @@
1
1
  <% if form_required? %>
2
2
  <%= form_with(url: @action, method: @http_method, **@form_arguments) do %>
3
- <% if render_input? %>
4
- <%= render(Primer::BaseComponent.new(tag: :input, **@input_arguments)) %>
3
+ <% if render_inputs? %>
4
+ <% @inputs.each do |input_arguments| %>
5
+ <%= render(Primer::BaseComponent.new(tag: :input, **input_arguments)) %>
6
+ <% end %>
5
7
  <% end %>
6
8
  <%= content %>
7
9
  <% end %>
@@ -24,14 +24,25 @@ module Primer
24
24
 
25
25
  name = @form_arguments.delete(:name)
26
26
  value = @form_arguments.delete(:value) || name
27
+ inputs = @form_arguments.delete(:inputs) || []
27
28
 
28
- @input_arguments = {
29
- type: :hidden,
30
- name: name,
31
- value: value,
32
- data: { list_item_input: true },
33
- **(@form_arguments.delete(:input_arguments) || {})
34
- }
29
+ # For the older version of this component that only allowed you to
30
+ # specify a single input
31
+ if inputs.empty?
32
+ inputs << {
33
+ name: name,
34
+ value: value,
35
+ **(@form_arguments.delete(:input_arguments) || {})
36
+ }
37
+ end
38
+
39
+ @inputs = inputs.map do |input_data|
40
+ input_data = input_data.dup
41
+ input_data[:type] ||= :hidden
42
+ input_data[:data] ||= {}
43
+ input_data[:data][:list_item_input] = true
44
+ input_data
45
+ end
35
46
  end
36
47
 
37
48
  def get?
@@ -42,8 +53,8 @@ module Primer
42
53
  @action && !get?
43
54
  end
44
55
 
45
- def render_input?
46
- @input_arguments[:name].present?
56
+ def render_inputs?
57
+ @inputs.present?
47
58
  end
48
59
 
49
60
  private
@@ -15,10 +15,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
16
16
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
17
17
  };
18
- var _ActionMenuElement_instances, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_inputName, _ActionMenuElement_setDynamicLabel, _ActionMenuElement_updateInput, _ActionMenuElement_isActivationKeydown, _ActionMenuElement_firstItem_get;
18
+ var _ActionMenuElement_instances, _ActionMenuElement_abortController, _ActionMenuElement_originalLabel, _ActionMenuElement_inputName, _ActionMenuElement_invokerBeingClicked, _ActionMenuElement_softDisableItems, _ActionMenuElement_potentiallyDisallowActivation, _ActionMenuElement_isKeyboardActivation, _ActionMenuElement_isMouseActivation, _ActionMenuElement_isActivation, _ActionMenuElement_handleInvokerActivated, _ActionMenuElement_handleDialogItemActivated, _ActionMenuElement_handleItemActivated, _ActionMenuElement_activateItem, _ActionMenuElement_handleIncludeFragmentReplaced, _ActionMenuElement_handleFocusOut, _ActionMenuElement_show, _ActionMenuElement_hide, _ActionMenuElement_isOpen, _ActionMenuElement_setDynamicLabel, _ActionMenuElement_updateInput, _ActionMenuElement_firstItem_get, _ActionMenuElement_items_get;
19
19
  import { controller, target } from '@github/catalyst';
20
20
  import '@oddbird/popover-polyfill';
21
- const menuItemSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'];
21
+ const validSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'];
22
+ const menuItemSelectors = validSelectors.map(selector => `:not([hidden]) > ${selector}`);
22
23
  let ActionMenuElement = class ActionMenuElement extends HTMLElement {
23
24
  constructor() {
24
25
  super(...arguments);
@@ -26,6 +27,7 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
26
27
  _ActionMenuElement_abortController.set(this, void 0);
27
28
  _ActionMenuElement_originalLabel.set(this, '');
28
29
  _ActionMenuElement_inputName.set(this, '');
30
+ _ActionMenuElement_invokerBeingClicked.set(this, false);
29
31
  }
30
32
  get selectVariant() {
31
33
  return this.getAttribute('data-select-variant');
@@ -93,8 +95,10 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
93
95
  this.addEventListener('click', this, { signal });
94
96
  this.addEventListener('mouseover', this, { signal });
95
97
  this.addEventListener('focusout', this, { signal });
98
+ this.addEventListener('mousedown', this, { signal });
96
99
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
97
100
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
101
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
98
102
  if (this.includeFragment) {
99
103
  this.includeFragment.addEventListener('include-fragment-replaced', this, {
100
104
  signal
@@ -105,98 +109,173 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
105
109
  __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f").abort();
106
110
  }
107
111
  handleEvent(event) {
108
- var _a, _b, _c, _d, _e;
109
- const activation = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivationKeydown).call(this, event);
110
- if (event.target === this.invokerElement && activation) {
111
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) {
112
- event.preventDefault();
113
- (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
114
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
115
- return;
116
- }
117
- }
118
- // Ignore events within dialogs within menus
119
- if (((_b = event.target) === null || _b === void 0 ? void 0 : _b.closest('dialog')) || ((_c = event.target) === null || _c === void 0 ? void 0 : _c.closest('modal-dialog'))) {
112
+ var _a;
113
+ const targetIsInvoker = (_a = this.invokerElement) === null || _a === void 0 ? void 0 : _a.contains(event.target);
114
+ const eventIsActivation = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivation).call(this, event);
115
+ if (targetIsInvoker && event.type === 'mousedown') {
116
+ __classPrivateFieldSet(this, _ActionMenuElement_invokerBeingClicked, true, "f");
120
117
  return;
121
118
  }
122
- // If a dialog has been rendered within the menu, we do not want to hide
123
- // the entire menu, as that will also hide the Dialog. Instead we want to
124
- // show the Dialog while hiding just the visible part of the menu.
125
- if ((activation || event.type === 'click') && ((_d = event.target) === null || _d === void 0 ? void 0 : _d.closest('[data-show-dialog-id]'))) {
126
- const dialogInvoker = event.target.closest('[data-show-dialog-id]');
127
- const dialog = this.ownerDocument.getElementById((dialogInvoker === null || dialogInvoker === void 0 ? void 0 : dialogInvoker.getAttribute('data-show-dialog-id')) || '');
128
- if (dialogInvoker && dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
129
- this.querySelector('.ActionListWrap').style.display = 'none';
130
- const dialog_controller = new AbortController();
131
- const { signal } = dialog_controller;
132
- const handleDialogClose = () => {
133
- var _a, _b;
134
- dialog_controller.abort();
135
- this.querySelector('.ActionListWrap').style.display = '';
136
- if ((_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open')) {
137
- (_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.hidePopover();
138
- }
139
- };
140
- dialog.addEventListener('close', handleDialogClose, { signal });
141
- dialog.addEventListener('cancel', handleDialogClose, { signal });
142
- return;
143
- }
119
+ // Prevent safari bug that dismisses menu on mousedown instead of allowing
120
+ // the click event to propagate to the button
121
+ if (event.type === 'mousedown') {
122
+ event.preventDefault();
123
+ return;
144
124
  }
145
- if (!((_e = this.popoverElement) === null || _e === void 0 ? void 0 : _e.matches(':popover-open')))
125
+ if (targetIsInvoker && eventIsActivation) {
126
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleInvokerActivated).call(this, event);
127
+ __classPrivateFieldSet(this, _ActionMenuElement_invokerBeingClicked, false, "f");
146
128
  return;
147
- if (event.type === 'include-fragment-replaced') {
148
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get))
149
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
150
129
  }
151
- else if (activation || (event instanceof MouseEvent && event.type === 'click')) {
152
- // Hide popover after current event loop to prevent changes in focus from
153
- // altering the target of the event. Not doing this specifically affects
154
- // <a> tags. It causes the event to be sent to the currently focused element
155
- // instead of the anchor, which effectively prevents navigation, i.e. it
156
- // appears as if hitting enter does nothing. Curiously, clicking instead
157
- // works fine.
158
- if (this.selectVariant !== 'multiple') {
159
- setTimeout(() => {
160
- var _a, _b;
161
- if ((_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open')) {
162
- (_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.hidePopover();
163
- }
164
- });
165
- }
166
- // The rest of the code below deals with single/multiple selection behavior, and should not
167
- // interfere with events fired by menu items whose behavior is specified outside the library.
168
- if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
130
+ if (event.type === 'focusout') {
131
+ if (__classPrivateFieldGet(this, _ActionMenuElement_invokerBeingClicked, "f"))
169
132
  return;
170
- const item = event.target.closest(menuItemSelectors.join(','));
171
- if (!item)
172
- return;
173
- const ariaChecked = item.getAttribute('aria-checked');
174
- const checked = ariaChecked !== 'true';
175
- if (this.selectVariant === 'single') {
176
- // Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
177
- if (checked) {
178
- item.setAttribute('aria-checked', 'true');
133
+ // Give the browser time to focus the next element
134
+ requestAnimationFrame(() => {
135
+ if (!this.contains(document.activeElement) || document.activeElement === this.invokerElement) {
136
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleFocusOut).call(this);
179
137
  }
180
- for (const checkedItem of this.querySelectorAll('[aria-checked]')) {
181
- if (checkedItem !== item) {
182
- checkedItem.setAttribute('aria-checked', 'false');
183
- }
138
+ });
139
+ return;
140
+ }
141
+ const item = event.target.closest(menuItemSelectors.join(','));
142
+ const targetIsItem = item !== null;
143
+ if (targetIsItem && eventIsActivation) {
144
+ const dialogInvoker = item.closest('[data-show-dialog-id]');
145
+ if (dialogInvoker) {
146
+ const dialog = this.ownerDocument.getElementById(dialogInvoker.getAttribute('data-show-dialog-id') || '');
147
+ if (dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
148
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleDialogItemActivated).call(this, event, dialog);
149
+ return;
184
150
  }
185
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
186
151
  }
187
- else {
188
- // multi-select mode allows unchecking a checked item
189
- item.setAttribute('aria-checked', `${checked}`);
152
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_activateItem).call(this, event, item);
153
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleItemActivated).call(this, event, item);
154
+ return;
155
+ }
156
+ if (event.type === 'include-fragment-replaced') {
157
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleIncludeFragmentReplaced).call(this);
158
+ }
159
+ }
160
+ };
161
+ _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalLabel = new WeakMap(), _ActionMenuElement_inputName = new WeakMap(), _ActionMenuElement_invokerBeingClicked = new WeakMap(), _ActionMenuElement_instances = new WeakSet(), _ActionMenuElement_softDisableItems = function _ActionMenuElement_softDisableItems() {
162
+ const { signal } = __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f");
163
+ for (const item of __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_items_get)) {
164
+ item.addEventListener('click', __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_potentiallyDisallowActivation).bind(this), { signal });
165
+ item.addEventListener('keydown', __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_potentiallyDisallowActivation).bind(this), { signal });
166
+ }
167
+ }, _ActionMenuElement_potentiallyDisallowActivation = function _ActionMenuElement_potentiallyDisallowActivation(event) {
168
+ if (!__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivation).call(this, event))
169
+ return;
170
+ const item = event.target.closest(menuItemSelectors.join(','));
171
+ if (!item)
172
+ return;
173
+ if (item.getAttribute('aria-disabled')) {
174
+ event.preventDefault();
175
+ event.stopPropagation();
176
+ event.stopImmediatePropagation();
177
+ }
178
+ }, _ActionMenuElement_isKeyboardActivation = function _ActionMenuElement_isKeyboardActivation(event) {
179
+ return (event instanceof KeyboardEvent &&
180
+ event.type === 'keydown' &&
181
+ !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
182
+ (event.key === 'Enter' || event.key === ' '));
183
+ }, _ActionMenuElement_isMouseActivation = function _ActionMenuElement_isMouseActivation(event) {
184
+ return event instanceof MouseEvent && event.type === 'click';
185
+ }, _ActionMenuElement_isActivation = function _ActionMenuElement_isActivation(event) {
186
+ return __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isMouseActivation).call(this, event) || __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isKeyboardActivation).call(this, event);
187
+ }, _ActionMenuElement_handleInvokerActivated = function _ActionMenuElement_handleInvokerActivated(event) {
188
+ var _a;
189
+ event.preventDefault();
190
+ event.stopPropagation();
191
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
192
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
193
+ }
194
+ else {
195
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_show).call(this);
196
+ (_a = __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) === null || _a === void 0 ? void 0 : _a.focus();
197
+ }
198
+ }, _ActionMenuElement_handleDialogItemActivated = function _ActionMenuElement_handleDialogItemActivated(event, dialog) {
199
+ this.querySelector('.ActionListWrap').style.display = 'none';
200
+ const dialog_controller = new AbortController();
201
+ const { signal } = dialog_controller;
202
+ const handleDialogClose = () => {
203
+ dialog_controller.abort();
204
+ this.querySelector('.ActionListWrap').style.display = '';
205
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
206
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
207
+ }
208
+ };
209
+ dialog.addEventListener('close', handleDialogClose, { signal });
210
+ dialog.addEventListener('cancel', handleDialogClose, { signal });
211
+ }, _ActionMenuElement_handleItemActivated = function _ActionMenuElement_handleItemActivated(event, item) {
212
+ // Hide popover after current event loop to prevent changes in focus from
213
+ // altering the target of the event. Not doing this specifically affects
214
+ // <a> tags. It causes the event to be sent to the currently focused element
215
+ // instead of the anchor, which effectively prevents navigation, i.e. it
216
+ // appears as if hitting enter does nothing. Curiously, clicking instead
217
+ // works fine.
218
+ if (this.selectVariant !== 'multiple') {
219
+ setTimeout(() => {
220
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
221
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
190
222
  }
191
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
192
- if (event instanceof KeyboardEvent && event.target instanceof HTMLButtonElement) {
193
- // prevent buttons from being clicked twice
194
- event.preventDefault();
223
+ });
224
+ }
225
+ // The rest of the code below deals with single/multiple selection behavior, and should not
226
+ // interfere with events fired by menu items whose behavior is specified outside the library.
227
+ if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
228
+ return;
229
+ const ariaChecked = item.getAttribute('aria-checked');
230
+ const checked = ariaChecked !== 'true';
231
+ if (this.selectVariant === 'single') {
232
+ // Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
233
+ if (checked) {
234
+ item.setAttribute('aria-checked', 'true');
235
+ }
236
+ for (const checkedItem of this.querySelectorAll('[aria-checked]')) {
237
+ if (checkedItem !== item) {
238
+ checkedItem.setAttribute('aria-checked', 'false');
195
239
  }
196
240
  }
241
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
197
242
  }
198
- };
199
- _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalLabel = new WeakMap(), _ActionMenuElement_inputName = new WeakMap(), _ActionMenuElement_instances = new WeakSet(), _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
243
+ else {
244
+ // multi-select mode allows unchecking a checked item
245
+ item.setAttribute('aria-checked', `${checked}`);
246
+ }
247
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
248
+ }, _ActionMenuElement_activateItem = function _ActionMenuElement_activateItem(event, item) {
249
+ const eventWillActivateByDefault = (event instanceof MouseEvent && event.type === 'click') ||
250
+ (event instanceof KeyboardEvent &&
251
+ event.type === 'keydown' &&
252
+ !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
253
+ event.key === 'Enter');
254
+ // if the event will result in activating the current item by default, i.e. is a
255
+ // mouse click or keyboard enter, bail out
256
+ if (eventWillActivateByDefault)
257
+ return;
258
+ // otherwise, event will not result in activation by default, so we stop it and
259
+ // simulate a click
260
+ event.stopPropagation();
261
+ const elem = item;
262
+ elem.click();
263
+ }, _ActionMenuElement_handleIncludeFragmentReplaced = function _ActionMenuElement_handleIncludeFragmentReplaced() {
264
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get))
265
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
266
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
267
+ }, _ActionMenuElement_handleFocusOut = function _ActionMenuElement_handleFocusOut() {
268
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
269
+ }, _ActionMenuElement_show = function _ActionMenuElement_show() {
270
+ var _a;
271
+ (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
272
+ }, _ActionMenuElement_hide = function _ActionMenuElement_hide() {
273
+ var _a;
274
+ (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.hidePopover();
275
+ }, _ActionMenuElement_isOpen = function _ActionMenuElement_isOpen() {
276
+ var _a;
277
+ return (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open');
278
+ }, _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
200
279
  if (!this.dynamicLabel)
201
280
  return;
202
281
  const invokerLabel = this.invokerLabel;
@@ -251,13 +330,10 @@ _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalL
251
330
  input.remove();
252
331
  }
253
332
  }
254
- }, _ActionMenuElement_isActivationKeydown = function _ActionMenuElement_isActivationKeydown(event) {
255
- return (event instanceof KeyboardEvent &&
256
- event.type === 'keydown' &&
257
- !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
258
- (event.key === 'Enter' || event.key === ' '));
259
333
  }, _ActionMenuElement_firstItem_get = function _ActionMenuElement_firstItem_get() {
260
334
  return this.querySelector(menuItemSelectors.join(','));
335
+ }, _ActionMenuElement_items_get = function _ActionMenuElement_items_get() {
336
+ return Array.from(this.querySelectorAll(menuItemSelectors.join(',')));
261
337
  };
262
338
  __decorate([
263
339
  target