@momentum-design/components 0.134.18 → 0.134.19

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.
@@ -6,7 +6,7 @@ import { ShortestDistanceWeights, SpatialNavigationContextValue, SpatialNavigati
6
6
  * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among
7
7
  * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.
8
8
  *
9
- * It should have only one instance and it should placed at the root of the application.
9
+ * It should have only one instance, and it should be placed at the root of the application.
10
10
  *
11
11
  * ## Focus management
12
12
  *
@@ -18,18 +18,21 @@ import { ShortestDistanceWeights, SpatialNavigationContextValue, SpatialNavigati
18
18
  * Spatial navigation goes through the following steps after each keydown:
19
19
  *
20
20
  * 1. Handle `keydown` in the capture phase.
21
- * - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the
22
- * provider's own `keydown` handler (see step 3).
21
+ * - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).
22
+ * Falls back to component navigation provider did not handle the event.
23
23
  * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not
24
24
  * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the
25
25
  * scroll view.
26
26
  * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not
27
27
  * prevented.
28
28
  * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)
29
- * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle
29
+ * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle
30
30
  * the key event itself. If `navbeforeprocess` event is prevented, stop here.
31
31
  * - If the component did not handle `keydown`, it calculates the next focusable item
32
- * - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.
32
+ * - If the active element has a `data-spatial-{direction}` attribute,
33
+ * - Evaluate the attribute value, try element ID, and falls back to css selector if needed
34
+ * - If it is focusable, move the focus there.
35
+ * - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.
33
36
  * - Otherwise calculate the next focused item based on the direction and distances.
34
37
  * - If there is no next item, it emits `navnotarget` event
35
38
  * - Otherwise emit `navbeforefocus`,
