openproject-primer_view_components 0.12.1 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/app/assets/javascripts/app/components/primer/alpha/tool_tip.d.ts +1 -0
  4. data/app/assets/javascripts/primer_view_components.js +1 -1
  5. data/app/assets/javascripts/primer_view_components.js.map +1 -1
  6. data/app/assets/styles/primer_view_components.css +1 -1
  7. data/app/assets/styles/primer_view_components.css.map +1 -1
  8. data/app/components/primer/alpha/action_bar/item.rb +7 -4
  9. data/app/components/primer/alpha/action_bar.rb +2 -2
  10. data/app/components/primer/alpha/action_bar_element.js +11 -4
  11. data/app/components/primer/alpha/action_bar_element.ts +11 -2
  12. data/app/components/primer/alpha/action_list/form_wrapper.html.erb +4 -2
  13. data/app/components/primer/alpha/action_list/form_wrapper.rb +20 -9
  14. data/app/components/primer/alpha/action_menu/action_menu_element.js +174 -84
  15. data/app/components/primer/alpha/action_menu/action_menu_element.ts +218 -81
  16. data/app/components/primer/alpha/action_menu/list.rb +0 -2
  17. data/app/components/primer/alpha/action_menu.rb +120 -3
  18. data/app/components/primer/alpha/modal_dialog.js +10 -13
  19. data/app/components/primer/alpha/modal_dialog.ts +10 -13
  20. data/app/components/primer/alpha/segmented_control/item.html.erb +1 -8
  21. data/app/components/primer/alpha/segmented_control/item.rb +38 -4
  22. data/app/components/primer/alpha/segmented_control.css +1 -1
  23. data/app/components/primer/alpha/segmented_control.css.json +14 -13
  24. data/app/components/primer/alpha/segmented_control.css.map +1 -1
  25. data/app/components/primer/alpha/segmented_control.pcss +75 -66
  26. data/app/components/primer/alpha/segmented_control.rb +10 -0
  27. data/app/components/primer/alpha/text_field.css +1 -1
  28. data/app/components/primer/alpha/tool_tip.d.ts +1 -0
  29. data/app/components/primer/alpha/tool_tip.js +34 -28
  30. data/app/components/primer/alpha/tool_tip.ts +33 -26
  31. data/app/components/primer/beta/base_button.rb +4 -0
  32. data/app/components/primer/beta/button.css +1 -1
  33. data/app/components/primer/beta/button.css.map +1 -1
  34. data/app/components/primer/beta/button.pcss +6 -2
  35. data/app/components/primer/focus_group.js +28 -3
  36. data/app/components/primer/focus_group.ts +27 -1
  37. data/lib/primer/static/generate_info_arch.rb +86 -5
  38. data/lib/primer/view_components/version.rb +1 -1
  39. data/previews/primer/alpha/action_menu_preview/single_select_form_items.html.erb +31 -0
  40. data/previews/primer/alpha/action_menu_preview/with_actions.html.erb +6 -5
  41. data/previews/primer/alpha/action_menu_preview.rb +10 -1
  42. data/previews/primer/alpha/check_box_preview.rb +0 -2
  43. data/previews/primer/alpha/dialog_preview/autofocus_element.html.erb +8 -0
  44. data/previews/primer/alpha/dialog_preview/with_text_input.html.erb +2 -1
  45. data/previews/primer/alpha/dialog_preview.rb +5 -0
  46. data/previews/primer/alpha/radio_button_preview.rb +0 -2
  47. data/previews/primer/alpha/segmented_control_preview.rb +35 -0
  48. data/previews/primer/alpha/tooltip_preview/tooltip_with_dialog_moving_focus_to_input.html.erb +23 -0
  49. data/previews/primer/alpha/tooltip_preview.rb +6 -1
  50. data/previews/primer/beta/button_group_preview.rb +6 -6
  51. data/previews/primer/beta/button_preview.rb +20 -2
  52. data/previews/primer/beta/icon_button_preview.rb +3 -0
  53. data/static/arguments.json +18 -1
  54. data/static/classes.json +12 -0
  55. data/static/constants.json +12 -1
  56. data/static/info_arch.json +135 -5
  57. data/static/previews.json +91 -0
  58. metadata +5 -310
@@ -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,23 @@ 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
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts-ignore
106
+ if (typeof element.checkVisibility === 'function')
107
+ return element.checkVisibility();
108
+ return Boolean(element.offsetParent || element.offsetWidth || element.offsetHeight);
109
+ }, _ActionBarElement_itemGap = function _ActionBarElement_itemGap() {
103
110
  var _a;
104
111
  return parseInt((_a = window.getComputedStyle(this.itemContainer)) === null || _a === void 0 ? void 0 : _a.columnGap, 10) || 0;
105
112
  }, _ActionBarElement_availableSpace = function _ActionBarElement_availableSpace() {
@@ -82,15 +82,24 @@ 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
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
97
+ // @ts-ignore
98
+ if (typeof element.checkVisibility === 'function') return element.checkVisibility()
99
+
100
+ return Boolean(element.offsetParent || element.offsetWidth || element.offsetHeight)
101
+ }
102
+
94
103
  #itemGap(): number {
