@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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/InputField.tsx +1 -0
- package/src/components/Popover.tsx +5 -0
- package/src/components/__tests__/InputField.test.tsx +36 -0
package/package.json
CHANGED
|
@@ -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
|
+
});
|