@@ -105,17 +108,17 @@ import { ShortestDistanceWeights, SpatialNavigationContextValue, SpatialNavigati
105
108
  *
106
109
  * Supported data attributes:
107
110
  *
108
- * | Attribute | Value | Default | Description |
109
- * |------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
110
- * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
111
- * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
112
- * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
113
- * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
114
- * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
115
- * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
116
- * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
117
- * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
118
- * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
111
+ * | Attribute | Value | Default | Description |
112
+ * |------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
113
+ * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
114
+ * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
115
+ * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
116
+ * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
117
+ * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
118
+ * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
119
+ * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
120
+ * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
121
+ * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
119
122
  *
120
123
  * ## Event emitting order
121
124
  *
@@ -358,7 +361,7 @@ declare class SpatialNavigationProvider extends Provider<SpatialNavigationContex
358
361
  * @internal
359
362
  */
360
363
  private getActiveElement;
361
- private handleKeyDownBefore;
364
+ private handleKeyDownCapture;
362
365
  /**
363
366
  * Handle keydown event
364
367
  *
@@ -22,7 +22,7 @@ import { SpatialNavigationEvent } from './spatialnavigationprovider.events';
22
22
  * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among
23
23
  * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.
24
24
  *
25
- * It should have only one instance and it should placed at the root of the application.
25
+ * It should have only one instance, and it should be placed at the root of the application.
26
26
  *
27
27
  * ## Focus management
28
28
  *
@@ -34,18 +34,21 @@ import { SpatialNavigationEvent } from './spatialnavigationprovider.events';
34
34
  * Spatial navigation goes through the following steps after each keydown:
35
35
  *
36
36
  * 1. Handle `keydown` in the capture phase.
37
- * - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the
38
- * provider's own `keydown` handler (see step 3).
37
+ * - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).
38
+ * Falls back to component navigation provider did not handle the event.
39
39
  * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not
40
40
  * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the
41
41
  * scroll view.
42
42
  * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not
43
43
  * prevented.
44
44
  * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)
45
- * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle
45
+ * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle
46
46
  * the key event itself. If `navbeforeprocess` event is prevented, stop here.
47
47
  * - If the component did not handle `keydown`, it calculates the next focusable item
48
- * - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.
48
+ * - If the active element has a `data-spatial-{direction}` attribute,
49
+ * - Evaluate the attribute value, try element ID, and falls back to css selector if needed
50
+ * - If it is focusable, move the focus there.
51
+ * - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.
49
52
  * - Otherwise calculate the next focused item based on the direction and distances.
50
53
  * - If there is no next item, it emits `navnotarget` event
51
54
  * - Otherwise emit `navbeforefocus`,
@@ -121,17 +124,17 @@ import { SpatialNavigationEvent } from './spatialnavigationprovider.events';
121
124
  *
122
125
  * Supported data attributes:
123
126
  *
124
- * | Attribute | Value | Default | Description |
125
- * |------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
126
- * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
127
- * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
128
- * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
129
- * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
130
- * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
131
- * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
132
- * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
133
- * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
134
- * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
127
+ * | Attribute | Value | Default | Description |
128
+ * |------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
129
+ * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
130
+ * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
131
+ * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
132
+ * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
133
+ * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
134
+ * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
135
+ * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
136
+ * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
137
+ * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
135
138
  *
136
139
  * ## Event emitting order
137
140
  *
@@ -300,7 +303,7 @@ class SpatialNavigationProvider extends Provider {
300
303
  * @internal
301
304
  */
302
305
  this.initialHistoryLength = window.history.length;
303
- this.handleKeyDownBefore = (evt) => {
306
+ this.handleKeyDownCapture = (evt) => {
304
307
  var _a;
305
308
  if (evt.shiftKey || evt.ctrlKey || evt.altKey || evt.metaKey || !this.isNavigationKey(evt.key)) {
306
309
  return;
@@ -311,8 +314,7 @@ class SpatialNavigationProvider extends Provider {
311
314
  if (this.isDirectionKey(evt.key) &&
312
315
  this.getElementSelectorForDirectionAttr(target, action) !== undefined) {
313
316
  eventHandled = true;
314
- // Need to call Spatial navigation key handler manually after all propagation stopped
315
- this.handleKeyDown(evt);
317
+ this.focusNext(evt, action);
316
318
  }
317
319
  // Handle over sized elements inside scrollable area
318
320
  if (target.parentElement && !target.hasAttribute(DATA_ATTRIBUTES.NO_SCROLL)) {
@@ -442,14 +444,14 @@ class SpatialNavigationProvider extends Provider {
442
444
  }
443
445
  connectedCallback() {
444
446
  super.connectedCallback();
445
- document.addEventListener('keydown', this.handleKeyDownBefore, { capture: true });
447
+ document.addEventListener('keydown', this.handleKeyDownCapture, { capture: true });
446
448
  document.addEventListener('keydown', this.handleKeyDown);
447
449
  document.addEventListener('focus', this.handleFocus);
448
450
  this.initActiveElement();
449
451
  }
450
452
  disconnectedCallback() {
451
453
  super.disconnectedCallback();
452
- document.removeEventListener('keydown', this.handleKeyDownBefore, { capture: true });
454
+ document.removeEventListener('keydown', this.handleKeyDownCapture, { capture: true });
453
455
  document.removeEventListener('keydown', this.handleKeyDown);
454
456
  document.removeEventListener('focus', this.handleFocus);
455
457
  this.activeElement = undefined;
@@ -581,7 +583,7 @@ class SpatialNavigationProvider extends Provider {
581
583
  let focusableElements = elements;
582
584
  // Sync current active element if necessary
583
585
  // It can be out of sync when:
584
- // - the component handled the navigation (programmatically focused another element) so DOM active element is different
586
+ // - the component handled the navigation (programmatically focused another element), so DOM active element is different
585
587
  // - focus fallback to body or other non-focusable element
586
588
  if (!currentActiveElement ||
587
589
  !focusableElements.includes(currentActiveElement) ||
@@ -605,17 +607,22 @@ class SpatialNavigationProvider extends Provider {
605
607
  const root = elementWithDataset.getRootNode();
606
608
  const nextElement = (_a = root === null || root === void 0 ? void 0 : root.getElementById(nextElementSelector)) !== null && _a !== void 0 ? _a : root === null || root === void 0 ? void 0 : root.querySelector(nextElementSelector);
607
609
  if (nextElement) {
608
- const focusableAroundNextElement = findFocusable(nextElement.parentElement, {
610
+ const focusableAroundNextElement = findFocusable(nextElement, {
609
611
  includeSelectors: [`[${DATA_ATTRIBUTES.FOCUSABLE}]`],
610
612
  excludeSelectors: [`[${DATA_ATTRIBUTES.EXCLUDE}]`],
611
613
  });
612
- const isNextElementInFocusables = focusableAroundNextElement.includes(nextElement);
613
- focusableElements = focusableAroundNextElement.filter(el => nextElement.contains(el) && el !== nextElement);
614
- if (isNextElementInFocusables || focusableElements.length <= 0) {
615
- // Use nextElement if it focusable
614
+ const isNextElementFocusable = focusableAroundNextElement.includes(nextElement);
615
+ // Use nextElement if it focusable
616
+ if (isNextElementFocusable)
617
+ return nextElement;
618
+ // Fall back to the distance-based navigation but search within the targeted element subtree only.
619
+ if (focusableAroundNextElement.length > 0) {
620
+ focusableElements = focusableAroundNextElement;
621
+ }
622
+ else {
623
+ // Focus it anyway
616
624
  return nextElement;
617
625
  }
618
- // Else, fall back to the distance based navigation but search within the targeted element subtree only.
619
626
  }
620
627
  }
621
628
  }
@@ -44925,7 +44925,7 @@
44925
44925
  "declarations": [
44926
44926
  {
44927
44927
  "kind": "class",
44928
- "description": "Spatial navigation focus manager\n\n[Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among\nelements on a 2D plane, common on TVs and game consoles with remotes or gamepads.\n\nIt should have only one instance and it should placed at the root of the application.\n\n## Focus management\n\nThe provider listens to keyboard events and moves focus among elements based on arrow key input.\nYou can influence or override this behavior.\n\n### Steps\n\nSpatial navigation goes through the following steps after each keydown:\n\n1. Handle `keydown` in the capture phase.\n - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the\n provider's own `keydown` handler (see step 3).\n - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not\n have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the\n scroll view.\n2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not\n prevented.\n3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)\n - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle\n the key event itself. If `navbeforeprocess` event is prevented, stop here.\n - If the component did not handle `keydown`, it calculates the next focusable item\n - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.\n - Otherwise calculate the next focused item based on the direction and distances.\n - If there is no next item, it emits `navnotarget` event\n - Otherwise emit `navbeforefocus`,\n - If this event is prevented, nothing happens\n - Otherwise the focus moves to the next element\n\n### Determine next focus\n\nThe provider uses multiple ways to determine the next focused element. The order defined in the \"Steps\" section.\n\n#### Calculated focus\n\nBy default, the next focus target is computed from element positions:\n\n1. Find the nearest focus area (scrollable container or active focus trap) relative to the current element.\n2. Collect focusable elements in that area.\n3. Compute distances from the current element to candidates using the W3C \"find the shortest\n distance\" algorithm: https://www.w3.org/TR/css-nav-1/#find-the-shortest-distance\n4. If no candidates are found, repeat from step 1, skipping areas already checked.\n5. Focus on the closest candidate.\n\nElements with `data-spatial-focusable` are treated as focusable even if they do otherwise not be\n(e.g., `tabindex=\"-1\"`).\n\nElements with `data-spatial-exclude` are excluded (with its subtree) from the navigation, even if they\nare focusable.\n\nNote: The algorithm is distance-based, so the UI should be designed to focusable elements are\npredictably reachable. Relative element positions should remain stable; responsive layouts can\nmake navigation unpredictable. This is less of an issue on fixed-size TV UIs but can show unexpected\nbehavior in Storybook when resizing. See the \"Limitations\" section.\n\n#### Overwrite the next element\n\nOverride calculated navigation by adding one of these attributes to a focusable element:\n\n- `data-spatial-up`\n- `data-spatial-down`\n- `data-spatial-left`\n- `data-spatial-right`\n\nEach attribute value must be the id of the element to focus when the corresponding key is pressed.\n\n#### Element internal navigation\n\nComplex components (List, Combobox, Tree, etc.) may handle their own navigation. For example, a List moves\nfocus internally on Down until the last item, after which Down should fall back to provider navigation.\n\nTo prevent the provider from handling a key, listen to `navbeforeprocess` and call `event.preventDefault()`.\nThis event fires after the component handles `keydown`.\n\n### Cancel focus change\n\nBefore focusing a computed target, the provider dispatches `navbeforefocus` on the current element. Call\n`event.preventDefault()` on this event to cancel the focus change.\n\n## Enter action\n\nPressing Enter triggers `.click()` on the currently focused element.\n\nYou can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n\n## Escape/Back action\n\nPressing Escape tries to find a focusable element with `data-spatial-go-back` and clicks it. If none exists,\nthe provider calls `history.back()`.\n\nYou can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n\nYou can also intercept the back click by listening to `navback` and calling `event.preventDefault()`.\n\n## Control data attributes\n\nSupported data attributes:\n\n| Attribute | Value | Default | Description |\n|------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|\n| `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |\n| `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex=\"-1\"`) |\n| `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |\n| `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |\n| `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |\n\n## Event emitting order\n\nOn a navigation key press, events fire in this order:\n\n1. `navbeforeprocess` on the currently focused element.\n2. If not prevented:\na. Arrow keys: `navbeforefocus` on the currently focused element.\nb. Enter: `.click()` on the currently focused element.\nc. Escape/Back: `navback` on the provider, then `.click()` on the go-back element or `history.back()`.\n3. If no target is found in the requested direction: `navnotarget` on the provider.\n\n## Handle complex components\n\n### Generic components\n\nComponents that handle navigation internally should prevent the provider from acting. Handle `navbeforeprocess`\nand call `event.preventDefault()` for keys you process yourself.\n\n### Form inputs\n\nNative inputs often submit on Enter, which is not desirable here. Enter should toggle or activate the control\n(e.g., check/uncheck). Provide a dedicated submit button users can navigate to and press Enter on.\n\n### Utilities for complex components\n\n#### KeyToActionMixin\n\nMaps key events to action names. Call `getActionForKeyEvent` to get the action for a keyboard event. Also provides\n`getKeyboardNavMode` to check whether navigation is spatial or default.\n\n#### KeyDownHandledMixin\n\nNotify the provider when a component handled `keydown` internally. Call `keyDownEventHandled` whenever you process\nkeydown yourself.\n\n## Platform specific behaviors\n\nConsider remote/gamepad constraints. Often focus alone is not enough, and users press Enter to \"enter\" an interactive mode:\n- Select: Enter opens options rather than arrow keys opening a popover.\n- Text inputs: see the next section.\n- Slider: Enter to start adjusting, arrow keys to change value, Enter/Escape to stop.\n\n### Text inputs\n\nOn TV-like platforms without physical keyboards, Enter/focus on an input should open a virtual keyboard instead of submitting\nthe form. Users must close the keyboard (Escape) to continue spatial navigation.\n\nIf navigation keys are mapped to letters (e.g., `w/a/s/d`), they should navigate, not change input values. Inputs should\nbe edited via the virtual keyboard.\n\nNote: Stories do not emulate virtual keyboards, so letter-based navigation may change input values in Storybook.\n\n## Debugging\n\n### Storybook toolbar\n\nEnable \"Spatial navigation\" in the toolbar. Key mapping:\n- Up - ArrowUp\n- Left - ArrowLeft\n- Down - ArrowDown\n- Right - ArrowRight\n- Enter - Enter\n- Escape - Escape\n\nWith wrapper: wraps the component in a 3x3 grid with surrounding buttons for testing.\nWithout a wrapper: renders the component alone.\n\n### Visual debugger\n\nWith spatial navigation enabled, press Shift + navigation key to visualize calculations:\n\n- Star: next active element\n- `#{number}`: candidate order by distance\n- `D: {distance}`: computed distance\n\n## Limitations\n\n### Completeness\n\nThe algorithm cannot guarantee reachability to all elements using the four directions. Some components can be isolated.\n\nWorkarounds:\n- Use data attributes to explicitly link navigation targets.\n- Arrange DOM to improve spatial consistency:\n- Group focusable elements using dedicated components (lists, menus, etc.).\n- Avoid complex grid-like layouts with variable-sized items.\n- Avoid overlap along horizontal or vertical axes.\n- Avoid nested focusable elements where possible.\n- Tune algorithm weights to match your UI layout.\n\n### Nested providers\n\nOnly one provider instance is supported in the application at a time.",
44928
+ "description": "Spatial navigation focus manager\n\n[Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among\nelements on a 2D plane, common on TVs and game consoles with remotes or gamepads.\n\nIt should have only one instance, and it should be placed at the root of the application.\n\n## Focus management\n\nThe provider listens to keyboard events and moves focus among elements based on arrow key input.\nYou can influence or override this behavior.\n\n### Steps\n\nSpatial navigation goes through the following steps after each keydown:\n\n1. Handle `keydown` in the capture phase.\n - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).\n Falls back to component navigation provider did not handle the event.\n - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not\n have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the\n scroll view.\n2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not\n prevented.\n3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)\n - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle\n the key event itself. If `navbeforeprocess` event is prevented, stop here.\n - If the component did not handle `keydown`, it calculates the next focusable item\n - If the active element has a `data-spatial-{direction}` attribute,\n - Evaluate the attribute value, try element ID, and falls back to css selector if needed\n - If it is focusable, move the focus there.\n - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.\n - Otherwise calculate the next focused item based on the direction and distances.\n - If there is no next item, it emits `navnotarget` event\n - Otherwise emit `navbeforefocus`,\n - If this event is prevented, nothing happens\n - Otherwise the focus moves to the next element\n\n### Determine next focus\n\nThe provider uses multiple ways to determine the next focused element. The order defined in the \"Steps\" section.\n\n#### Calculated focus\n\nBy default, the next focus target is computed from element positions:\n\n1. Find the nearest focus area (scrollable container or active focus trap) relative to the current element.\n2. Collect focusable elements in that area.\n3. Compute distances from the current element to candidates using the W3C \"find the shortest\n distance\" algorithm: https://www.w3.org/TR/css-nav-1/#find-the-shortest-distance\n4. If no candidates are found, repeat from step 1, skipping areas already checked.\n5. Focus on the closest candidate.\n\nElements with `data-spatial-focusable` are treated as focusable even if they do otherwise not be\n(e.g., `tabindex=\"-1\"`).\n\nElements with `data-spatial-exclude` are excluded (with its subtree) from the navigation, even if they\nare focusable.\n\nNote: The algorithm is distance-based, so the UI should be designed to focusable elements are\npredictably reachable. Relative element positions should remain stable; responsive layouts can\nmake navigation unpredictable. This is less of an issue on fixed-size TV UIs but can show unexpected\nbehavior in Storybook when resizing. See the \"Limitations\" section.\n\n#### Overwrite the next element\n\nOverride calculated navigation by adding one of these attributes to a focusable element:\n\n- `data-spatial-up`\n- `data-spatial-down`\n- `data-spatial-left`\n- `data-spatial-right`\n\nEach attribute value must be the id of the element to focus when the corresponding key is pressed.\n\n#### Element internal navigation\n\nComplex components (List, Combobox, Tree, etc.) may handle their own navigation. For example, a List moves\nfocus internally on Down until the last item, after which Down should fall back to provider navigation.\n\nTo prevent the provider from handling a key, listen to `navbeforeprocess` and call `event.preventDefault()`.\nThis event fires after the component handles `keydown`.\n\n### Cancel focus change\n\nBefore focusing a computed target, the provider dispatches `navbeforefocus` on the current element. Call\n`event.preventDefault()` on this event to cancel the focus change.\n\n## Enter action\n\nPressing Enter triggers `.click()` on the currently focused element.\n\nYou can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n\n## Escape/Back action\n\nPressing Escape tries to find a focusable element with `data-spatial-go-back` and clicks it. If none exists,\nthe provider calls `history.back()`.\n\nYou can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n\nYou can also intercept the back click by listening to `navback` and calling `event.preventDefault()`.\n\n## Control data attributes\n\nSupported data attributes:\n\n| Attribute | Value | Default | Description |\n|------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|\n| `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |\n| `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |\n| `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex=\"-1\"`) |\n| `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |\n| `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |\n| `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |\n\n## Event emitting order\n\nOn a navigation key press, events fire in this order:\n\n1. `navbeforeprocess` on the currently focused element.\n2. If not prevented:\na. Arrow keys: `navbeforefocus` on the currently focused element.\nb. Enter: `.click()` on the currently focused element.\nc. Escape/Back: `navback` on the provider, then `.click()` on the go-back element or `history.back()`.\n3. If no target is found in the requested direction: `navnotarget` on the provider.\n\n## Handle complex components\n\n### Generic components\n\nComponents that handle navigation internally should prevent the provider from acting. Handle `navbeforeprocess`\nand call `event.preventDefault()` for keys you process yourself.\n\n### Form inputs\n\nNative inputs often submit on Enter, which is not desirable here. Enter should toggle or activate the control\n(e.g., check/uncheck). Provide a dedicated submit button users can navigate to and press Enter on.\n\n### Utilities for complex components\n\n#### KeyToActionMixin\n\nMaps key events to action names. Call `getActionForKeyEvent` to get the action for a keyboard event. Also provides\n`getKeyboardNavMode` to check whether navigation is spatial or default.\n\n#### KeyDownHandledMixin\n\nNotify the provider when a component handled `keydown` internally. Call `keyDownEventHandled` whenever you process\nkeydown yourself.\n\n## Platform specific behaviors\n\nConsider remote/gamepad constraints. Often focus alone is not enough, and users press Enter to \"enter\" an interactive mode:\n- Select: Enter opens options rather than arrow keys opening a popover.\n- Text inputs: see the next section.\n- Slider: Enter to start adjusting, arrow keys to change value, Enter/Escape to stop.\n\n### Text inputs\n\nOn TV-like platforms without physical keyboards, Enter/focus on an input should open a virtual keyboard instead of submitting\nthe form. Users must close the keyboard (Escape) to continue spatial navigation.\n\nIf navigation keys are mapped to letters (e.g., `w/a/s/d`), they should navigate, not change input values. Inputs should\nbe edited via the virtual keyboard.\n\nNote: Stories do not emulate virtual keyboards, so letter-based navigation may change input values in Storybook.\n\n## Debugging\n\n### Storybook toolbar\n\nEnable \"Spatial navigation\" in the toolbar. Key mapping:\n- Up - ArrowUp\n- Left - ArrowLeft\n- Down - ArrowDown\n- Right - ArrowRight\n- Enter - Enter\n- Escape - Escape\n\nWith wrapper: wraps the component in a 3x3 grid with surrounding buttons for testing.\nWithout a wrapper: renders the component alone.\n\n### Visual debugger\n\nWith spatial navigation enabled, press Shift + navigation key to visualize calculations:\n\n- Star: next active element\n- `#{number}`: candidate order by distance\n- `D: {distance}`: computed distance\n\n## Limitations\n\n### Completeness\n\nThe algorithm cannot guarantee reachability to all elements using the four directions. Some components can be isolated.\n\nWorkarounds:\n- Use data attributes to explicitly link navigation targets.\n- Arrange DOM to improve spatial consistency:\n- Group focusable elements using dedicated components (lists, menus, etc.).\n- Avoid complex grid-like layouts with variable-sized items.\n- Avoid overlap along horizontal or vertical axes.\n- Avoid nested focusable elements where possible.\n- Tune algorithm weights to match your UI layout.\n\n### Nested providers\n\nOnly one provider instance is supported in the application at a time.",
44929
44929
  "name": "SpatialNavigationProvider",
44930
44930
  "members": [
44931
44931
  {
@@ -44990,7 +44990,7 @@
44990
44990
  },
44991
44991
  {
44992
44992
  "kind": "field",
44993
- "name": "handleKeyDownBefore",
44993
+ "name": "handleKeyDownCapture",
44994
44994
  "privacy": "private"
44995
44995
  },
44996
44996
  {
@@ -45087,7 +45087,7 @@
45087
45087
  "module": "/src/models"
45088
45088
  },
45089
45089
  "tagName": "mdc-spatialnavigationprovider",
45090
- "jsDoc": "/**\n * Spatial navigation focus manager\n *\n * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among\n * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.\n *\n * It should have only one instance and it should placed at the root of the application.\n *\n * ## Focus management\n *\n * The provider listens to keyboard events and moves focus among elements based on arrow key input.\n * You can influence or override this behavior.\n *\n * ### Steps\n *\n * Spatial navigation goes through the following steps after each keydown:\n *\n * 1. Handle `keydown` in the capture phase.\n * - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the\n * provider's own `keydown` handler (see step 3).\n * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not\n * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the\n * scroll view.\n * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not\n * prevented.\n * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)\n * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle\n * the key event itself. If `navbeforeprocess` event is prevented, stop here.\n * - If the component did not handle `keydown`, it calculates the next focusable item\n * - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.\n * - Otherwise calculate the next focused item based on the direction and distances.\n * - If there is no next item, it emits `navnotarget` event\n * - Otherwise emit `navbeforefocus`,\n * - If this event is prevented, nothing happens\n * - Otherwise the focus moves to the next element\n *\n * ### Determine next focus\n *\n * The provider uses multiple ways to determine the next focused element. The order defined in the \"Steps\" section.\n *\n * #### Calculated focus\n *\n * By default, the next focus target is computed from element positions:\n *\n * 1. Find the nearest focus area (scrollable container or active focus trap) relative to the current element.\n * 2. Collect focusable elements in that area.\n * 3. Compute distances from the current element to candidates using the W3C \"find the shortest\n * distance\" algorithm: https://www.w3.org/TR/css-nav-1/#find-the-shortest-distance\n * 4. If no candidates are found, repeat from step 1, skipping areas already checked.\n * 5. Focus on the closest candidate.\n *\n * Elements with `data-spatial-focusable` are treated as focusable even if they do otherwise not be\n * (e.g., `tabindex=\"-1\"`).\n *\n * Elements with `data-spatial-exclude` are excluded (with its subtree) from the navigation, even if they\n * are focusable.\n *\n * Note: The algorithm is distance-based, so the UI should be designed to focusable elements are\n * predictably reachable. Relative element positions should remain stable; responsive layouts can\n * make navigation unpredictable. This is less of an issue on fixed-size TV UIs but can show unexpected\n * behavior in Storybook when resizing. See the \"Limitations\" section.\n *\n * #### Overwrite the next element\n *\n * Override calculated navigation by adding one of these attributes to a focusable element:\n *\n * - `data-spatial-up`\n * - `data-spatial-down`\n * - `data-spatial-left`\n * - `data-spatial-right`\n *\n * Each attribute value must be the id of the element to focus when the corresponding key is pressed.\n *\n * #### Element internal navigation\n *\n * Complex components (List, Combobox, Tree, etc.) may handle their own navigation. For example, a List moves\n * focus internally on Down until the last item, after which Down should fall back to provider navigation.\n *\n * To prevent the provider from handling a key, listen to `navbeforeprocess` and call `event.preventDefault()`.\n * This event fires after the component handles `keydown`.\n *\n * ### Cancel focus change\n *\n * Before focusing a computed target, the provider dispatches `navbeforefocus` on the current element. Call\n * `event.preventDefault()` on this event to cancel the focus change.\n *\n * ## Enter action\n *\n * Pressing Enter triggers `.click()` on the currently focused element.\n *\n * You can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n *\n * ## Escape/Back action\n *\n * Pressing Escape tries to find a focusable element with `data-spatial-go-back` and clicks it. If none exists,\n * the provider calls `history.back()`.\n *\n * You can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n *\n * You can also intercept the back click by listening to `navback` and calling `event.preventDefault()`.\n *\n * ## Control data attributes\n *\n * Supported data attributes:\n *\n * | Attribute | Value | Default | Description |\n * |------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|\n * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |\n * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex=\"-1\"`) |\n * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |\n * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |\n * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |\n *\n * ## Event emitting order\n *\n * On a navigation key press, events fire in this order:\n *\n * 1. `navbeforeprocess` on the currently focused element.\n * 2. If not prevented:\n * a. Arrow keys: `navbeforefocus` on the currently focused element.\n * b. Enter: `.click()` on the currently focused element.\n * c. Escape/Back: `navback` on the provider, then `.click()` on the go-back element or `history.back()`.\n * 3. If no target is found in the requested direction: `navnotarget` on the provider.\n *\n * ## Handle complex components\n *\n * ### Generic components\n *\n * Components that handle navigation internally should prevent the provider from acting. Handle `navbeforeprocess`\n * and call `event.preventDefault()` for keys you process yourself.\n *\n * ### Form inputs\n *\n * Native inputs often submit on Enter, which is not desirable here. Enter should toggle or activate the control\n * (e.g., check/uncheck). Provide a dedicated submit button users can navigate to and press Enter on.\n *\n * ### Utilities for complex components\n *\n * #### KeyToActionMixin\n *\n * Maps key events to action names. Call `getActionForKeyEvent` to get the action for a keyboard event. Also provides\n * `getKeyboardNavMode` to check whether navigation is spatial or default.\n *\n * #### KeyDownHandledMixin\n *\n * Notify the provider when a component handled `keydown` internally. Call `keyDownEventHandled` whenever you process\n * keydown yourself.\n *\n * ## Platform specific behaviors\n *\n * Consider remote/gamepad constraints. Often focus alone is not enough, and users press Enter to \"enter\" an interactive mode:\n * - Select: Enter opens options rather than arrow keys opening a popover.\n * - Text inputs: see the next section.\n * - Slider: Enter to start adjusting, arrow keys to change value, Enter/Escape to stop.\n *\n * ### Text inputs\n *\n * On TV-like platforms without physical keyboards, Enter/focus on an input should open a virtual keyboard instead of submitting\n * the form. Users must close the keyboard (Escape) to continue spatial navigation.\n *\n * If navigation keys are mapped to letters (e.g., `w/a/s/d`), they should navigate, not change input values. Inputs should\n * be edited via the virtual keyboard.\n *\n * Note: Stories do not emulate virtual keyboards, so letter-based navigation may change input values in Storybook.\n *\n * ## Debugging\n *\n * ### Storybook toolbar\n *\n * Enable \"Spatial navigation\" in the toolbar. Key mapping:\n * - Up - ArrowUp\n * - Left - ArrowLeft\n * - Down - ArrowDown\n * - Right - ArrowRight\n * - Enter - Enter\n * - Escape - Escape\n *\n * With wrapper: wraps the component in a 3x3 grid with surrounding buttons for testing.\n * Without a wrapper: renders the component alone.\n *\n * ### Visual debugger\n *\n * With spatial navigation enabled, press Shift + navigation key to visualize calculations:\n *\n * - Star: next active element\n * - `#{number}`: candidate order by distance\n * - `D: {distance}`: computed distance\n *\n * ## Limitations\n *\n * ### Completeness\n *\n * The algorithm cannot guarantee reachability to all elements using the four directions. Some components can be isolated.\n *\n * Workarounds:\n * - Use data attributes to explicitly link navigation targets.\n * - Arrange DOM to improve spatial consistency:\n * - Group focusable elements using dedicated components (lists, menus, etc.).\n * - Avoid complex grid-like layouts with variable-sized items.\n * - Avoid overlap along horizontal or vertical axes.\n * - Avoid nested focusable elements where possible.\n * - Tune algorithm weights to match your UI layout.\n *\n * ### Nested providers\n *\n * Only one provider instance is supported in the application at a time.\n *\n * @event navbeforeprocess - (React: onNavBeforeProcess) This event dispatched before spatial navigation process any key event.\n * It can be canceled to prevent any action from spatial navigation, e.g.: back, click or calculating the next candidate.\n * @event navbeforefocus - (React: onNavBeforeFocus) This event is dispatched before the focus is changing to the next element.\n * It can be canceled to prevent the focus change. @see https://www.w3.org/TR/css-nav-1/#event-type-navbeforefocus\n * @event navback - (React: onNavBack) This event dispatched a back navigation triggered by the user.\n * The event's detail contains the goBackElement if any. It is cancelable to prevent click\n * action on the goBackElement.\n * @event navnotarget - (React: onNavNoTarget) This event is dispatched when there is no target to focus in the current focus area and\n * in the given direction .\n *\n * @tagname mdc-spatialnavigationprovider\n */",
45090
+ "jsDoc": "/**\n * Spatial navigation focus manager\n *\n * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among\n * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.\n *\n * It should have only one instance, and it should be placed at the root of the application.\n *\n * ## Focus management\n *\n * The provider listens to keyboard events and moves focus among elements based on arrow key input.\n * You can influence or override this behavior.\n *\n * ### Steps\n *\n * Spatial navigation goes through the following steps after each keydown:\n *\n * 1. Handle `keydown` in the capture phase.\n * - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).\n * Falls back to component navigation provider did not handle the event.\n * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not\n * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the\n * scroll view.\n * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not\n * prevented.\n * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)\n * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle\n * the key event itself. If `navbeforeprocess` event is prevented, stop here.\n * - If the component did not handle `keydown`, it calculates the next focusable item\n * - If the active element has a `data-spatial-{direction}` attribute,\n * - Evaluate the attribute value, try element ID, and falls back to css selector if needed\n * - If it is focusable, move the focus there.\n * - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.\n * - Otherwise calculate the next focused item based on the direction and distances.\n * - If there is no next item, it emits `navnotarget` event\n * - Otherwise emit `navbeforefocus`,\n * - If this event is prevented, nothing happens\n * - Otherwise the focus moves to the next element\n *\n * ### Determine next focus\n *\n * The provider uses multiple ways to determine the next focused element. The order defined in the \"Steps\" section.\n *\n * #### Calculated focus\n *\n * By default, the next focus target is computed from element positions:\n *\n * 1. Find the nearest focus area (scrollable container or active focus trap) relative to the current element.\n * 2. Collect focusable elements in that area.\n * 3. Compute distances from the current element to candidates using the W3C \"find the shortest\n * distance\" algorithm: https://www.w3.org/TR/css-nav-1/#find-the-shortest-distance\n * 4. If no candidates are found, repeat from step 1, skipping areas already checked.\n * 5. Focus on the closest candidate.\n *\n * Elements with `data-spatial-focusable` are treated as focusable even if they do otherwise not be\n * (e.g., `tabindex=\"-1\"`).\n *\n * Elements with `data-spatial-exclude` are excluded (with its subtree) from the navigation, even if they\n * are focusable.\n *\n * Note: The algorithm is distance-based, so the UI should be designed to focusable elements are\n * predictably reachable. Relative element positions should remain stable; responsive layouts can\n * make navigation unpredictable. This is less of an issue on fixed-size TV UIs but can show unexpected\n * behavior in Storybook when resizing. See the \"Limitations\" section.\n *\n * #### Overwrite the next element\n *\n * Override calculated navigation by adding one of these attributes to a focusable element:\n *\n * - `data-spatial-up`\n * - `data-spatial-down`\n * - `data-spatial-left`\n * - `data-spatial-right`\n *\n * Each attribute value must be the id of the element to focus when the corresponding key is pressed.\n *\n * #### Element internal navigation\n *\n * Complex components (List, Combobox, Tree, etc.) may handle their own navigation. For example, a List moves\n * focus internally on Down until the last item, after which Down should fall back to provider navigation.\n *\n * To prevent the provider from handling a key, listen to `navbeforeprocess` and call `event.preventDefault()`.\n * This event fires after the component handles `keydown`.\n *\n * ### Cancel focus change\n *\n * Before focusing a computed target, the provider dispatches `navbeforefocus` on the current element. Call\n * `event.preventDefault()` on this event to cancel the focus change.\n *\n * ## Enter action\n *\n * Pressing Enter triggers `.click()` on the currently focused element.\n *\n * You can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n *\n * ## Escape/Back action\n *\n * Pressing Escape tries to find a focusable element with `data-spatial-go-back` and clicks it. If none exists,\n * the provider calls `history.back()`.\n *\n * You can prevent this by listening to `navbeforeprocess` and calling `event.preventDefault()`.\n *\n * You can also intercept the back click by listening to `navback` and calling `event.preventDefault()`.\n *\n * ## Control data attributes\n *\n * Supported data attributes:\n *\n * | Attribute | Value | Default | Description |\n * |------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|\n * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |\n * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |\n * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex=\"-1\"`) |\n * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |\n * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |\n * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |\n *\n * ## Event emitting order\n *\n * On a navigation key press, events fire in this order:\n *\n * 1. `navbeforeprocess` on the currently focused element.\n * 2. If not prevented:\n * a. Arrow keys: `navbeforefocus` on the currently focused element.\n * b. Enter: `.click()` on the currently focused element.\n * c. Escape/Back: `navback` on the provider, then `.click()` on the go-back element or `history.back()`.\n * 3. If no target is found in the requested direction: `navnotarget` on the provider.\n *\n * ## Handle complex components\n *\n * ### Generic components\n *\n * Components that handle navigation internally should prevent the provider from acting. Handle `navbeforeprocess`\n * and call `event.preventDefault()` for keys you process yourself.\n *\n * ### Form inputs\n *\n * Native inputs often submit on Enter, which is not desirable here. Enter should toggle or activate the control\n * (e.g., check/uncheck). Provide a dedicated submit button users can navigate to and press Enter on.\n *\n * ### Utilities for complex components\n *\n * #### KeyToActionMixin\n *\n * Maps key events to action names. Call `getActionForKeyEvent` to get the action for a keyboard event. Also provides\n * `getKeyboardNavMode` to check whether navigation is spatial or default.\n *\n * #### KeyDownHandledMixin\n *\n * Notify the provider when a component handled `keydown` internally. Call `keyDownEventHandled` whenever you process\n * keydown yourself.\n *\n * ## Platform specific behaviors\n *\n * Consider remote/gamepad constraints. Often focus alone is not enough, and users press Enter to \"enter\" an interactive mode:\n * - Select: Enter opens options rather than arrow keys opening a popover.\n * - Text inputs: see the next section.\n * - Slider: Enter to start adjusting, arrow keys to change value, Enter/Escape to stop.\n *\n * ### Text inputs\n *\n * On TV-like platforms without physical keyboards, Enter/focus on an input should open a virtual keyboard instead of submitting\n * the form. Users must close the keyboard (Escape) to continue spatial navigation.\n *\n * If navigation keys are mapped to letters (e.g., `w/a/s/d`), they should navigate, not change input values. Inputs should\n * be edited via the virtual keyboard.\n *\n * Note: Stories do not emulate virtual keyboards, so letter-based navigation may change input values in Storybook.\n *\n * ## Debugging\n *\n * ### Storybook toolbar\n *\n * Enable \"Spatial navigation\" in the toolbar. Key mapping:\n * - Up - ArrowUp\n * - Left - ArrowLeft\n * - Down - ArrowDown\n * - Right - ArrowRight\n * - Enter - Enter\n * - Escape - Escape\n *\n * With wrapper: wraps the component in a 3x3 grid with surrounding buttons for testing.\n * Without a wrapper: renders the component alone.\n *\n * ### Visual debugger\n *\n * With spatial navigation enabled, press Shift + navigation key to visualize calculations:\n *\n * - Star: next active element\n * - `#{number}`: candidate order by distance\n * - `D: {distance}`: computed distance\n *\n * ## Limitations\n *\n * ### Completeness\n *\n * The algorithm cannot guarantee reachability to all elements using the four directions. Some components can be isolated.\n *\n * Workarounds:\n * - Use data attributes to explicitly link navigation targets.\n * - Arrange DOM to improve spatial consistency:\n * - Group focusable elements using dedicated components (lists, menus, etc.).\n * - Avoid complex grid-like layouts with variable-sized items.\n * - Avoid overlap along horizontal or vertical axes.\n * - Avoid nested focusable elements where possible.\n * - Tune algorithm weights to match your UI layout.\n *\n * ### Nested providers\n *\n * Only one provider instance is supported in the application at a time.\n *\n * @event navbeforeprocess - (React: onNavBeforeProcess) This event dispatched before spatial navigation process any key event.\n * It can be canceled to prevent any action from spatial navigation, e.g.: back, click or calculating the next candidate.\n * @event navbeforefocus - (React: onNavBeforeFocus) This event is dispatched before the focus is changing to the next element.\n * It can be canceled to prevent the focus change. @see https://www.w3.org/TR/css-nav-1/#event-type-navbeforefocus\n * @event navback - (React: onNavBack) This event dispatched a back navigation triggered by the user.\n * The event's detail contains the goBackElement if any. It is cancelable to prevent click\n * action on the goBackElement.\n * @event navnotarget - (React: onNavNoTarget) This event is dispatched when there is no target to focus in the current focus area and\n * in the given direction .\n *\n * @tagname mdc-spatialnavigationprovider\n */",
45091
45091
  "customElement": true
45092
45092
  }
45093
45093
  ],
@@ -7,7 +7,7 @@ import type { Events } from '../../components/spatialnavigationprovider/spatialn
7
7
  * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among
8
8
  * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.
9
9
  *
10
- * It should have only one instance and it should placed at the root of the application.
10
+ * It should have only one instance, and it should be placed at the root of the application.
11
11
  *
12
12
  * ## Focus management
13
13
  *
@@ -19,18 +19,21 @@ import type { Events } from '../../components/spatialnavigationprovider/spatialn
19
19
  * Spatial navigation goes through the following steps after each keydown:
20
20
  *
21
21
  * 1. Handle `keydown` in the capture phase.
22
- * - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the
23
- * provider's own `keydown` handler (see step 3).
22
+ * - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).
23
+ * Falls back to component navigation provider did not handle the event.
24
24
  * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not
25
25
  * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the
26
26
  * scroll view.
27
27
  * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not
28
28
  * prevented.
29
29
  * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)
30
- * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle
30
+ * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle
31
31
  * the key event itself. If `navbeforeprocess` event is prevented, stop here.
32
32
  * - If the component did not handle `keydown`, it calculates the next focusable item
33
- * - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.
33
+ * - If the active element has a `data-spatial-{direction}` attribute,
34
+ * - Evaluate the attribute value, try element ID, and falls back to css selector if needed
35
+ * - If it is focusable, move the focus there.
36
+ * - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.
34
37
  * - Otherwise calculate the next focused item based on the direction and distances.
35
38
  * - If there is no next item, it emits `navnotarget` event
36
39
  * - Otherwise emit `navbeforefocus`,
@@ -106,17 +109,17 @@ import type { Events } from '../../components/spatialnavigationprovider/spatialn
106
109
  *
107
110
  * Supported data attributes:
108
111
  *
109
- * | Attribute | Value | Default | Description |
110
- * |------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
111
- * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
112
- * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
113
- * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
114
- * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
115
- * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
116
- * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
117
- * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
118
- * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
119
- * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
112
+ * | Attribute | Value | Default | Description |
113
+ * |------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
114
+ * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
115
+ * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
116
+ * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
117
+ * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
118
+ * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
119
+ * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
120
+ * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
121
+ * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
122
+ * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
120
123
  *
121
124
  * ## Event emitting order
122
125
  *
@@ -8,7 +8,7 @@ import { TAG_NAME } from '../../components/spatialnavigationprovider/spatialnavi
8
8
  * [Spatial navigation](https://en.wikipedia.org/wiki/Spatial_navigation) lets users move focus among
9
9
  * elements on a 2D plane, common on TVs and game consoles with remotes or gamepads.
10
10
  *
11
- * It should have only one instance and it should placed at the root of the application.
11
+ * It should have only one instance, and it should be placed at the root of the application.
12
12
  *
13
13
  * ## Focus management
14
14
  *
@@ -20,18 +20,21 @@ import { TAG_NAME } from '../../components/spatialnavigationprovider/spatialnavi
20
20
  * Spatial navigation goes through the following steps after each keydown:
21
21
  *
22
22
  * 1. Handle `keydown` in the capture phase.
23
- * - When the active element has a `data-spatial-{direction}` attribute, then prevent all component navigation and call the
24
- * provider's own `keydown` handler (see step 3).
23
+ * - When the active element has a `data-spatial-{direction}` attribute, call the provider's own `keydown` handler (see step 3).
24
+ * Falls back to component navigation provider did not handle the event.
25
25
  * - When the active element's parent is scrollable and it is not fully visible in the given direction, and it does not
26
26
  * have a `data-spatial-noscroll` attribute, prevent all navigation and scroll in the given direction half-size of the
27
27
  * scroll view.
28
28
  * 2. Component own `keydown` handler executed (bubble phase) (e.g., list moves focus internally) it it was not
29
29
  * prevented.
30
30
  * 3. Spatial Navigation Provider's `keydown` handler executed (bubble phase)
31
- * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component want to handle
31
+ * - If a key event was not prevented in step 1. emit `navbeforeprocess` to check if any component wants to handle
32
32
  * the key event itself. If `navbeforeprocess` event is prevented, stop here.
33
33
  * - If the component did not handle `keydown`, it calculates the next focusable item
34
- * - if the active element has a `data-spatial-{direction}` attribute, it will try to focus the element with the id.
34
+ * - If the active element has a `data-spatial-{direction}` attribute,
35
+ * - Evaluate the attribute value, try element ID, and falls back to css selector if needed
36
+ * - If it is focusable, move the focus there.
37
+ * - If it is not focusable and contains focusable elements, calculate the next focused item within that element subtree.
35
38
  * - Otherwise calculate the next focused item based on the direction and distances.
36
39
  * - If there is no next item, it emits `navnotarget` event
37
40
  * - Otherwise emit `navbeforefocus`,
@@ -107,17 +110,17 @@ import { TAG_NAME } from '../../components/spatialnavigationprovider/spatialnavi
107
110
  *
108
111
  * Supported data attributes:
109
112
  *
110
- * | Attribute | Value | Default | Description |
111
- * |------------------------------|-------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
112
- * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
113
- * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
114
- * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
115
- * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
116
- * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
117
- * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
118
- * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
119
- * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
120
- * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
113
+ * | Attribute | Value | Default | Description |
114
+ * |------------------------------|------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------|
115
+ * | `data-spatial-left` | empty string / id / selector | N/A | Prevent native navigation in the Left direction, focus it if it's focusable otherwise limit the search in the selected container. |
116
+ * | `data-spatial-up` | empty string / id / selector | N/A | Prevent native navigation in Up direction, focus it if it's focusable otherwise limit the search in the selected container. |
117
+ * | `data-spatial-right` | empty string / id / selector | N/A | Prevent native navigation in the Right direction, focus it if it's focusable otherwise limit the search in the selected container. |
118
+ * | `data-spatial-down` | empty string / id / selector | N/A | Prevent native navigation in Down direction, focus it if it's focusable otherwise limit the search in the selected container. |
119
+ * | `data-spatial-go-back` | N/A | N/A | First focusable element with this attribute is clicked on Back/Escape |
120
+ * | `data-spatial-focusable` | N/A | N/A | Treat element as focusable even if it normally is not (e.g., `tabindex="-1"`) |
121
+ * | `data-spatial-exclude` | N/A | N/A | Exclude focusable element (and its subtree) from the navigation |
122
+ * | `data-spatial-noscroll` | N/A | N/A | Prevent scroll for active element in scrollable area even if the is not fit in view |
123
+ * | `data-spatial-scroll-parent` | N/A | N/A | When the focusable item in not a direct child of the scrollable aria use this attribute to mark scrollable area element |
121
124
  *
122
125
  * ## Event emitting order
123
126
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.134.18",
4
+ "version": "0.134.19",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
7
7
  "npm": ">=8.0.0"