95
104
  return parseInt(window.getComputedStyle(this.itemContainer)?.columnGap, 10) || 0
96
105
  }
@@ -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,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 _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_isKeyboardActivationViaEnter, _ActionMenuElement_isKeyboardActivationViaSpace, _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
21
  const validSelectors = ['[role="menuitem"]', '[role="menuitemcheckbox"]', '[role="menuitemradio"]'];
@@ -27,6 +27,7 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
27
27
  _ActionMenuElement_abortController.set(this, void 0);
28
28
  _ActionMenuElement_originalLabel.set(this, '');
29
29
  _ActionMenuElement_inputName.set(this, '');
30
+ _ActionMenuElement_invokerBeingClicked.set(this, false);
30
31
  }
31
32
  get selectVariant() {
32
33
  return this.getAttribute('data-select-variant');
@@ -94,8 +95,10 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
94
95
  this.addEventListener('click', this, { signal });
95
96
  this.addEventListener('mouseover', this, { signal });
96
97
  this.addEventListener('focusout', this, { signal });
98
+ this.addEventListener('mousedown', this, { signal });
97
99
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
98
100
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
101
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
99
102
  if (this.includeFragment) {
100
103
  this.includeFragment.addEventListener('include-fragment-replaced', this, {
101
104
  signal
@@ -106,98 +109,188 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
106
109
  __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f").abort();
107
110
  }
108
111
  handleEvent(event) {
109
- var _a, _b, _c, _d, _e;
110
- const activation = __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivationKeydown).call(this, event);
111
- if (event.target === this.invokerElement && activation) {
112
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) {
113
- event.preventDefault();
114
- (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
115
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
116
- return;
117
- }
118
- }
119
- // Ignore events within dialogs within menus
120
- 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, _b;
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");
121
117
  return;
122
118
  }
123
- // If a dialog has been rendered within the menu, we do not want to hide
124
- // the entire menu, as that will also hide the Dialog. Instead we want to
125
- // show the Dialog while hiding just the visible part of the menu.
126
- if ((activation || event.type === 'click') && ((_d = event.target) === null || _d === void 0 ? void 0 : _d.closest('[data-show-dialog-id]'))) {
127
- const dialogInvoker = event.target.closest('[data-show-dialog-id]');
128
- const dialog = this.ownerDocument.getElementById((dialogInvoker === null || dialogInvoker === void 0 ? void 0 : dialogInvoker.getAttribute('data-show-dialog-id')) || '');
129
- if (dialogInvoker && dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
130
- this.querySelector('.ActionListWrap').style.display = 'none';
131
- const dialog_controller = new AbortController();
132
- const { signal } = dialog_controller;
133
- const handleDialogClose = () => {
134
- var _a, _b;
135
- dialog_controller.abort();
136
- this.querySelector('.ActionListWrap').style.display = '';
137
- if ((_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open')) {
138
- (_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.hidePopover();
139
- }
140
- };
141
- dialog.addEventListener('close', handleDialogClose, { signal });
142
- dialog.addEventListener('cancel', handleDialogClose, { signal });
143
- return;
144
- }
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;
145
124
  }
146
- 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");
147
128
  return;
148
- if (event.type === 'include-fragment-replaced') {
149
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get))
150
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
151
129
  }
152
- else if (activation || (event instanceof MouseEvent && event.type === 'click')) {
153
- // Hide popover after current event loop to prevent changes in focus from
154
- // altering the target of the event. Not doing this specifically affects
155
- // <a> tags. It causes the event to be sent to the currently focused element
156
- // instead of the anchor, which effectively prevents navigation, i.e. it
157
- // appears as if hitting enter does nothing. Curiously, clicking instead
158
- // works fine.
159
- if (this.selectVariant !== 'multiple') {
160
- setTimeout(() => {
161
- var _a, _b;
162
- if ((_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open')) {
163
- (_b = this.popoverElement) === null || _b === void 0 ? void 0 : _b.hidePopover();
164
- }
165
- });
166
- }
167
- // The rest of the code below deals with single/multiple selection behavior, and should not
168
- // interfere with events fired by menu items whose behavior is specified outside the library.
169
- if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
130
+ if (event.type === 'focusout') {
131
+ if (__classPrivateFieldGet(this, _ActionMenuElement_invokerBeingClicked, "f"))
170
132
  return;
171
- const item = event.target.closest(menuItemSelectors.join(','));
172
- if (!item)
173
- return;
174
- const ariaChecked = item.getAttribute('aria-checked');
175
- const checked = ariaChecked !== 'true';
176
- if (this.selectVariant === 'single') {
177
- // Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
178
- if (checked) {
179
- 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);
180
137
  }
181
- for (const checkedItem of this.querySelectorAll('[aria-checked]')) {
182
- if (checkedItem !== item) {
183
- checkedItem.setAttribute('aria-checked', 'false');
184
- }
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;
185
150
  }
186
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
187
- }
188
- else {
189
- // multi-select mode allows unchecking a checked item
190
- item.setAttribute('aria-checked', `${checked}`);
191
151
  }
192
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
193
- if (event instanceof KeyboardEvent && event.target instanceof HTMLButtonElement) {
194
- // prevent buttons from being clicked twice
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
+ // Pressing the space key on a button will cause the page to scroll unless preventDefault()
155
+ // is called. Unfortunately, calling preventDefault() will also skip form submission. The
156
+ // code below therefore only calls preventDefault() if the button submits a form and the
157
+ // button is being activated by the space key.
158
+ if (item.getAttribute('type') === 'submit' && __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isKeyboardActivationViaSpace).call(this, event)) {
195
159
  event.preventDefault();
160
+ (_b = item.closest('form')) === null || _b === void 0 ? void 0 : _b.submit();
196
161
  }
162
+ return;
163
+ }
164
+ if (event.type === 'include-fragment-replaced') {
165
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleIncludeFragmentReplaced).call(this);
197
166
  }
198
167
  }
199
168
  };
