@trackunit/react-components 1.24.1 → 1.24.3

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/index.cjs.js CHANGED
@@ -2799,10 +2799,10 @@ const cvaPopoverTitleText = cssClassVarianceUtilities.cvaMerge(["flex-1", "text-
2799
2799
  * @param {PopoverContentProps} props - The props for the PopoverContent component
2800
2800
  * @returns {ReactElement} The popover content element
2801
2801
  */
2802
- const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, ref: propRef, ...props }) {
2802
+ const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, ref: propRef, ...props }) {
2803
2803
  const { context: floatingContext, customProps, ...context } = usePopoverContext();
2804
2804
  const ref = react$1.useMergeRefs([context.refs.setFloating, propRef]);
2805
- return (jsxRuntime.jsx(Portal, { id: portalId, children: context.isOpen === true ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { closeOnFocusOut: false, context: floatingContext, guards: true, modal: context.isModal, order: ["reference", "content"], returnFocus: true, children: jsxRuntime.jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
2805
+ return (jsxRuntime.jsx(Portal, { id: portalId, children: context.isOpen === true ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { closeOnFocusOut: false, context: floatingContext, guards: true, initialFocus: initialFocus, modal: context.isModal, order: ["reference", "content"], returnFocus: true, children: jsxRuntime.jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
2806
2806
  position: context.strategy,
2807
2807
  top: context.y,
2808
2808
  left: context.x,
@@ -11513,12 +11513,15 @@ const useContainerBreakpoints = (ref, options = {}) => {
11513
11513
  const { skip = false } = options;
11514
11514
  const [containerSize, setContainerSize] = react.useState(() => defaultBreakpointState);
11515
11515
  react.useEffect(() => {
11516
+ if (skip) {
11517
+ return;
11518
+ }
11516
11519
  if (process.env.NODE_ENV === "development" && !ref.current) {
11517
11520
  // eslint-disable-next-line no-console
11518
11521
  console.warn("useContainerBreakpoints: The provided ref is not attached to any element. " +
11519
11522
  "Make sure to pass the ref to an element using the ref prop, like: <div ref={myRef}>", "\nComponent:", ref.current);
11520
11523
  }
11521
- }, [ref]);
11524
+ }, [ref, skip]);
11522
11525
  const updateContainerSize = react.useCallback(() => {
11523
11526
  if (!ref.current) {
11524
11527
  return;
package/index.esm.js CHANGED
@@ -2797,10 +2797,10 @@ const cvaPopoverTitleText = cvaMerge(["flex-1", "text-neutral-500"]);
2797
2797
  * @param {PopoverContentProps} props - The props for the PopoverContent component
2798
2798
  * @returns {ReactElement} The popover content element
2799
2799
  */
2800
- const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, ref: propRef, ...props }) {
2800
+ const PopoverContent = function PopoverContent({ className, "data-testid": dataTestId, children, portalId, initialFocus, ref: propRef, ...props }) {
2801
2801
  const { context: floatingContext, customProps, ...context } = usePopoverContext();
2802
2802
  const ref = useMergeRefs$1([context.refs.setFloating, propRef]);
2803
- return (jsx(Portal, { id: portalId, children: context.isOpen === true ? (jsx(FloatingFocusManager, { closeOnFocusOut: false, context: floatingContext, guards: true, modal: context.isModal, order: ["reference", "content"], returnFocus: true, children: jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
2803
+ return (jsx(Portal, { id: portalId, children: context.isOpen === true ? (jsx(FloatingFocusManager, { closeOnFocusOut: false, context: floatingContext, guards: true, initialFocus: initialFocus, modal: context.isModal, order: ["reference", "content"], returnFocus: true, children: jsx("div", { "aria-describedby": context.descriptionId, "aria-labelledby": context.labelId, className: cvaPopoverContainer({ className: className ?? customProps.className }), "data-testid": dataTestId ?? customProps["data-testid"] ?? "popover-content", ref: ref, style: {
2804
2804
  position: context.strategy,
2805
2805
  top: context.y,
2806
2806
  left: context.x,
@@ -11511,12 +11511,15 @@ const useContainerBreakpoints = (ref, options = {}) => {
11511
11511
  const { skip = false } = options;
11512
11512
  const [containerSize, setContainerSize] = useState(() => defaultBreakpointState);
11513
11513
  useEffect(() => {
11514
+ if (skip) {
11515
+ return;
11516
+ }
11514
11517
  if (process.env.NODE_ENV === "development" && !ref.current) {
11515
11518
  // eslint-disable-next-line no-console
11516
11519
  console.warn("useContainerBreakpoints: The provided ref is not attached to any element. " +
11517
11520
  "Make sure to pass the ref to an element using the ref prop, like: <div ref={myRef}>", "\nComponent:", ref.current);
11518
11521
  }
11519
- }, [ref]);
11522
+ }, [ref, skip]);
11520
11523
  const updateContainerSize = useCallback(() => {
11521
11524
  if (!ref.current) {
11522
11525
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "1.24.1",
3
+ "version": "1.24.3",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -1,4 +1,4 @@
1
- import { HTMLProps, ReactElement, ReactNode, Ref } from "react";
1
+ import { HTMLProps, MutableRefObject, ReactElement, ReactNode, Ref } from "react";
2
2
  import { CommonProps } from "../../common/CommonProps";
3
3
  export type PopoverContentChildren = ((close: () => void) => ReactNode) | ReactNode;
4
4
  export interface PopoverContentProps extends Omit<HTMLProps<HTMLDivElement>, "children">, CommonProps {
@@ -31,6 +31,18 @@ export interface PopoverContentProps extends Omit<HTMLProps<HTMLDivElement>, "ch
31
31
  * Custom dom id to use for portalling the popover content
32
32
  */
33
33
  portalId?: string;
34
+ /**
35
+ * Controls which element receives focus when the popover opens.
36
+ *
37
+ * - **number** (default `0`): index into the FloatingFocusManager focus order. With the
38
+ * default `order` of `["reference", "content"]`, `0` keeps focus on the trigger reference
39
+ * and `1` moves focus to the first tabbable element inside the popover content.
40
+ * - **ref**: focuses the specific element pointed to by the ref when the popover opens.
41
+ *
42
+ * Use this when you want the popover to capture keyboard focus on open (for example,
43
+ * dialog-like menus or pickers) instead of leaving focus on the trigger.
44
+ */
45
+ initialFocus?: number | MutableRefObject<HTMLElement | null>;
34
46
  /**
35
47
  * A ref for the component
36
48
  */
@@ -71,4 +83,4 @@ export interface PopoverContentProps extends Omit<HTMLProps<HTMLDivElement>, "ch
71
83
  * @param {PopoverContentProps} props - The props for the PopoverContent component
72
84
  * @returns {ReactElement} The popover content element
73
85
  */
74
- export declare const PopoverContent: ({ className, "data-testid": dataTestId, children, portalId, ref: propRef, ...props }: PopoverContentProps) => ReactElement;
86
+ export declare const PopoverContent: ({ className, "data-testid": dataTestId, children, portalId, initialFocus, ref: propRef, ...props }: PopoverContentProps) => ReactElement;