@primer/view-components 0.28.0-rc.538292aa → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- package/app/assets/javascripts/app/components/primer/alpha/select_panel_element.d.ts +1 -3
- package/app/assets/javascripts/primer_view_components.js +1 -1
- package/app/assets/javascripts/primer_view_components.js.map +1 -1
- package/app/components/primer/alpha/select_panel_element.d.ts +1 -3
- package/app/components/primer/alpha/select_panel_element.js +68 -71
- package/package.json +1 -1
- package/static/info_arch.json +27 -1
- package/static/previews.json +26 -0
@@ -20,7 +20,7 @@ export declare class SelectPanelElement extends HTMLElement {
|
|
20
20
|
ariaLiveContainer: HTMLElement;
|
21
21
|
noResults: HTMLElement;
|
22
22
|
fragmentErrorElement: HTMLElement;
|
23
|
-
|
23
|
+
bannerErrorElement: HTMLElement;
|
24
24
|
bodySpinner: HTMLElement;
|
25
25
|
filterFn?: FilterFn;
|
26
26
|
get open(): boolean;
|
@@ -52,8 +52,6 @@ export declare class SelectPanelElement extends HTMLElement {
|
|
52
52
|
disableItem(item: SelectPanelItem | null): void;
|
53
53
|
enableItem(item: SelectPanelItem | null): void;
|
54
54
|
isItemHidden(item: SelectPanelItem | null): boolean;
|
55
|
-
hideItem(item: SelectPanelItem | null): void;
|
56
|
-
showItem(item: SelectPanelItem | null): void;
|
57
55
|
isItemChecked(item: SelectPanelItem | null): boolean;
|
58
56
|
checkItem(item: SelectPanelItem | null): void;
|
59
57
|
uncheckItem(item: SelectPanelItem | null): void;
|
@@ -15,7 +15,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
15
15
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
16
16
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
17
17
|
};
|
18
|
-
var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_softDisableItems, _SelectPanelElement_updateTabIndices, _SelectPanelElement_potentiallyDisallowActivation, _SelectPanelElement_isAnchorActivationViaSpace, _SelectPanelElement_isActivation, _SelectPanelElement_checkSelectedItems, _SelectPanelElement_addSelectedItem, _SelectPanelElement_removeSelectedItem, _SelectPanelElement_setTextFieldLoadingSpinnerTimer, _SelectPanelElement_handleIncludeFragmentEvent, _SelectPanelElement_toggleIncludeFragmentElements, _SelectPanelElement_handleRemoteInputEvent, _SelectPanelElement_defaultFilterFn, _SelectPanelElement_handleSearchFieldEvent, _SelectPanelElement_updateItemVisibility, _SelectPanelElement_inErrorState, _SelectPanelElement_setErrorState, _SelectPanelElement_clearErrorState, _SelectPanelElement_maybeAnnounce, _SelectPanelElement_fetchStrategy_get, _SelectPanelElement_filterInputTextFieldElement_get, _SelectPanelElement_performFilteringLocally, _SelectPanelElement_handleInvokerActivated, _SelectPanelElement_handleDialogItemActivated, _SelectPanelElement_handleItemActivated, _SelectPanelElement_setDynamicLabel, _SelectPanelElement_updateInput, _SelectPanelElement_firstItem_get, _SelectPanelElement_getItemContent;
|
18
|
+
var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_waitForCondition, _SelectPanelElement_softDisableItems, _SelectPanelElement_updateTabIndices, _SelectPanelElement_potentiallyDisallowActivation, _SelectPanelElement_isAnchorActivationViaSpace, _SelectPanelElement_isActivation, _SelectPanelElement_checkSelectedItems, _SelectPanelElement_addSelectedItem, _SelectPanelElement_removeSelectedItem, _SelectPanelElement_setTextFieldLoadingSpinnerTimer, _SelectPanelElement_handleIncludeFragmentEvent, _SelectPanelElement_toggleIncludeFragmentElements, _SelectPanelElement_handleRemoteInputEvent, _SelectPanelElement_defaultFilterFn, _SelectPanelElement_handleSearchFieldEvent, _SelectPanelElement_updateItemVisibility, _SelectPanelElement_inErrorState, _SelectPanelElement_setErrorState, _SelectPanelElement_clearErrorState, _SelectPanelElement_maybeAnnounce, _SelectPanelElement_fetchStrategy_get, _SelectPanelElement_filterInputTextFieldElement_get, _SelectPanelElement_performFilteringLocally, _SelectPanelElement_handleInvokerActivated, _SelectPanelElement_handleDialogItemActivated, _SelectPanelElement_handleItemActivated, _SelectPanelElement_setDynamicLabel, _SelectPanelElement_updateInput, _SelectPanelElement_firstItem_get, _SelectPanelElement_hideItem, _SelectPanelElement_showItem, _SelectPanelElement_getItemContent;
|
19
19
|
import { getAnchoredPosition } from '@primer/behaviors';
|
20
20
|
import { controller, target } from '@github/catalyst';
|
21
21
|
import { announceFromElement, announce } from '../aria_live';
|
@@ -170,64 +170,35 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
|
|
170
170
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
171
171
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_softDisableItems).call(this);
|
172
172
|
updateWhenVisible(this);
|
173
|
-
|
173
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.remoteInput), () => {
|
174
174
|
this.remoteInput.addEventListener('loadstart', this, { signal });
|
175
175
|
this.remoteInput.addEventListener('loadend', this, { signal });
|
176
|
-
}
|
177
|
-
|
178
|
-
const mutationObserver = new MutationObserver(() => {
|
179
|
-
if (this.remoteInput) {
|
180
|
-
this.remoteInput.addEventListener('loadstart', this, { signal });
|
181
|
-
this.remoteInput.addEventListener('loadend', this, { signal });
|
182
|
-
mutationObserver.disconnect();
|
183
|
-
}
|
184
|
-
});
|
185
|
-
mutationObserver.observe(this, { childList: true, subtree: true });
|
186
|
-
}
|
187
|
-
if (this.includeFragment) {
|
176
|
+
});
|
177
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.includeFragment), () => {
|
188
178
|
this.includeFragment.addEventListener('include-fragment-replaced', this, { signal });
|
189
179
|
this.includeFragment.addEventListener('error', this, { signal });
|
190
180
|
this.includeFragment.addEventListener('loadend', this, { signal });
|
191
|
-
}
|
192
|
-
else {
|
193
|
-
const mutationObserver = new MutationObserver(() => {
|
194
|
-
if (this.includeFragment) {
|
195
|
-
this.includeFragment.addEventListener('include-fragment-replaced', this, { signal });
|
196
|
-
this.includeFragment.addEventListener('error', this, { signal });
|
197
|
-
this.includeFragment.addEventListener('loadend', this, { signal });
|
198
|
-
mutationObserver.disconnect();
|
199
|
-
}
|
200
|
-
});
|
201
|
-
mutationObserver.observe(this, { childList: true, subtree: true });
|
202
|
-
}
|
181
|
+
});
|
203
182
|
__classPrivateFieldSet(this, _SelectPanelElement_dialogIntersectionObserver, new IntersectionObserver(entries => {
|
204
183
|
for (const entry of entries) {
|
205
184
|
const elem = entry.target;
|
206
185
|
if (entry.isIntersecting && elem === this.dialog) {
|
207
186
|
this.updateAnchorPosition();
|
208
|
-
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
|
209
|
-
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
210
|
-
}
|
211
187
|
}
|
212
188
|
}
|
213
189
|
}), "f");
|
214
|
-
|
190
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.dialog), () => {
|
215
191
|
if (this.getAttribute('data-open-on-load') === 'true') {
|
216
192
|
this.show();
|
217
193
|
}
|
218
194
|
__classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
}
|
226
|
-
__classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
|
227
|
-
mutationObserver.disconnect();
|
228
|
-
}
|
195
|
+
this.dialog.addEventListener('close', this, { signal });
|
196
|
+
});
|
197
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
|
198
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => this.items.length > 0, () => {
|
199
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
200
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
229
201
|
});
|
230
|
-
mutationObserver.observe(this, { childList: true, subtree: true });
|
231
202
|
}
|
232
203
|
}
|
233
204
|
disconnectedCallback() {
|
@@ -262,7 +233,14 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
|
|
262
233
|
return;
|
263
234
|
}
|
264
235
|
if (targetIsCloseButton && eventIsActivation) {
|
265
|
-
//
|
236
|
+
// hide() will automatically be called by dialog event triggered from `data-close-dialog-id`
|
237
|
+
return;
|
238
|
+
}
|
239
|
+
if (event.target === this.dialog && event.type === 'close') {
|
240
|
+
this.dispatchEvent(new CustomEvent('panelClosed', {
|
241
|
+
detail: { panel: this },
|
242
|
+
bubbles: true,
|
243
|
+
}));
|
266
244
|
return;
|
267
245
|
}
|
268
246
|
const item = event.target.closest(visibleMenuItemSelectors)?.parentElement;
|
@@ -315,10 +293,6 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
|
|
315
293
|
}
|
316
294
|
hide() {
|
317
295
|
this.dialog.close();
|
318
|
-
this.dispatchEvent(new CustomEvent('panelClosed', {
|
319
|
-
detail: { panel: this },
|
320
|
-
bubbles: true,
|
321
|
-
}));
|
322
296
|
}
|
323
297
|
get visibleItems() {
|
324
298
|
return Array.from(this.querySelectorAll(visibleMenuItemSelectors)).map(element => element.parentElement);
|
@@ -367,16 +341,6 @@ let SelectPanelElement = class SelectPanelElement extends HTMLElement {
|
|
367
341
|
return false;
|
368
342
|
}
|
369
343
|
}
|
370
|
-
hideItem(item) {
|
371
|
-
if (item) {
|
372
|
-
item.setAttribute('hidden', 'hidden');
|
373
|
-
}
|
374
|
-
}
|
375
|
-
showItem(item) {
|
376
|
-
if (item) {
|
377
|
-
item.removeAttribute('hidden');
|
378
|
-
}
|
379
|
-
}
|
380
344
|
isItemChecked(item) {
|
381
345
|
if (item) {
|
382
346
|
return __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).getAttribute(this.ariaSelectionType) === 'true';
|
@@ -408,6 +372,20 @@ _SelectPanelElement_selectedItems = new WeakMap();
|
|
408
372
|
_SelectPanelElement_loadingDelayTimeoutId = new WeakMap();
|
409
373
|
_SelectPanelElement_loadingAnnouncementTimeoutId = new WeakMap();
|
410
374
|
_SelectPanelElement_instances = new WeakSet();
|
375
|
+
_SelectPanelElement_waitForCondition = function _SelectPanelElement_waitForCondition(condition, body) {
|
376
|
+
if (condition()) {
|
377
|
+
body();
|
378
|
+
}
|
379
|
+
else {
|
380
|
+
const mutationObserver = new MutationObserver(() => {
|
381
|
+
if (condition()) {
|
382
|
+
body();
|
383
|
+
mutationObserver.disconnect();
|
384
|
+
}
|
385
|
+
});
|
386
|
+
mutationObserver.observe(this, { childList: true, subtree: true });
|
387
|
+
}
|
388
|
+
};
|
411
389
|
_SelectPanelElement_softDisableItems = function _SelectPanelElement_softDisableItems() {
|
412
390
|
const { signal } = __classPrivateFieldGet(this, _SelectPanelElement_abortController, "f");
|
413
391
|
for (const item of this.querySelectorAll(validSelectors.join(','))) {
|
@@ -483,23 +461,28 @@ _SelectPanelElement_isActivation = function _SelectPanelElement_isActivation(eve
|
|
483
461
|
};
|
484
462
|
_SelectPanelElement_checkSelectedItems = function _SelectPanelElement_checkSelectedItems() {
|
485
463
|
for (const item of this.items) {
|
486
|
-
const
|
464
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
465
|
+
if (!itemContent)
|
466
|
+
continue;
|
467
|
+
const value = itemContent.getAttribute('data-value');
|
487
468
|
if (value) {
|
488
469
|
if (__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value)) {
|
489
|
-
|
470
|
+
itemContent.setAttribute(this.ariaSelectionType, 'true');
|
490
471
|
}
|
491
472
|
}
|
492
473
|
}
|
493
474
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
494
475
|
};
|
495
476
|
_SelectPanelElement_addSelectedItem = function _SelectPanelElement_addSelectedItem(item) {
|
496
|
-
const
|
497
|
-
|
477
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
478
|
+
if (!itemContent)
|
479
|
+
return;
|
480
|
+
const value = itemContent.getAttribute('data-value');
|
498
481
|
if (value) {
|
499
482
|
__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").set(value, {
|
500
483
|
value,
|
501
|
-
label:
|
502
|
-
inputName:
|
484
|
+
label: itemContent.querySelector('.ActionListItem-label')?.textContent?.trim(),
|
485
|
+
inputName: itemContent.getAttribute('data-input-name'),
|
503
486
|
element: item,
|
504
487
|
});
|
505
488
|
}
|
@@ -633,11 +616,11 @@ _SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateIt
|
|
633
616
|
const filter = this.filterFn || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_defaultFilterFn);
|
634
617
|
for (const item of this.items) {
|
635
618
|
if (filter(item, query)) {
|
636
|
-
this.
|
619
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_showItem).call(this, item);
|
637
620
|
atLeastOneResult = true;
|
638
621
|
}
|
639
622
|
else {
|
640
|
-
this.
|
623
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_hideItem).call(this, item);
|
641
624
|
}
|
642
625
|
}
|
643
626
|
}
|
@@ -647,7 +630,10 @@ _SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateIt
|
|
647
630
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
648
631
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_maybeAnnounce).call(this);
|
649
632
|
for (const item of this.items) {
|
650
|
-
const
|
633
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
634
|
+
if (!itemContent)
|
635
|
+
continue;
|
636
|
+
const value = itemContent.getAttribute('data-value');
|
651
637
|
if (value && !__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value) && this.isItemChecked(item)) {
|
652
638
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
653
639
|
}
|
@@ -672,17 +658,17 @@ _SelectPanelElement_inErrorState = function _SelectPanelElement_inErrorState() {
|
|
672
658
|
if (this.fragmentErrorElement && !this.fragmentErrorElement.hasAttribute('hidden')) {
|
673
659
|
return true;
|
674
660
|
}
|
675
|
-
return !this.
|
661
|
+
return !this.bannerErrorElement.hasAttribute('hidden');
|
676
662
|
};
|
677
663
|
_SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(type) {
|
678
664
|
let errorElement = this.fragmentErrorElement;
|
679
665
|
if (type === ErrorStateType.BODY) {
|
680
666
|
this.fragmentErrorElement?.removeAttribute('hidden');
|
681
|
-
this.
|
667
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
682
668
|
}
|
683
669
|
else {
|
684
|
-
errorElement = this.
|
685
|
-
this.
|
670
|
+
errorElement = this.bannerErrorElement;
|
671
|
+
this.bannerErrorElement?.removeAttribute('hidden');
|
686
672
|
this.fragmentErrorElement?.setAttribute('hidden', '');
|
687
673
|
}
|
688
674
|
// check if the errorElement is visible in the dom
|
@@ -693,7 +679,7 @@ _SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(t
|
|
693
679
|
};
|
694
680
|
_SelectPanelElement_clearErrorState = function _SelectPanelElement_clearErrorState() {
|
695
681
|
this.fragmentErrorElement?.setAttribute('hidden', '');
|
696
|
-
this.
|
682
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
697
683
|
};
|
698
684
|
_SelectPanelElement_maybeAnnounce = function _SelectPanelElement_maybeAnnounce() {
|
699
685
|
if (this.open && this.list) {
|
@@ -814,6 +800,7 @@ _SelectPanelElement_handleItemActivated = function _SelectPanelElement_handleIte
|
|
814
800
|
}
|
815
801
|
}
|
816
802
|
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
803
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
817
804
|
this.dispatchEvent(new CustomEvent('itemActivated', {
|
818
805
|
bubbles: true,
|
819
806
|
detail: { item, checked },
|
@@ -884,6 +871,16 @@ _SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
|
884
871
|
_SelectPanelElement_firstItem_get = function _SelectPanelElement_firstItem_get() {
|
885
872
|
return (this.querySelector(visibleMenuItemSelectors)?.parentElement || null);
|
886
873
|
};
|
874
|
+
_SelectPanelElement_hideItem = function _SelectPanelElement_hideItem(item) {
|
875
|
+
if (item) {
|
876
|
+
item.setAttribute('hidden', 'hidden');
|
877
|
+
}
|
878
|
+
};
|
879
|
+
_SelectPanelElement_showItem = function _SelectPanelElement_showItem(item) {
|
880
|
+
if (item) {
|
881
|
+
item.removeAttribute('hidden');
|
882
|
+
}
|
883
|
+
};
|
887
884
|
_SelectPanelElement_getItemContent = function _SelectPanelElement_getItemContent(item) {
|
888
885
|
return item.querySelector('.ActionListContent');
|
889
886
|
};
|
@@ -913,7 +910,7 @@ __decorate([
|
|
913
910
|
], SelectPanelElement.prototype, "fragmentErrorElement", void 0);
|
914
911
|
__decorate([
|
915
912
|
target
|
916
|
-
], SelectPanelElement.prototype, "
|
913
|
+
], SelectPanelElement.prototype, "bannerErrorElement", void 0);
|
917
914
|
__decorate([
|
918
915
|
target
|
919
916
|
], SelectPanelElement.prototype, "bodySpinner", void 0);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/view-components",
|
3
|
-
"version": "0.28.0
|
3
|
+
"version": "0.28.0",
|
4
4
|
"description": "ViewComponents for the Primer Design System",
|
5
5
|
"main": "app/assets/javascripts/primer_view_components.js",
|
6
6
|
"module": "app/components/primer/primer.js",
|
package/static/info_arch.json
CHANGED
@@ -7511,7 +7511,7 @@
|
|
7511
7511
|
},
|
7512
7512
|
{
|
7513
7513
|
"fully_qualified_name": "Primer::Alpha::SelectPanel",
|
7514
|
-
"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 # 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:\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, 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_code]'\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, 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* `showItem(item: Element)`: Shows the item, i.e. makes it visible.\n* `hideItem(item: Element)`: Hides the item, i.e. makes it invisible.\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```",
|
7514
|
+
"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_code]'\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, 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```",
|
7515
7515
|
"accessibility_docs": null,
|
7516
7516
|
"is_form_component": false,
|
7517
7517
|
"is_published": true,
|
@@ -8051,6 +8051,32 @@
|
|
8051
8051
|
"color-contrast"
|
8052
8052
|
]
|
8053
8053
|
}
|
8054
|
+
},
|
8055
|
+
{
|
8056
|
+
"preview_path": "primer/alpha/select_panel/single_select_form",
|
8057
|
+
"name": "single_select_form",
|
8058
|
+
"snapshot": "interactive",
|
8059
|
+
"skip_rules": {
|
8060
|
+
"wont_fix": [
|
8061
|
+
"region"
|
8062
|
+
],
|
8063
|
+
"will_fix": [
|
8064
|
+
"color-contrast"
|
8065
|
+
]
|
8066
|
+
}
|
8067
|
+
},
|
8068
|
+
{
|
8069
|
+
"preview_path": "primer/alpha/select_panel/multiselect_form",
|
8070
|
+
"name": "multiselect_form",
|
8071
|
+
"snapshot": "interactive",
|
8072
|
+
"skip_rules": {
|
8073
|
+
"wont_fix": [
|
8074
|
+
"region"
|
8075
|
+
],
|
8076
|
+
"will_fix": [
|
8077
|
+
"color-contrast"
|
8078
|
+
]
|
8079
|
+
}
|
8054
8080
|
}
|
8055
8081
|
],
|
8056
8082
|
"subcomponents": [
|
package/static/previews.json
CHANGED
@@ -6134,6 +6134,32 @@
|
|
6134
6134
|
"color-contrast"
|
6135
6135
|
]
|
6136
6136
|
}
|
6137
|
+
},
|
6138
|
+
{
|
6139
|
+
"preview_path": "primer/alpha/select_panel/single_select_form",
|
6140
|
+
"name": "single_select_form",
|
6141
|
+
"snapshot": "interactive",
|
6142
|
+
"skip_rules": {
|
6143
|
+
"wont_fix": [
|
6144
|
+
"region"
|
6145
|
+
],
|
6146
|
+
"will_fix": [
|
6147
|
+
"color-contrast"
|
6148
|
+
]
|
6149
|
+
}
|
6150
|
+
},
|
6151
|
+
{
|
6152
|
+
"preview_path": "primer/alpha/select_panel/multiselect_form",
|
6153
|
+
"name": "multiselect_form",
|
6154
|
+
"snapshot": "interactive",
|
6155
|
+
"skip_rules": {
|
6156
|
+
"wont_fix": [
|
6157
|
+
"region"
|
6158
|
+
],
|
6159
|
+
"will_fix": [
|
6160
|
+
"color-contrast"
|
6161
|
+
]
|
6162
|
+
}
|
6137
6163
|
}
|
6138
6164
|
]
|
6139
6165
|
},
|