openproject-primer_view_components 0.57.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/components/primer/alpha/select_panel.html.erb +5 -0
- data/app/components/primer/alpha/select_panel.rb +23 -24
- data/app/components/primer/alpha/select_panel_element.js +6 -4
- data/app/components/primer/alpha/select_panel_element.ts +8 -4
- data/lib/primer/view_components/version.rb +1 -1
- data/previews/primer/alpha/select_panel_preview/remote_fetch_form.html.erb +34 -0
- data/previews/primer/alpha/select_panel_preview.rb +9 -0
- data/static/arguments.json +2 -80
- data/static/info_arch.json +16 -81
- data/static/previews.json +13 -0
- metadata +3 -2
@@ -1,4 +1,9 @@
|
|
1
1
|
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
|
2
|
+
<% if required_form_arguments_given? %>
|
3
|
+
<span data-select-panel-inputs="true">
|
4
|
+
<%= @form_builder.hidden_field(@input_name, multiple: multi_select?, skip_default_ids: true, value: @value) %>
|
5
|
+
</span>
|
6
|
+
<% end %>
|
2
7
|
<dialog-helper>
|
3
8
|
<%= show_button %>
|
4
9
|
<%= render(@dialog) do %>
|
@@ -152,27 +152,6 @@ module Primer
|
|
152
152
|
# end
|
153
153
|
# end
|
154
154
|
# ```
|
155
|
-
#
|
156
|
-
# If items are provided dynamically, things become a bit more complicated. The `form_for` or `form_with` method call
|
157
|
-
# happens in the view that renders the `SelectPanel`, which means the form builder object but isn't available in the
|
158
|
-
# view that renders the list items. In such a case, it can be useful to create an instance of the form builder maually:
|
159
|
-
#
|
160
|
-
# ```erb
|
161
|
-
# <% builder = ActionView::Helpers::FormBuilder.new(
|
162
|
-
# "address", # the name of the model, used to wrap input names, eg 'address[country]'
|
163
|
-
# nil, # object (eg. the Address instance, which we can omit)
|
164
|
-
# self, # template
|
165
|
-
# {} # options
|
166
|
-
# ) %>
|
167
|
-
# <%= render(Primer::Alpha::SelectPanel::ItemList.new(
|
168
|
-
# form_arguments: { builder: builder, name: "country" }
|
169
|
-
# )) do |list| %>
|
170
|
-
# <% countries.each do |country| %>
|
171
|
-
# <% menu.with_item(label: country.name, content_arguments: { data: { value: country.code } }) %>
|
172
|
-
# <% end %>
|
173
|
-
# <% end %>
|
174
|
-
# ```
|
175
|
-
#
|
176
155
|
# ### JavaScript API
|
177
156
|
#
|
178
157
|
# `SelectPanel`s render a `<select-panel>` custom element that exposes behavior to the client.
|
@@ -375,7 +354,9 @@ module Primer
|
|
375
354
|
# @param dynamic_aria_label_prefix [String] If provided, the prefix is prepended to the dynamic label and set as the value of the `aria-label` attribute on the show button.
|
376
355
|
# @param body_id [String] The unique ID of the panel body. If not provided, the body ID will be set to the panel ID with a "-body" suffix.
|
377
356
|
# @param list_arguments [Hash] Arguments to pass to the underlying <%= link_to_component(Primer::Alpha::ActionList) %> component. Only has an effect for the local fetch strategy.
|
378
|
-
# @param form_arguments [Hash] Form arguments
|
357
|
+
# @param form_arguments [Hash] Form arguments
|
358
|
+
|
359
|
+
# @param use_experimental_non_local_form [Boolean] A feature flag used to slowly roll out moving the input field (generated from form arguments) to the top of the SelectPanel HTML thus allowing remote fetching to have default form values.
|
379
360
|
# @param show_filter [Boolean] Whether or not to show the filter input.
|
380
361
|
# @param open_on_load [Boolean] Open the panel when the page loads.
|
381
362
|
# @param anchor_align [Symbol] The anchor alignment of the Overlay. <%= one_of(Primer::Alpha::Overlay::ANCHOR_ALIGN_OPTIONS) %>
|
@@ -397,6 +378,7 @@ module Primer
|
|
397
378
|
dynamic_label_prefix: nil,
|
398
379
|
dynamic_aria_label_prefix: nil,
|
399
380
|
body_id: nil,
|
381
|
+
use_experimental_non_local_form: false,
|
400
382
|
list_arguments: {},
|
401
383
|
form_arguments: {},
|
402
384
|
show_filter: true,
|
@@ -429,6 +411,15 @@ module Primer
|
|
429
411
|
@dynamic_aria_label_prefix = dynamic_aria_label_prefix
|
430
412
|
@loading_label = loading_label
|
431
413
|
@loading_description_id = nil
|
414
|
+
|
415
|
+
if use_experimental_non_local_form
|
416
|
+
@form_builder = form_arguments[:builder]
|
417
|
+
@value = form_arguments[:value]
|
418
|
+
@input_name = form_arguments[:name]
|
419
|
+
end
|
420
|
+
|
421
|
+
@list_form_arguments = use_experimental_non_local_form ? {} : form_arguments
|
422
|
+
|
432
423
|
if loading_description.present?
|
433
424
|
@loading_description_id = "#{@panel_id}-loading-description"
|
434
425
|
end
|
@@ -471,7 +462,7 @@ module Primer
|
|
471
462
|
|
472
463
|
@list = Primer::Alpha::SelectPanel::ItemList.new(
|
473
464
|
**list_arguments,
|
474
|
-
form_arguments:
|
465
|
+
form_arguments: @list_form_arguments,
|
475
466
|
id: "#{@panel_id}-list",
|
476
467
|
select_variant: @select_variant,
|
477
468
|
aria: {
|
@@ -546,6 +537,14 @@ module Primer
|
|
546
537
|
def before_render
|
547
538
|
content
|
548
539
|
end
|
540
|
+
|
541
|
+
def required_form_arguments_given?
|
542
|
+
@input_name && @form_builder
|
543
|
+
end
|
544
|
+
|
545
|
+
def multi_select?
|
546
|
+
select_variant == :multiple
|
547
|
+
end
|
549
548
|
end
|
550
549
|
end
|
551
|
-
end
|
550
|
+
end
|
@@ -893,7 +893,8 @@ _SelectPanelElement_setDynamicLabel = function _SelectPanelElement_setDynamicLab
|
|
893
893
|
};
|
894
894
|
_SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
895
895
|
if (this.selectVariant === 'single') {
|
896
|
-
const input = this.querySelector(`[data-
|
896
|
+
const input = this.querySelector(`[data-select-panel-inputs=true] input`) ??
|
897
|
+
this.querySelector(`[data-list-inputs=true] input`);
|
897
898
|
if (!input)
|
898
899
|
return;
|
899
900
|
const selectedItem = this.selectedItems[0];
|
@@ -903,13 +904,14 @@ _SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
|
903
904
|
input.name = selectedItem.inputName;
|
904
905
|
input.removeAttribute('disabled');
|
905
906
|
}
|
906
|
-
else {
|
907
|
+
else if (__classPrivateFieldGet(this, _SelectPanelElement_hasLoadedData, "f")) {
|
907
908
|
input.setAttribute('disabled', 'disabled');
|
908
909
|
}
|
909
910
|
}
|
910
911
|
else if (this.selectVariant !== 'none') {
|
911
912
|
// multiple select variant
|
912
|
-
const
|
913
|
+
const isRemoteInput = !!this.querySelector('[data-select-panel-inputs=true]');
|
914
|
+
const inputList = this.querySelector('[data-select-panel-inputs=true]') ?? this.querySelector('[data-list-inputs=true]');
|
913
915
|
if (!inputList)
|
914
916
|
return;
|
915
917
|
const inputs = inputList.querySelectorAll('input');
|
@@ -918,7 +920,7 @@ _SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
|
918
920
|
}
|
919
921
|
for (const selectedItem of this.selectedItems) {
|
920
922
|
const newInput = document.createElement('input');
|
921
|
-
newInput.setAttribute('data-list-input'
|
923
|
+
newInput.setAttribute(`${isRemoteInput ? 'data-select-panel-input' : 'data-list-input'}`, 'true');
|
922
924
|
newInput.type = 'hidden';
|
923
925
|
newInput.autocomplete = 'off';
|
924
926
|
newInput.name = selectedItem.inputName || __classPrivateFieldGet(this, _SelectPanelElement_inputName, "f");
|
@@ -959,7 +959,9 @@ export class SelectPanelElement extends HTMLElement {
|
|
959
959
|
|
960
960
|
#updateInput() {
|
961
961
|
if (this.selectVariant === 'single') {
|
962
|
-
const input =
|
962
|
+
const input =
|
963
|
+
(this.querySelector(`[data-select-panel-inputs=true] input`) as HTMLInputElement) ??
|
964
|
+
(this.querySelector(`[data-list-inputs=true] input`) as HTMLInputElement)
|
963
965
|
if (!input) return
|
964
966
|
|
965
967
|
const selectedItem = this.selectedItems[0]
|
@@ -968,12 +970,14 @@ export class SelectPanelElement extends HTMLElement {
|
|
968
970
|
input.value = (selectedItem.value || selectedItem.label || '').trim()
|
969
971
|
if (selectedItem.inputName) input.name = selectedItem.inputName
|
970
972
|
input.removeAttribute('disabled')
|
971
|
-
} else {
|
973
|
+
} else if (this.#hasLoadedData) {
|
972
974
|
input.setAttribute('disabled', 'disabled')
|
973
975
|
}
|
974
976
|
} else if (this.selectVariant !== 'none') {
|
975
977
|
// multiple select variant
|
976
|
-
const
|
978
|
+
const isRemoteInput = !!this.querySelector('[data-select-panel-inputs=true]')
|
979
|
+
const inputList =
|
980
|
+
this.querySelector('[data-select-panel-inputs=true]') ?? this.querySelector('[data-list-inputs=true]')
|
977
981
|
if (!inputList) return
|
978
982
|
|
979
983
|
const inputs = inputList.querySelectorAll('input')
|
@@ -984,7 +988,7 @@ export class SelectPanelElement extends HTMLElement {
|
|
984
988
|
|
985
989
|
for (const selectedItem of this.selectedItems) {
|
986
990
|
const newInput = document.createElement('input')
|
987
|
-
newInput.setAttribute('data-list-input'
|
991
|
+
newInput.setAttribute(`${isRemoteInput ? 'data-select-panel-input' : 'data-list-input'}`, 'true')
|
988
992
|
newInput.type = 'hidden'
|
989
993
|
newInput.autocomplete = 'off'
|
990
994
|
newInput.name = selectedItem.inputName || this.#inputName
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<% subject_id = SecureRandom.hex %>
|
2
|
+
|
3
|
+
<%= form_with(url: generic_form_submission_path(format: route_format)) do |builder| %>
|
4
|
+
<%= render(Primer::Alpha::SelectPanel.new(
|
5
|
+
data: { interaction_subject: subject_id },
|
6
|
+
select_variant: :single,
|
7
|
+
src: select_panel_items_path(
|
8
|
+
select_variant: :single,
|
9
|
+
selected_items: selected_items,
|
10
|
+
),
|
11
|
+
open_on_load: open_on_load,
|
12
|
+
dynamic_label: true,
|
13
|
+
dynamic_label_prefix: "Item",
|
14
|
+
use_experimental_non_local_form: true,
|
15
|
+
form_arguments: {
|
16
|
+
name: :item,
|
17
|
+
builder: builder,
|
18
|
+
value: 3,
|
19
|
+
}
|
20
|
+
)) do |panel| %>
|
21
|
+
<% panel.with_show_button { "Sci-fi equipment" } %>
|
22
|
+
<% panel.with_footer(show_divider: true) do %>
|
23
|
+
I'm a footer!
|
24
|
+
<% end %>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<hr>
|
28
|
+
|
29
|
+
<%= render(Primer::Beta::Button.new(type: :submit, scheme: :primary)) do %>
|
30
|
+
Submit
|
31
|
+
<% end %>
|
32
|
+
<% end %>
|
33
|
+
|
34
|
+
<%= render partial: "primer/alpha/select_panel_preview/interaction_subject_js", locals: { subject_id: subject_id } %>
|
@@ -259,6 +259,15 @@ module Primer
|
|
259
259
|
render_with_template(locals: { open_on_load: open_on_load, route_format: route_format })
|
260
260
|
end
|
261
261
|
|
262
|
+
# @label Remote fetch form
|
263
|
+
#
|
264
|
+
# @snapshot interactive
|
265
|
+
# @param open_on_load toggle
|
266
|
+
# @param selected_items text
|
267
|
+
def remote_fetch_form(open_on_load: false, selected_items: "Phaser", route_format: :html)
|
268
|
+
render_with_template(locals: { open_on_load: open_on_load, selected_items: selected_items, route_format: route_format })
|
269
|
+
end
|
270
|
+
|
262
271
|
# @label Multi-select form
|
263
272
|
#
|
264
273
|
# @snapshot interactive
|
data/static/arguments.json
CHANGED
@@ -2345,88 +2345,10 @@
|
|
2345
2345
|
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/alpha/select_panel/default/",
|
2346
2346
|
"parameters": [
|
2347
2347
|
{
|
2348
|
-
"name": "
|
2349
|
-
"type": "String",
|
2350
|
-
"default": "`nil`",
|
2351
|
-
"description": "The URL to fetch search results from."
|
2352
|
-
},
|
2353
|
-
{
|
2354
|
-
"name": "title",
|
2355
|
-
"type": "String",
|
2356
|
-
"default": "`\"Menu\"`",
|
2357
|
-
"description": "The title that appears at the top of the panel."
|
2358
|
-
},
|
2359
|
-
{
|
2360
|
-
"name": "id",
|
2361
|
-
"type": "String",
|
2362
|
-
"default": "`self.class.generate_id`",
|
2363
|
-
"description": "The unique ID of the panel."
|
2364
|
-
},
|
2365
|
-
{
|
2366
|
-
"name": "size",
|
2367
|
-
"type": "Symbol",
|
2368
|
-
"default": "`:small`",
|
2369
|
-
"description": "The size of the panel. One of `:auto`, `:large`, `:medium`, `:medium_portrait`, `:small`, or `:xlarge`."
|
2370
|
-
},
|
2371
|
-
{
|
2372
|
-
"name": "select_variant",
|
2373
|
-
"type": "Symbol",
|
2374
|
-
"default": "`:single`",
|
2375
|
-
"description": "One of `:multiple`, `:none`, or `:single`."
|
2376
|
-
},
|
2377
|
-
{
|
2378
|
-
"name": "fetch_strategy",
|
2379
|
-
"type": "Symbol",
|
2380
|
-
"default": "`:remote`",
|
2381
|
-
"description": "One of `:eventually_local`, `:local`, or `:remote`."
|
2382
|
-
},
|
2383
|
-
{
|
2384
|
-
"name": "no_results_label",
|
2385
|
-
"type": "String",
|
2386
|
-
"default": "`\"No results found\"`",
|
2387
|
-
"description": "The label to display when no results are found."
|
2388
|
-
},
|
2389
|
-
{
|
2390
|
-
"name": "preload",
|
2391
|
-
"type": "Boolean",
|
2392
|
-
"default": "`false`",
|
2393
|
-
"description": "Whether to preload search results when the page loads. If this option is false, results are loaded when the panel is opened."
|
2394
|
-
},
|
2395
|
-
{
|
2396
|
-
"name": "dynamic_label",
|
2348
|
+
"name": "use_experimental_non_local_form",
|
2397
2349
|
"type": "Boolean",
|
2398
2350
|
"default": "`false`",
|
2399
|
-
"description": "
|
2400
|
-
},
|
2401
|
-
{
|
2402
|
-
"name": "dynamic_label_prefix",
|
2403
|
-
"type": "String",
|
2404
|
-
"default": "`nil`",
|
2405
|
-
"description": "If provided, the prefix is prepended to the dynamic label and displayed in the show button."
|
2406
|
-
},
|
2407
|
-
{
|
2408
|
-
"name": "dynamic_aria_label_prefix",
|
2409
|
-
"type": "String",
|
2410
|
-
"default": "`nil`",
|
2411
|
-
"description": "If provided, the prefix is prepended to the dynamic label and set as the value of the `aria-label` attribute on the show button."
|
2412
|
-
},
|
2413
|
-
{
|
2414
|
-
"name": "body_id",
|
2415
|
-
"type": "String",
|
2416
|
-
"default": "`nil`",
|
2417
|
-
"description": "The unique ID of the panel body. If not provided, the body ID will be set to the panel ID with a \"-body\" suffix."
|
2418
|
-
},
|
2419
|
-
{
|
2420
|
-
"name": "list_arguments",
|
2421
|
-
"type": "Hash",
|
2422
|
-
"default": "`{}`",
|
2423
|
-
"description": "Arguments to pass to the underlying [ActionList](/components/alpha/actionlist) component. Only has an effect for the local fetch strategy."
|
2424
|
-
},
|
2425
|
-
{
|
2426
|
-
"name": "form_arguments",
|
2427
|
-
"type": "Hash",
|
2428
|
-
"default": "`{}`",
|
2429
|
-
"description": "Form arguments to pass to the underlying [ActionList](/components/alpha/actionlist) component. Only has an effect for the local fetch strategy."
|
2351
|
+
"description": "A feature flag used to slowly roll out moving the input field (generated from form arguments) to the top of the SelectPanel HTML thus allowing remote fetching to have default form values."
|
2430
2352
|
},
|
2431
2353
|
{
|
2432
2354
|
"name": "show_filter",
|
data/static/info_arch.json
CHANGED
@@ -7438,7 +7438,7 @@
|
|
7438
7438
|
},
|
7439
7439
|
{
|
7440
7440
|
"fully_qualified_name": "Primer::Alpha::SelectPanel",
|
7441
|
-
"description": "Select panels allow for selecting from a large number of options and can be thought of as a more capable\nversion of the traditional HTML `<select>` element.\n\nSelect panels:\n\n1. feature an input field at the top that allows an end user to filter the list of results.\n1. can render their items statically or dynamically by fetching results from the server.\n1. allow selecting a single item or multiple items.\n1. permit leading visuals like Octicons, avatars, and custom SVGs.\n1. can be used as form inputs in Rails forms.\n\n## Static list items\n\nThe Rails `SelectPanel` component allows items to be provided statically or loaded dynamically from the\nserver. Providing items statically is done using a fetch strategy of `:local` in combination with the\n`item` slot:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel.new(fetch_strategy: :local))) do |panel| %>\n <% panel.with_show_button { \"Select item\" } %>\n <% panel.with_item(label: \"Item 1\") %>\n <% panel.with_item(label: \"Item 2\") %>\n<% end %>\n```\n\n## Dynamic list items\n\nList items can also be fetched dynamically from the server and will require creating a Rails controller action\nto respond with the list of items in addition to rendering the `SelectPanel` instance. Render the instance as\nnormal, providing your desired [fetch strategy](#fetch-strategies):\n\n```erb\n<%= render(\n Primer::Alpha::SelectPanel.new(\n fetch_strategy: :remote,\n src: search_items_path # perhaps a Rails URL helper\n )\n) %>\n```\n\nDefine a controller action to serve the list of items. The `SelectPanel` component passes any filter text in\nthe `q=` URL parameter.\n\n```ruby\nclass SearchItemsController < ApplicationController\n def show\n # NOTE: params[:q] may be nil since there is no filter string available\n # when the panel is first opened\n @results = SomeModel.search(params[:q] || \"\")\n end\nend\n```\n\nResponses must be HTML fragments, eg. have a content type of `text/html+fragment`. This content type isn't\navailable by default in Rails, so you may have to register it eg. in an initializer:\n\n```ruby\nMime::Type.register(\"text/fragment+html\", :html_fragment)\n```\n\nRender a `Primer::Alpha::SelectPanel::ItemList` in the action's template, search_items/show.html_fragment.erb:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel::ItemList.new) do |list| %>\n <% @results.each do |result| %>\n <% list.with_item(label: result.title) do |item| %>\n <% item.with_description(result.description) %>\n <% end %>\n <% end %>\n<% end %>\n```\n\n### Selection consistency\n\nThe `SelectPanel` component automatically \"remembers\" which items have been selected across item fetch requests,\nmeaning the controller that renders dynamic list items does not (and should not) remember these selections or\npersist them until the user has confirmed them, either by submitting the form or otherwise indicating completion.\nThe `SelectPanel` component does not include unconfirmed selection data in requests.\n\n## Fetch strategies\n\nThe list of items can be fetched from a remote URL, or provided as a static list, configured using the\n`fetch_strategy` attribute. Fetch strategies are summarized below.\n\n1. `:remote`: a query is made to the URL in the `src` attribute every time the input field changes.\n\n2. `:eventually_local`: a query is made to the URL in the `src` attribute when the panel is first opened. The\n results are \"remembered\" and filtered in-memory for all subsequent filter operations, i.e. when the input\n field changes.\n\n3. `:local`: the list of items is provided statically ahead of time and filtered in-memory. No requests are made\n to the server.\n\n## Customizing filter behavior\n\nIf the fetch strategy is `:remote`, then filtering is handled server-side. The server should render a\n`Primer::Alpha::SelectPanel::ItemList` (an alias of {{#link_to_component}}Primer::Alpha::ActionList{{/link_to_component}})\nin the response containing the filtered list of items. The component achieves remote fetching via the\n[remote-input-element](https://github.com/github/remote-input-element), which sends a request to the\nserver with the filter string in the `q=` parameter. Responses must be HTML fragments, eg. have a content\ntype of `text/html+fragment`.\n\n### Local filtering\n\nIf the fetch strategy is `:local` or `:eventually_local`, filtering is performed client-side. Filter behavior can\nbe customized in JavaScript by setting the `filterFn` attribute on the instance of `SelectPanelElement`, eg:\n\n```javascript\ndocument.querySelector(\"select-panel\").filterFn = (item: HTMLElement, query: string): boolean => {\n // return true if the item should be displayed, false otherwise\n}\n```\n\nThe element's default filter function uses the value of the `data-filter-string` attribute, falling back to the\nelement's `innerText` property. It performs a case-insensitive substring match against the filter string.\n\n### `SelectPanel`s as form inputs\n\n`SelectPanel`s can be used as form inputs. They behave very similarly to how HTML `<select>` boxes behave, and\nplay nicely with Rails' built-in form mechanisms. Pass arguments via the `form_arguments:` argument, including\nthe Rails form builder object and the name of the field. Each list item must also have a value specified in\n`content_arguments: { data: { value: } }`.\n\n```erb\n<% form_with(model: Address.new) do |f| %>\n <%= render(Primer::Alpha::SelectPanel.new(form_arguments: { builder: f, name: \"country\" })) do |menu| %>\n <% countries.each do |country|\n <% menu.with_item(label: country.name, content_arguments: { data: { value: country.code } }) %>\n <% end %>\n <% end %>\n<% end %>\n```\n\nThe value of the `data: { value: ... }` argument is sent to the server on submit, keyed using the name provided above\n(eg. `\"country\"`). If no value is provided for an item, the value of that item is the item's label. Here's the\ncorresponding `AddressesController` that might be written to handle the form above:\n\n```ruby\nclass AddressesController < ApplicationController\n def create\n puts \"You chose #{address_params[:country]} as your country\"\n end\n\n private\n\n def address_params\n params.require(:address).permit(:country)\n end\nend\n```\n\nIf items are provided dynamically, things become a bit more complicated. The `form_for` or `form_with` method call\nhappens in the view that renders the `SelectPanel`, which means the form builder object but isn't available in the\nview that renders the list items. In such a case, it can be useful to create an instance of the form builder maually:\n\n```erb\n<% builder = ActionView::Helpers::FormBuilder.new(\n \"address\", # the name of the model, used to wrap input names, eg 'address[country]'\n nil, # object (eg. the Address instance, which we can omit)\n self, # template\n {} # options\n) %>\n<%= render(Primer::Alpha::SelectPanel::ItemList.new(\n form_arguments: { builder: builder, name: \"country\" }\n)) do |list| %>\n <% countries.each do |country| %>\n <% menu.with_item(label: country.name, content_arguments: { data: { value: country.code } }) %>\n <% end %>\n<% end %>\n```\n\n### JavaScript API\n\n`SelectPanel`s render a `<select-panel>` custom element that exposes behavior to the client.\n\n#### Utility methods\n\n* `show()`: Manually open the panel. Under normal circumstances, a show button is used to show the panel, but this method exists to support unusual use-cases.\n* `hide()`: Manually hides (closes) the panel.\n\n#### Query methods\n\n* `getItemById(itemId: string): Element`: Returns the item's HTML `<li>` element. The return value can be passed as the `item` argument to the other methods listed below.\n* `isItemChecked(item: Element): boolean`: Returns `true` if the item is checked, `false` otherwise.\n* `isItemHidden(item: Element): boolean`: Returns `true` if the item is hidden, `false` otherwise.\n* `isItemDisabled(item: Element): boolean`: Returns `true` if the item is disabled, `false` otherwise.\n\nNOTE: Item IDs are special values provided by the user that are attached to `SelectPanel` list items as the `data-item-id`\nHTML attribute. Item IDs can be provided by passing an `item_id:` attribute when adding items to the panel, eg:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel.new) do |panel| %>\n <% panel.with_item(item_id: \"my-id\") %>\n<% end %>\n```\n\nThe same is true when rendering `ItemList`s:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel::ItemList.new) do |list| %>\n <% list.with_item(item_id: \"my-id\") %>\n<% end %>\n```\n\n#### State methods\n\n* `enableItem(item: Element)`: Enables the item, i.e. makes it clickable by the mouse and keyboard.\n* `disableItem(item: Element)`: Disables the item, i.e. makes it unclickable by the mouse and keyboard.\n* `checkItem(item: Element)`: Checks the item. Only has an effect in single- and multi-select modes.\n* `uncheckItem(item: Element)`: Unchecks the item. Only has an effect in multi-select mode, since items cannot be unchecked in single-select mode.\n\n#### Events\n\n|Name |Type |Bubbles |Cancelable |\n|:--------------------|:------------------------------------------|:-------|:----------|\n|`itemActivated` |`CustomEvent<ItemActivatedEvent>` |Yes |No |\n|`beforeItemActivated`|`CustomEvent<ItemActivatedEvent>` |Yes |Yes |\n|`dialog:open` |`CustomEvent<{dialog: HTMLDialogElement}>` |No |No |\n|`panelClosed` |`CustomEvent<{panel: SelectPanelElement}>` |Yes |No |\n\n_Item activation_\n\nThe `<select-panel>` element fires an `itemActivated` event whenever an item is activated (eg. clicked) via the mouse or keyboard.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"itemActivated\",\n (event: CustomEvent<ItemActivatedEvent>) => {\n event.detail.item // Element: the <li> item that was activated\n event.detail.checked // boolean: whether or not the result of the activation checked the item\n }\n)\n```\n\nThe `beforeItemActivated` event fires before an item is activated. Canceling this event will prevent the item\nfrom being activated.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"beforeItemActivated\",\n (event: CustomEvent<ItemActivatedEvent>) => {\n event.detail.item // Element: the <li> item that was activated\n event.detail.checked // boolean: whether or not the result of the activation checked the item\n event.preventDefault() // Cancel the event to prevent activation (eg. checking/unchecking)\n }\n)\n```",
|
7441
|
+
"description": "Select panels allow for selecting from a large number of options and can be thought of as a more capable\nversion of the traditional HTML `<select>` element.\n\nSelect panels:\n\n1. feature an input field at the top that allows an end user to filter the list of results.\n1. can render their items statically or dynamically by fetching results from the server.\n1. allow selecting a single item or multiple items.\n1. permit leading visuals like Octicons, avatars, and custom SVGs.\n1. can be used as form inputs in Rails forms.\n\n## Static list items\n\nThe Rails `SelectPanel` component allows items to be provided statically or loaded dynamically from the\nserver. Providing items statically is done using a fetch strategy of `:local` in combination with the\n`item` slot:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel.new(fetch_strategy: :local))) do |panel| %>\n <% panel.with_show_button { \"Select item\" } %>\n <% panel.with_item(label: \"Item 1\") %>\n <% panel.with_item(label: \"Item 2\") %>\n<% end %>\n```\n\n## Dynamic list items\n\nList items can also be fetched dynamically from the server and will require creating a Rails controller action\nto respond with the list of items in addition to rendering the `SelectPanel` instance. Render the instance as\nnormal, providing your desired [fetch strategy](#fetch-strategies):\n\n```erb\n<%= render(\n Primer::Alpha::SelectPanel.new(\n fetch_strategy: :remote,\n src: search_items_path # perhaps a Rails URL helper\n )\n) %>\n```\n\nDefine a controller action to serve the list of items. The `SelectPanel` component passes any filter text in\nthe `q=` URL parameter.\n\n```ruby\nclass SearchItemsController < ApplicationController\n def show\n # NOTE: params[:q] may be nil since there is no filter string available\n # when the panel is first opened\n @results = SomeModel.search(params[:q] || \"\")\n end\nend\n```\n\nResponses must be HTML fragments, eg. have a content type of `text/html+fragment`. This content type isn't\navailable by default in Rails, so you may have to register it eg. in an initializer:\n\n```ruby\nMime::Type.register(\"text/fragment+html\", :html_fragment)\n```\n\nRender a `Primer::Alpha::SelectPanel::ItemList` in the action's template, search_items/show.html_fragment.erb:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel::ItemList.new) do |list| %>\n <% @results.each do |result| %>\n <% list.with_item(label: result.title) do |item| %>\n <% item.with_description(result.description) %>\n <% end %>\n <% end %>\n<% end %>\n```\n\n### Selection consistency\n\nThe `SelectPanel` component automatically \"remembers\" which items have been selected across item fetch requests,\nmeaning the controller that renders dynamic list items does not (and should not) remember these selections or\npersist them until the user has confirmed them, either by submitting the form or otherwise indicating completion.\nThe `SelectPanel` component does not include unconfirmed selection data in requests.\n\n## Fetch strategies\n\nThe list of items can be fetched from a remote URL, or provided as a static list, configured using the\n`fetch_strategy` attribute. Fetch strategies are summarized below.\n\n1. `:remote`: a query is made to the URL in the `src` attribute every time the input field changes.\n\n2. `:eventually_local`: a query is made to the URL in the `src` attribute when the panel is first opened. The\n results are \"remembered\" and filtered in-memory for all subsequent filter operations, i.e. when the input\n field changes.\n\n3. `:local`: the list of items is provided statically ahead of time and filtered in-memory. No requests are made\n to the server.\n\n## Customizing filter behavior\n\nIf the fetch strategy is `:remote`, then filtering is handled server-side. The server should render a\n`Primer::Alpha::SelectPanel::ItemList` (an alias of {{#link_to_component}}Primer::Alpha::ActionList{{/link_to_component}})\nin the response containing the filtered list of items. The component achieves remote fetching via the\n[remote-input-element](https://github.com/github/remote-input-element), which sends a request to the\nserver with the filter string in the `q=` parameter. Responses must be HTML fragments, eg. have a content\ntype of `text/html+fragment`.\n\n### Local filtering\n\nIf the fetch strategy is `:local` or `:eventually_local`, filtering is performed client-side. Filter behavior can\nbe customized in JavaScript by setting the `filterFn` attribute on the instance of `SelectPanelElement`, eg:\n\n```javascript\ndocument.querySelector(\"select-panel\").filterFn = (item: HTMLElement, query: string): boolean => {\n // return true if the item should be displayed, false otherwise\n}\n```\n\nThe element's default filter function uses the value of the `data-filter-string` attribute, falling back to the\nelement's `innerText` property. It performs a case-insensitive substring match against the filter string.\n\n### `SelectPanel`s as form inputs\n\n`SelectPanel`s can be used as form inputs. They behave very similarly to how HTML `<select>` boxes behave, and\nplay nicely with Rails' built-in form mechanisms. Pass arguments via the `form_arguments:` argument, including\nthe Rails form builder object and the name of the field. Each list item must also have a value specified in\n`content_arguments: { data: { value: } }`.\n\n```erb\n<% form_with(model: Address.new) do |f| %>\n <%= render(Primer::Alpha::SelectPanel.new(form_arguments: { builder: f, name: \"country\" })) do |menu| %>\n <% countries.each do |country|\n <% menu.with_item(label: country.name, content_arguments: { data: { value: country.code } }) %>\n <% end %>\n <% end %>\n<% end %>\n```\n\nThe value of the `data: { value: ... }` argument is sent to the server on submit, keyed using the name provided above\n(eg. `\"country\"`). If no value is provided for an item, the value of that item is the item's label. Here's the\ncorresponding `AddressesController` that might be written to handle the form above:\n\n```ruby\nclass AddressesController < ApplicationController\n def create\n puts \"You chose #{address_params[:country]} as your country\"\n end\n\n private\n\n def address_params\n params.require(:address).permit(:country)\n end\nend\n```\n### JavaScript API\n\n`SelectPanel`s render a `<select-panel>` custom element that exposes behavior to the client.\n\n#### Utility methods\n\n* `show()`: Manually open the panel. Under normal circumstances, a show button is used to show the panel, but this method exists to support unusual use-cases.\n* `hide()`: Manually hides (closes) the panel.\n\n#### Query methods\n\n* `getItemById(itemId: string): Element`: Returns the item's HTML `<li>` element. The return value can be passed as the `item` argument to the other methods listed below.\n* `isItemChecked(item: Element): boolean`: Returns `true` if the item is checked, `false` otherwise.\n* `isItemHidden(item: Element): boolean`: Returns `true` if the item is hidden, `false` otherwise.\n* `isItemDisabled(item: Element): boolean`: Returns `true` if the item is disabled, `false` otherwise.\n\nNOTE: Item IDs are special values provided by the user that are attached to `SelectPanel` list items as the `data-item-id`\nHTML attribute. Item IDs can be provided by passing an `item_id:` attribute when adding items to the panel, eg:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel.new) do |panel| %>\n <% panel.with_item(item_id: \"my-id\") %>\n<% end %>\n```\n\nThe same is true when rendering `ItemList`s:\n\n```erb\n<%= render(Primer::Alpha::SelectPanel::ItemList.new) do |list| %>\n <% list.with_item(item_id: \"my-id\") %>\n<% end %>\n```\n\n#### State methods\n\n* `enableItem(item: Element)`: Enables the item, i.e. makes it clickable by the mouse and keyboard.\n* `disableItem(item: Element)`: Disables the item, i.e. makes it unclickable by the mouse and keyboard.\n* `checkItem(item: Element)`: Checks the item. Only has an effect in single- and multi-select modes.\n* `uncheckItem(item: Element)`: Unchecks the item. Only has an effect in multi-select mode, since items cannot be unchecked in single-select mode.\n\n#### Events\n\n|Name |Type |Bubbles |Cancelable |\n|:--------------------|:------------------------------------------|:-------|:----------|\n|`itemActivated` |`CustomEvent<ItemActivatedEvent>` |Yes |No |\n|`beforeItemActivated`|`CustomEvent<ItemActivatedEvent>` |Yes |Yes |\n|`dialog:open` |`CustomEvent<{dialog: HTMLDialogElement}>` |No |No |\n|`panelClosed` |`CustomEvent<{panel: SelectPanelElement}>` |Yes |No |\n\n_Item activation_\n\nThe `<select-panel>` element fires an `itemActivated` event whenever an item is activated (eg. clicked) via the mouse or keyboard.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"itemActivated\",\n (event: CustomEvent<ItemActivatedEvent>) => {\n event.detail.item // Element: the <li> item that was activated\n event.detail.checked // boolean: whether or not the result of the activation checked the item\n }\n)\n```\n\nThe `beforeItemActivated` event fires before an item is activated. Canceling this event will prevent the item\nfrom being activated.\n\n```typescript\ndocument.querySelector(\"select-panel\").addEventListener(\n \"beforeItemActivated\",\n (event: CustomEvent<ItemActivatedEvent>) => {\n event.detail.item // Element: the <li> item that was activated\n event.detail.checked // boolean: whether or not the result of the activation checked the item\n event.preventDefault() // Cancel the event to prevent activation (eg. checking/unchecking)\n }\n)\n```",
|
7442
7442
|
"accessibility_docs": null,
|
7443
7443
|
"is_form_component": false,
|
7444
7444
|
"is_published": true,
|
@@ -7451,88 +7451,10 @@
|
|
7451
7451
|
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/alpha/select_panel/default/",
|
7452
7452
|
"parameters": [
|
7453
7453
|
{
|
7454
|
-
"name": "
|
7455
|
-
"type": "String",
|
7456
|
-
"default": "`nil`",
|
7457
|
-
"description": "The URL to fetch search results from."
|
7458
|
-
},
|
7459
|
-
{
|
7460
|
-
"name": "title",
|
7461
|
-
"type": "String",
|
7462
|
-
"default": "`\"Menu\"`",
|
7463
|
-
"description": "The title that appears at the top of the panel."
|
7464
|
-
},
|
7465
|
-
{
|
7466
|
-
"name": "id",
|
7467
|
-
"type": "String",
|
7468
|
-
"default": "`self.class.generate_id`",
|
7469
|
-
"description": "The unique ID of the panel."
|
7470
|
-
},
|
7471
|
-
{
|
7472
|
-
"name": "size",
|
7473
|
-
"type": "Symbol",
|
7474
|
-
"default": "`:small`",
|
7475
|
-
"description": "The size of the panel. One of `:auto`, `:large`, `:medium`, `:medium_portrait`, `:small`, or `:xlarge`."
|
7476
|
-
},
|
7477
|
-
{
|
7478
|
-
"name": "select_variant",
|
7479
|
-
"type": "Symbol",
|
7480
|
-
"default": "`:single`",
|
7481
|
-
"description": "One of `:multiple`, `:none`, or `:single`."
|
7482
|
-
},
|
7483
|
-
{
|
7484
|
-
"name": "fetch_strategy",
|
7485
|
-
"type": "Symbol",
|
7486
|
-
"default": "`:remote`",
|
7487
|
-
"description": "One of `:eventually_local`, `:local`, or `:remote`."
|
7488
|
-
},
|
7489
|
-
{
|
7490
|
-
"name": "no_results_label",
|
7491
|
-
"type": "String",
|
7492
|
-
"default": "`\"No results found\"`",
|
7493
|
-
"description": "The label to display when no results are found."
|
7494
|
-
},
|
7495
|
-
{
|
7496
|
-
"name": "preload",
|
7454
|
+
"name": "use_experimental_non_local_form",
|
7497
7455
|
"type": "Boolean",
|
7498
7456
|
"default": "`false`",
|
7499
|
-
"description": "
|
7500
|
-
},
|
7501
|
-
{
|
7502
|
-
"name": "dynamic_label",
|
7503
|
-
"type": "Boolean",
|
7504
|
-
"default": "`false`",
|
7505
|
-
"description": "Whether or not to display the text of the currently selected item in the show button."
|
7506
|
-
},
|
7507
|
-
{
|
7508
|
-
"name": "dynamic_label_prefix",
|
7509
|
-
"type": "String",
|
7510
|
-
"default": "`nil`",
|
7511
|
-
"description": "If provided, the prefix is prepended to the dynamic label and displayed in the show button."
|
7512
|
-
},
|
7513
|
-
{
|
7514
|
-
"name": "dynamic_aria_label_prefix",
|
7515
|
-
"type": "String",
|
7516
|
-
"default": "`nil`",
|
7517
|
-
"description": "If provided, the prefix is prepended to the dynamic label and set as the value of the `aria-label` attribute on the show button."
|
7518
|
-
},
|
7519
|
-
{
|
7520
|
-
"name": "body_id",
|
7521
|
-
"type": "String",
|
7522
|
-
"default": "`nil`",
|
7523
|
-
"description": "The unique ID of the panel body. If not provided, the body ID will be set to the panel ID with a \"-body\" suffix."
|
7524
|
-
},
|
7525
|
-
{
|
7526
|
-
"name": "list_arguments",
|
7527
|
-
"type": "Hash",
|
7528
|
-
"default": "`{}`",
|
7529
|
-
"description": "Arguments to pass to the underlying {{#link_to_component}}Primer::Alpha::ActionList{{/link_to_component}} component. Only has an effect for the local fetch strategy."
|
7530
|
-
},
|
7531
|
-
{
|
7532
|
-
"name": "form_arguments",
|
7533
|
-
"type": "Hash",
|
7534
|
-
"default": "`{}`",
|
7535
|
-
"description": "Form arguments to pass to the underlying {{#link_to_component}}Primer::Alpha::ActionList{{/link_to_component}} component. Only has an effect for the local fetch strategy."
|
7457
|
+
"description": "A feature flag used to slowly roll out moving the input field (generated from form arguments) to the top of the SelectPanel HTML thus allowing remote fetching to have default form values."
|
7536
7458
|
},
|
7537
7459
|
{
|
7538
7460
|
"name": "show_filter",
|
@@ -8052,6 +7974,19 @@
|
|
8052
7974
|
]
|
8053
7975
|
}
|
8054
7976
|
},
|
7977
|
+
{
|
7978
|
+
"preview_path": "primer/alpha/select_panel/remote_fetch_form",
|
7979
|
+
"name": "remote_fetch_form",
|
7980
|
+
"snapshot": "interactive",
|
7981
|
+
"skip_rules": {
|
7982
|
+
"wont_fix": [
|
7983
|
+
"region"
|
7984
|
+
],
|
7985
|
+
"will_fix": [
|
7986
|
+
"color-contrast"
|
7987
|
+
]
|
7988
|
+
}
|
7989
|
+
},
|
8055
7990
|
{
|
8056
7991
|
"preview_path": "primer/alpha/select_panel/multiselect_form",
|
8057
7992
|
"name": "multiselect_form",
|
data/static/previews.json
CHANGED
@@ -6909,6 +6909,19 @@
|
|
6909
6909
|
]
|
6910
6910
|
}
|
6911
6911
|
},
|
6912
|
+
{
|
6913
|
+
"preview_path": "primer/alpha/select_panel/remote_fetch_form",
|
6914
|
+
"name": "remote_fetch_form",
|
6915
|
+
"snapshot": "interactive",
|
6916
|
+
"skip_rules": {
|
6917
|
+
"wont_fix": [
|
6918
|
+
"region"
|
6919
|
+
],
|
6920
|
+
"will_fix": [
|
6921
|
+
"color-contrast"
|
6922
|
+
]
|
6923
|
+
}
|
6924
|
+
},
|
6912
6925
|
{
|
6913
6926
|
"preview_path": "primer/alpha/select_panel/multiselect_form",
|
6914
6927
|
"name": "multiselect_form",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openproject-primer_view_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.58.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub Open Source
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-03-
|
12
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionview
|
@@ -905,6 +905,7 @@ files:
|
|
905
905
|
- previews/primer/alpha/select_panel_preview/playground.html.erb
|
906
906
|
- previews/primer/alpha/select_panel_preview/remote_fetch.html.erb
|
907
907
|
- previews/primer/alpha/select_panel_preview/remote_fetch_filter_failure.html.erb
|
908
|
+
- previews/primer/alpha/select_panel_preview/remote_fetch_form.html.erb
|
908
909
|
- previews/primer/alpha/select_panel_preview/remote_fetch_initial_failure.html.erb
|
909
910
|
- previews/primer/alpha/select_panel_preview/remote_fetch_no_results.html.erb
|
910
911
|
- previews/primer/alpha/select_panel_preview/scroll_container.html.erb
|