200
- _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalLabel = new WeakMap(), _ActionMenuElement_inputName = new WeakMap(), _ActionMenuElement_instances = new WeakSet(), _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
169
+ _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() {
170
+ const { signal } = __classPrivateFieldGet(this, _ActionMenuElement_abortController, "f");
171
+ for (const item of __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_items_get)) {
172
+ item.addEventListener('click', __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_potentiallyDisallowActivation).bind(this), { signal });
173
+ item.addEventListener('keydown', __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_potentiallyDisallowActivation).bind(this), { signal });
174
+ }
175
+ }, _ActionMenuElement_potentiallyDisallowActivation = function _ActionMenuElement_potentiallyDisallowActivation(event) {
176
+ if (!__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isActivation).call(this, event))
177
+ return;
178
+ const item = event.target.closest(menuItemSelectors.join(','));
179
+ if (!item)
180
+ return;
181
+ if (item.getAttribute('aria-disabled')) {
182
+ event.preventDefault();
183
+ event.stopPropagation();
184
+ event.stopImmediatePropagation();
185
+ }
186
+ }, _ActionMenuElement_isKeyboardActivation = function _ActionMenuElement_isKeyboardActivation(event) {
187
+ return __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isKeyboardActivationViaEnter).call(this, event) || __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isKeyboardActivationViaSpace).call(this, event);
188
+ }, _ActionMenuElement_isKeyboardActivationViaEnter = function _ActionMenuElement_isKeyboardActivationViaEnter(event) {
189
+ return (event instanceof KeyboardEvent &&
190
+ event.type === 'keydown' &&
191
+ !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
192
+ event.key === 'Enter');
193
+ }, _ActionMenuElement_isKeyboardActivationViaSpace = function _ActionMenuElement_isKeyboardActivationViaSpace(event) {
194
+ return (event instanceof KeyboardEvent &&
195
+ event.type === 'keydown' &&
196
+ !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
197
+ event.key === ' ');
198
+ }, _ActionMenuElement_isMouseActivation = function _ActionMenuElement_isMouseActivation(event) {
199
+ return event instanceof MouseEvent && event.type === 'click';
200
+ }, _ActionMenuElement_isActivation = function _ActionMenuElement_isActivation(event) {
201
+ return __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isMouseActivation).call(this, event) || __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isKeyboardActivation).call(this, event);
202
+ }, _ActionMenuElement_handleInvokerActivated = function _ActionMenuElement_handleInvokerActivated(event) {
203
+ var _a;
204
+ event.preventDefault();
205
+ event.stopPropagation();
206
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
207
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
208
+ }
209
+ else {
210
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_show).call(this);
211
+ (_a = __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get)) === null || _a === void 0 ? void 0 : _a.focus();
212
+ }
213
+ }, _ActionMenuElement_handleDialogItemActivated = function _ActionMenuElement_handleDialogItemActivated(event, dialog) {
214
+ this.querySelector('.ActionListWrap').style.display = 'none';
215
+ const dialog_controller = new AbortController();
216
+ const { signal } = dialog_controller;
217
+ const handleDialogClose = () => {
218
+ dialog_controller.abort();
219
+ this.querySelector('.ActionListWrap').style.display = '';
220
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
221
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
222
+ }
223
+ };
224
+ dialog.addEventListener('close', handleDialogClose, { signal });
225
+ dialog.addEventListener('cancel', handleDialogClose, { signal });
226
+ }, _ActionMenuElement_handleItemActivated = function _ActionMenuElement_handleItemActivated(event, item) {
227
+ // Hide popover after current event loop to prevent changes in focus from
228
+ // altering the target of the event. Not doing this specifically affects
229
+ // <a> tags. It causes the event to be sent to the currently focused element
230
+ // instead of the anchor, which effectively prevents navigation, i.e. it
231
+ // appears as if hitting enter does nothing. Curiously, clicking instead
232
+ // works fine.
233
+ if (this.selectVariant !== 'multiple') {
234
+ setTimeout(() => {
235
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
236
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
237
+ }
238
+ });
239
+ }
240
+ // The rest of the code below deals with single/multiple selection behavior, and should not
241
+ // interfere with events fired by menu items whose behavior is specified outside the library.
242
+ if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
243
+ return;
244
+ const ariaChecked = item.getAttribute('aria-checked');
245
+ const checked = ariaChecked !== 'true';
246
+ if (this.selectVariant === 'single') {
247
+ // Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
248
+ if (checked) {
249
+ item.setAttribute('aria-checked', 'true');
250
+ }
251
+ for (const checkedItem of this.querySelectorAll('[aria-checked]')) {
252
+ if (checkedItem !== item) {
253
+ checkedItem.setAttribute('aria-checked', 'false');
254
+ }
255
+ }
256
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_setDynamicLabel).call(this);
257
+ }
258
+ else {
259
+ // multi-select mode allows unchecking a checked item
260
+ item.setAttribute('aria-checked', `${checked}`);
261
+ }
262
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_updateInput).call(this);
263
+ }, _ActionMenuElement_activateItem = function _ActionMenuElement_activateItem(event, item) {
264
+ const eventWillActivateByDefault = (event instanceof MouseEvent && event.type === 'click') ||
265
+ (event instanceof KeyboardEvent &&
266
+ event.type === 'keydown' &&
267
+ !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
268
+ event.key === 'Enter');
269
+ // if the event will result in activating the current item by default, i.e. is a
270
+ // mouse click or keyboard enter, bail out
271
+ if (eventWillActivateByDefault)
272
+ return;
273
+ // otherwise, event will not result in activation by default, so we stop it and
274
+ // simulate a click
275
+ event.stopPropagation();
276
+ const elem = item;
277
+ elem.click();
278
+ }, _ActionMenuElement_handleIncludeFragmentReplaced = function _ActionMenuElement_handleIncludeFragmentReplaced() {
279
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get))
280
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "a", _ActionMenuElement_firstItem_get).focus();
281
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_softDisableItems).call(this);
282
+ }, _ActionMenuElement_handleFocusOut = function _ActionMenuElement_handleFocusOut() {
283
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
284
+ }, _ActionMenuElement_show = function _ActionMenuElement_show() {
285
+ var _a;
286
+ (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.showPopover();
287
+ }, _ActionMenuElement_hide = function _ActionMenuElement_hide() {
288
+ var _a;
289
+ (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.hidePopover();
290
+ }, _ActionMenuElement_isOpen = function _ActionMenuElement_isOpen() {
291
+ var _a;
292
+ return (_a = this.popoverElement) === null || _a === void 0 ? void 0 : _a.matches(':popover-open');
293
+ }, _ActionMenuElement_setDynamicLabel = function _ActionMenuElement_setDynamicLabel() {
201
294
  if (!this.dynamicLabel)
202
295
  return;
203
296
  const invokerLabel = this.invokerLabel;
@@ -252,13 +345,10 @@ _ActionMenuElement_abortController = new WeakMap(), _ActionMenuElement_originalL
252
345
  input.remove();
253
346
  }
254
347
  }
255
- }, _ActionMenuElement_isActivationKeydown = function _ActionMenuElement_isActivationKeydown(event) {
256
- return (event instanceof KeyboardEvent &&
257
- event.type === 'keydown' &&
258
- !(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
259
- (event.key === 'Enter' || event.key === ' '));
260
348
  }, _ActionMenuElement_firstItem_get = function _ActionMenuElement_firstItem_get() {
261
349
  return this.querySelector(menuItemSelectors.join(','));
350
+ }, _ActionMenuElement_items_get = function _ActionMenuElement_items_get() {
351
+ return Array.from(this.querySelectorAll(menuItemSelectors.join(',')));
262
352
  };
263
353
  __decorate([
264
354
  target