@noya-app/noya-designsystem 0.1.85 → 0.1.86

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noya-app/noya-designsystem",
3
- "version": "0.1.85",
3
+ "version": "0.1.86",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -661,6 +661,7 @@ function InputFieldRoot({
661
661
  <Popover
662
662
  open={true}
663
663
  trigger={rootElement}
664
+ initialFocus={false}
664
665
  sideOffset={sideOffset}
665
666
  showArrow={false}
666
667
  >
@@ -31,6 +31,9 @@ interface Props {
31
31
  style?: React.CSSProperties;
32
32
  portalContainer?: HTMLElement | null;
33
33
  side?: "top" | "bottom" | "left" | "right";
34
+ initialFocus?: React.ComponentProps<
35
+ typeof PopoverPrimitive.Popup
36
+ >["initialFocus"];
34
37
  /**
35
38
  * Called when an interaction outside the popover occurs.
36
39
  * Return false to prevent the popover from closing.
@@ -58,6 +61,7 @@ export function Popover({
58
61
  className,
59
62
  portalContainer,
60
63
  style,
64
+ initialFocus,
61
65
  shouldCloseOnInteractOutside,
62
66
  }: Props) {
63
67
  const defaultId = useId();
@@ -126,6 +130,7 @@ export function Popover({
126
130
  >
127
131
  <PopoverPrimitive.Popup
128
132
  ref={popupRef}
133
+ initialFocus={initialFocus}
129
134
  style={style}
130
135
  className={cx(
131
136
  popoverStyle.base,
@@ -0,0 +1,36 @@
1
+ import { act, cleanup, render } from "@testing-library/react";
2
+ import { afterEach, describe, expect, test } from "bun:test";
3
+ import React, { useEffect, useRef } from "react";
4
+ import { InputField } from "../InputField";
5
+
6
+ afterEach(cleanup);
7
+
8
+ describe("InputField", () => {
9
+ test("keeps focus on the input when its popover mounts", async () => {
10
+ let input: HTMLInputElement | null = null;
11
+
12
+ function InputWithPopover() {
13
+ const inputRef = useRef<HTMLInputElement>(null);
14
+
15
+ useEffect(() => {
16
+ requestAnimationFrame(() => inputRef.current?.focus());
17
+ }, []);
18
+
19
+ return (
20
+ <InputField
21
+ ref={(element) => {
22
+ inputRef.current = element;
23
+ input = element;
24
+ }}
25
+ width={240}
26
+ renderPopoverContent={() => <button>Result</button>}
27
+ />
28
+ );
29
+ }
30
+
31
+ render(<InputWithPopover />);
32
+ await act(() => new Promise((resolve) => setTimeout(resolve, 50)));
33
+
34
+ expect(document.activeElement === input).toBe(true);
35
+ });
36
+ });