@primer/view-components 0.35.1 → 0.35.2-rc.4013086b

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.
@@ -1,5 +1,7 @@
1
1
  import { IncludeFragmentElement } from '@github/include-fragment-element';
2
2
  import type { AnchorAlignment, AnchorSide } from '@primer/behaviors';
3
+ import type { LiveRegionElement } from '@primer/live-region-element';
4
+ import '@primer/live-region-element';
3
5
  import '@oddbird/popover-polyfill';
4
6
  type SelectVariant = 'none' | 'single' | 'multiple' | null;
5
7
  type SelectedItem = {
@@ -16,11 +18,11 @@ export declare class SelectPanelElement extends HTMLElement {
16
18
  filterInputTextField: HTMLInputElement;
17
19
  remoteInput: HTMLElement;
18
20
  list: HTMLElement;
19
- ariaLiveContainer: HTMLElement;
20
21
  noResults: HTMLElement;
21
22
  fragmentErrorElement: HTMLElement;
22
23
  bannerErrorElement: HTMLElement;
23
24
  bodySpinner: HTMLElement;
25
+ liveRegion: LiveRegionElement;
24
26
  filterFn?: FilterFn;
25
27
  get open(): boolean;
26
28
  get selectVariant(): SelectVariant;
@@ -18,8 +18,8 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
18
18
  var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_hasLoadedData, _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
- import { announceFromElement, announce } from '../aria_live';
22
21
  import { IncludeFragmentElement } from '@github/include-fragment-element';
22
+ import '@primer/live-region-element';
23
23
  import '@oddbird/popover-polyfill';
24
24
  const validSelectors = ['[role="option"]'];
25
25
  const menuItemSelectors = validSelectors.join(',');
@@ -525,7 +525,7 @@ _SelectPanelElement_setTextFieldLoadingSpinnerTimer = function _SelectPanelEleme
525
525
  if (__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"))
526
526
  clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"));
527
527
  __classPrivateFieldSet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, setTimeout(() => {
528
- announce('Loading', { element: this.ariaLiveContainer });
528
+ this.liveRegion.announce('Loading');
529
529
  }, 2000), "f");
530
530
  __classPrivateFieldSet(this, _SelectPanelElement_loadingDelayTimeoutId, setTimeout(() => {
531
531
  __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_filterInputTextFieldElement_get)?.showLeadingSpinner();
@@ -551,7 +551,7 @@ _SelectPanelElement_handleIncludeFragmentEvent = function _SelectPanelElement_ha
551
551
  const errorElement = this.fragmentErrorElement;
552
552
  // check if the errorElement is visible in the dom
553
553
  if (errorElement && !errorElement.hasAttribute('hidden')) {
554
- announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
554
+ this.liveRegion.announceFromElement(errorElement, { politeness: 'assertive' });
555
555
  return;
556
556
  }
557
557
  break;
@@ -738,7 +738,7 @@ _SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(t
738
738
  }
739
739
  // check if the errorElement is visible in the dom
740
740
  if (errorElement && !errorElement.hasAttribute('hidden')) {
741
- announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
741
+ this.liveRegion.announceFromElement(errorElement, { politeness: 'assertive' });
742
742
  return;
743
743
  }
744
744
  };
@@ -748,17 +748,15 @@ _SelectPanelElement_clearErrorState = function _SelectPanelElement_clearErrorSta
748
748
  };
749
749
  _SelectPanelElement_maybeAnnounce = function _SelectPanelElement_maybeAnnounce() {
750
750
  if (this.open && this.list) {
751
- const items = this.items;
751
+ const items = this.visibleItems;
752
752
  if (items.length > 0) {
753
753
  const instructions = 'tab for results';
754
- announce(`${items.length} result${items.length === 1 ? '' : 's'} ${instructions}`, {
755
- element: this.ariaLiveContainer,
756
- });
754
+ this.liveRegion.announce(`${items.length} result${items.length === 1 ? '' : 's'} ${instructions}`);
757
755
  }
758
756
  else {
759
757
  const noResultsEl = this.noResults;
760
758
  if (noResultsEl) {
761
- announceFromElement(noResultsEl, { element: this.ariaLiveContainer });
759
+ this.liveRegion.announceFromElement(noResultsEl);
762
760
  }
763
761
  }
764
762
  }
@@ -976,9 +974,6 @@ __decorate([
976
974
  __decorate([
977
975
  target
978
976
  ], SelectPanelElement.prototype, "list", void 0);
979
- __decorate([
980
- target
981
- ], SelectPanelElement.prototype, "ariaLiveContainer", void 0);
982
977
  __decorate([
983
978
  target
984
979
  ], SelectPanelElement.prototype, "noResults", void 0);
@@ -991,6 +986,9 @@ __decorate([
991
986
  __decorate([
992
987
  target
993
988
  ], SelectPanelElement.prototype, "bodySpinner", void 0);
989
+ __decorate([
990
+ target
991
+ ], SelectPanelElement.prototype, "liveRegion", void 0);
994
992
  SelectPanelElement = __decorate([
995
993
  controller
996
994
  ], SelectPanelElement);
@@ -7,7 +7,6 @@ import './anchored_position';
7
7
  import './dialog_helper';
8
8
  import './focus_group';
9
9
  import './scrollable_region';
10
- import './aria_live';
11
10
  import './shared_events';
12
11
  import './alpha/modal_dialog';
13
12
  import './beta/nav_list';
@@ -7,7 +7,6 @@ import './anchored_position';
7
7
  import './dialog_helper';
8
8
  import './focus_group';
9
9
  import './scrollable_region';
10
- import './aria_live';
11
10
  import './shared_events';
12
11
  import './alpha/modal_dialog';
13
12
  import './beta/nav_list';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.35.1",
3
+ "version": "0.35.2-rc.4013086b",
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",
@@ -53,6 +53,7 @@
53
53
  "@github/relative-time-element": "^4.0.0",
54
54
  "@github/remote-input-element": "^0.4.0",
55
55
  "@github/tab-container-element": "^3.1.2",
56
+ "@primer/live-region-element": "^0.7.1",
56
57
  "@oddbird/popover-polyfill": "^0.4.0",
57
58
  "@primer/behaviors": "^1.3.4"
58
59
  },
@@ -1,8 +0,0 @@
1
- export declare function announceFromElement(el: HTMLElement, options?: {
2
- assertive?: boolean;
3
- element?: HTMLElement;
4
- }): void;
5
- export declare function announce(message: string, options?: {
6
- assertive?: boolean;
7
- element?: HTMLElement;
8
- }): void;
@@ -1,8 +0,0 @@
1
- export declare function announceFromElement(el: HTMLElement, options?: {
2
- assertive?: boolean;
3
- element?: HTMLElement;
4
- }): void;
5
- export declare function announce(message: string, options?: {
6
- assertive?: boolean;
7
- element?: HTMLElement;
8
- }): void;
@@ -1,38 +0,0 @@
1
- const safeDocument = typeof document === 'undefined' ? undefined : document;
2
- // Announce an element's text to the screen reader.
3
- export function announceFromElement(el, options) {
4
- announce(getTextContent(el), options);
5
- }
6
- // Announce message update to screen reader.
7
- // Note: Use caution when using this function while a dialog is active.
8
- // If the message is updated while the dialog is open, the screen reader may not announce the live region.
9
- export function announce(message, options) {
10
- const { assertive, element } = options ?? {};
11
- setContainerContent(message, assertive, element);
12
- }
13
- // Set aria-live container to message.
14
- function setContainerContent(message, assertive, element) {
15
- const getQuerySelector = () => {
16
- return assertive ? '#js-global-screen-reader-notice-assertive' : '#js-global-screen-reader-notice';
17
- };
18
- const container = element ?? safeDocument?.querySelector(getQuerySelector());
19
- if (!container)
20
- return;
21
- if (container.textContent === message) {
22
- /* This is a hack due to the way the aria live API works.
23
- A screen reader will not read a live region again
24
- if the text is the same. Adding a space character tells
25
- the browser that the live region has updated,
26
- which will cause it to read again, but with no audible difference. */
27
- container.textContent = `${message}\u00A0`;
28
- }
29
- else {
30
- container.textContent = message;
31
- }
32
- }
33
- // Gets the trimmed text content of an element.
34
- function getTextContent(el) {
35
- // innerText does not contain hidden text
36
- /* eslint-disable-next-line github/no-innerText */
37
- return (el.getAttribute('aria-label') || el.innerText || '').trim();
38
- }