@primer/behaviors 1.2.0-rc.5aa5da2 → 1.3.0-rc.9cf9e61

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @primer/behaviors
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#152](https://github.com/primer/behaviors/pull/152) [`afaf380`](https://github.com/primer/behaviors/commit/afaf380893cb858e6c85515bb490866d76d3d8b7) Thanks [@colebemis](https://github.com/colebemis)! - focusZone: Add `preventScroll` option
8
+
3
9
  ## 1.2.0
4
10
 
5
11
  ### Minor Changes
@@ -24,6 +24,7 @@ export interface FocusZoneSettings {
24
24
  activeDescendantControl?: HTMLElement;
25
25
  onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
26
26
  focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
27
+ preventScroll?: boolean;
27
28
  }
28
29
  export declare const isActiveDescendantAttribute = "data-is-active-descendant";
29
30
  export declare const activeDescendantActivatedDirectly = "activated-directly";
@@ -124,7 +124,7 @@ exports.activeDescendantActivatedDirectly = 'activated-directly';
124
124
  exports.activeDescendantActivatedIndirectly = 'activated-indirectly';
125
125
  exports.hasActiveDescendantAttribute = 'data-has-active-descendant';
126
126
  function focusZone(container, settings) {
127
- var _a, _b, _c, _d;
127
+ var _a, _b, _c, _d, _e;
128
128
  const focusableElements = [];
129
129
  const savedTabIndex = new WeakMap();
130
130
  const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
@@ -133,6 +133,7 @@ function focusZone(container, settings) {
133
133
  const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
134
134
  const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
135
135
  let currentFocusedElement;
136
+ const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
136
137
  function getFirstFocusableElement() {
137
138
  return focusableElements[0];
138
139
  }
@@ -243,7 +244,7 @@ function focusZone(container, settings) {
243
244
  childList: true
244
245
  });
245
246
  const controller = new AbortController();
246
- const signal = (_d = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _d !== void 0 ? _d : controller.signal;
247
+ const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
247
248
  signal.addEventListener('abort', () => {
248
249
  endFocusManagement(...focusableElements);
249
250
  });
@@ -256,7 +257,7 @@ function focusZone(container, settings) {
256
257
  if (activeDescendantControl) {
257
258
  container.addEventListener('focusin', event => {
258
259
  if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
259
- activeDescendantControl.focus();
260
+ activeDescendantControl.focus({ preventScroll });
260
261
  updateFocusedElement(event.target);
261
262
  }
262
263
  });
@@ -300,7 +301,7 @@ function focusZone(container, settings) {
300
301
  if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
301
302
  const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
302
303
  const targetElement = focusableElements[targetElementIndex];
303
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
304
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({ preventScroll });
304
305
  return;
305
306
  }
306
307
  else {
@@ -312,7 +313,7 @@ function focusZone(container, settings) {
312
313
  const elementToFocus = focusInStrategy(event.relatedTarget);
313
314
  const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
314
315
  if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
315
- elementToFocus.focus();
316
+ elementToFocus.focus({ preventScroll });
316
317
  return;
317
318
  }
318
319
  else {
@@ -397,7 +398,7 @@ function focusZone(container, settings) {
397
398
  }
398
399
  else if (nextElementToFocus) {
399
400
  lastKeyboardFocusDirection = direction;
400
- nextElementToFocus.focus();
401
+ nextElementToFocus.focus({ preventScroll });
401
402
  }
402
403
  if (event.key !== 'Tab' || nextElementToFocus) {
403
404
  event.preventDefault();
@@ -24,6 +24,7 @@ export interface FocusZoneSettings {
24
24
  activeDescendantControl?: HTMLElement;
25
25
  onActiveDescendantChanged?: (newActiveDescendant: HTMLElement | undefined, previousActiveDescendant: HTMLElement | undefined, directlyActivated: boolean) => void;
26
26
  focusInStrategy?: 'first' | 'closest' | 'previous' | ((previousFocusedElement: Element) => HTMLElement | undefined);
27
+ preventScroll?: boolean;
27
28
  }
28
29
  export declare const isActiveDescendantAttribute = "data-is-active-descendant";
29
30
  export declare const activeDescendantActivatedDirectly = "activated-directly";
@@ -121,7 +121,7 @@ export const activeDescendantActivatedDirectly = 'activated-directly';
121
121
  export const activeDescendantActivatedIndirectly = 'activated-indirectly';
122
122
  export const hasActiveDescendantAttribute = 'data-has-active-descendant';
123
123
  export function focusZone(container, settings) {
124
- var _a, _b, _c, _d;
124
+ var _a, _b, _c, _d, _e;
125
125
  const focusableElements = [];
126
126
  const savedTabIndex = new WeakMap();
127
127
  const bindKeys = (_a = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _a !== void 0 ? _a : ((settings === null || settings === void 0 ? void 0 : settings.getNextFocusable) ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
@@ -130,6 +130,7 @@ export function focusZone(container, settings) {
130
130
  const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
131
131
  const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
132
132
  let currentFocusedElement;
133
+ const preventScroll = (_d = settings === null || settings === void 0 ? void 0 : settings.preventScroll) !== null && _d !== void 0 ? _d : false;
133
134
  function getFirstFocusableElement() {
134
135
  return focusableElements[0];
135
136
  }
@@ -240,7 +241,7 @@ export function focusZone(container, settings) {
240
241
  childList: true
241
242
  });
242
243
  const controller = new AbortController();
243
- const signal = (_d = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _d !== void 0 ? _d : controller.signal;
244
+ const signal = (_e = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _e !== void 0 ? _e : controller.signal;
244
245
  signal.addEventListener('abort', () => {
245
246
  endFocusManagement(...focusableElements);
246
247
  });
@@ -253,7 +254,7 @@ export function focusZone(container, settings) {
253
254
  if (activeDescendantControl) {
254
255
  container.addEventListener('focusin', event => {
255
256
  if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
256
- activeDescendantControl.focus();
257
+ activeDescendantControl.focus({ preventScroll });
257
258
  updateFocusedElement(event.target);
258
259
  }
259
260
  });
@@ -297,7 +298,7 @@ export function focusZone(container, settings) {
297
298
  if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
298
299
  const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
299
300
  const targetElement = focusableElements[targetElementIndex];
300
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
301
+ targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus({ preventScroll });
301
302
  return;
302
303
  }
303
304
  else {
@@ -309,7 +310,7 @@ export function focusZone(container, settings) {
309
310
  const elementToFocus = focusInStrategy(event.relatedTarget);
310
311
  const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
311
312
  if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
312
- elementToFocus.focus();
313
+ elementToFocus.focus({ preventScroll });
313
314
  return;
314
315
  }
315
316
  else {
@@ -394,7 +395,7 @@ export function focusZone(container, settings) {
394
395
  }
395
396
  else if (nextElementToFocus) {
396
397
  lastKeyboardFocusDirection = direction;
397
- nextElementToFocus.focus();
398
+ nextElementToFocus.focus({ preventScroll });
398
399
  }
399
400
  if (event.key !== 'Tab' || nextElementToFocus) {
400
401
  event.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "1.2.0-rc.5aa5da2",
3
+ "version": "1.3.0-rc.9cf9e61",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",