@enonic/ui 0.49.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ import { RefObject } from 'react';
2
+ type VirtuosoLikeHandle = {
3
+ scrollToIndex: (location: number | {
4
+ index: number;
5
+ align?: 'start' | 'center' | 'end';
6
+ behavior?: 'auto' | 'smooth';
7
+ }) => void;
8
+ };
9
+ export type UseScrollSelectedToVirtuosoConfig<TItem extends {
10
+ id: string;
11
+ }> = {
12
+ /** Whether the dropdown is open. The hook fires on the rising edge. */
13
+ open: boolean;
14
+ /** The single selected ID to center on open, or undefined to skip. */
15
+ selectedId: string | undefined;
16
+ /**
17
+ * Setter called with `selectedId` on the rising edge so navigation
18
+ * resumes from there. Pass the active setter from the wrapped list
19
+ * (e.g., `VirtualizedTreeList`'s `onActiveChange` consumer).
20
+ */
21
+ setActive: (id: string) => void;
22
+ /** Flat items in render order. Used to look up the index for `scrollToIndex`. */
23
+ items: readonly TItem[];
24
+ /** Ref to the Virtuoso instance for scroll operations. */
25
+ virtuosoRef: RefObject<VirtuosoLikeHandle | null> | undefined;
26
+ };
27
+ /**
28
+ * Centers the selected item in a Virtuoso-backed virtualized list when its
29
+ * containing dropdown opens, and sets the consumer's active state to match.
30
+ *
31
+ * Retries on `requestAnimationFrame` while the Virtuoso ref is still null
32
+ * (Virtuoso typically attaches within a frame of mount). Bails after a small
33
+ * cap to avoid infinite loops.
34
+ *
35
+ * Use inside a consumer that wraps `VirtualizedTreeList` in `Combobox.TreeContent`
36
+ * (or any other open/close container) when the same UX as `Combobox.ListContent`
37
+ * is desired: open with selection → centered, arrow keys → nearest.
38
+ */
39
+ export declare function useScrollSelectedToVirtuoso<TItem extends {
40
+ id: string;
41
+ }>({ open, selectedId, setActive, items, virtuosoRef, }: UseScrollSelectedToVirtuosoConfig<TItem>): void;
42
+ export {};
@@ -29,6 +29,12 @@ export type ComboboxContextValue = {
29
29
  isItemDisabled: (id: string) => boolean;
30
30
  hasValue: boolean;
31
31
  setHasValue: (has: boolean) => void;
32
+ /**
33
+ * Whether the auto-active-on-open behavior should run inside Listbox-backed
34
+ * content. Set to `false` when active state is consumer-controlled. Tree
35
+ * content doesn't use this — see `useScrollSelectedToVirtuoso` instead.
36
+ */
37
+ autoActiveOnOpen: boolean;
32
38
  };
33
39
  export type ComboboxProviderProps = {
34
40
  value: ComboboxContextValue;
@@ -26,6 +26,11 @@ export type ListboxContextValue = {
26
26
  unregisterItem: (id: string) => void;
27
27
  getItems: () => string[];
28
28
  isItemDisabled: (id: string) => boolean;
29
+ /**
30
+ * When `false`, `useActiveOnOpen` in `Listbox.Content` is skipped. Set
31
+ * by hosts (e.g., Combobox) when the consumer controls active state.
32
+ */
33
+ autoActiveOnOpen: boolean;
29
34
  };
30
35
  export type ListboxProviderProps = {
31
36
  value: ListboxContextValue;
@@ -9,6 +9,7 @@ export type VirtualizedTreeListContextValue = {
9
9
  toggleSelection: (id: string, index: number) => void;
10
10
  selectionMode: 'single' | 'multiple' | 'none';
11
11
  isFocused: boolean;
12
+ keyboardActive: boolean;
12
13
  items: readonly FlatNodeBase[];
13
14
  getItemIndex: (id: string) => number;
14
15
  scrollToIndex: (index: number) => void;
@@ -2,4 +2,5 @@ export * from './aria';
2
2
  export * from './cn';
3
3
  export * from './mobile';
4
4
  export * from './ref';
5
+ export * from './scroll';
5
6
  export * from './unwrap';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Scrolls an element to the center of its nearest scrollable ancestor without
3
+ * disturbing outer scroll containers (page, dialog, etc.).
4
+ *
5
+ * - Chromium 134+ uses `scrollIntoView({ block: 'center', container: 'nearest' })`
6
+ * and centers the element within the closest scroll container only.
7
+ * - Other browsers fall back to `scrollIntoView({ block: 'nearest' })` — the
8
+ * element lands at the closest edge instead of the center, but ancestors
9
+ * that already show it stay put.
10
+ *
11
+ * Useful for dropdowns: bring the selected option into view on open without
12
+ * scrolling the page underneath.
13
+ */
14
+ export declare function scrollIntoCenter(element: HTMLElement): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enonic/ui",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "Enonic UI Component Library",
5
5
  "author": "Enonic",
6
6
  "license": "MIT",