@seed-design/lynx-react 0.4.1 → 0.5.1
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/lib/components/Accordion/Accordion.d.ts +56 -0
- package/lib/components/Accordion/Accordion.d.ts.map +1 -0
- package/lib/components/Accordion/Accordion.jsx +210 -0
- package/lib/components/Accordion/Accordion.namespace.d.ts +2 -0
- package/lib/components/Accordion/Accordion.namespace.d.ts.map +1 -0
- package/lib/components/Accordion/Accordion.namespace.js +17 -0
- package/lib/components/Accordion/index.d.ts +3 -0
- package/lib/components/Accordion/index.d.ts.map +1 -0
- package/lib/components/ActionButton/ActionButton.jsx +6 -6
- package/lib/components/AppBar/AppBar.jsx +1 -1
- package/lib/components/Badge/Badge.jsx +1 -1
- package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/lib/components/BottomSheet/BottomSheet.jsx +6 -3
- package/lib/components/Box/Box.jsx +1 -1
- package/lib/components/Callout/Callout.d.ts +32 -0
- package/lib/components/Callout/Callout.d.ts.map +1 -0
- package/lib/components/Callout/Callout.jsx +113 -0
- package/lib/components/Callout/Callout.namespace.d.ts +2 -0
- package/lib/components/Callout/Callout.namespace.d.ts.map +1 -0
- package/lib/components/Callout/Callout.namespace.js +13 -0
- package/lib/components/Callout/index.d.ts +3 -0
- package/lib/components/Callout/index.d.ts.map +1 -0
- package/lib/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/lib/components/Checkbox/Checkbox.jsx +36 -5
- package/lib/components/Chip/Chip.d.ts +66 -0
- package/lib/components/Chip/Chip.d.ts.map +1 -0
- package/lib/components/Chip/Chip.jsx +159 -0
- package/lib/components/Chip/Chip.namespace.d.ts +2 -0
- package/lib/components/Chip/Chip.namespace.d.ts.map +1 -0
- package/lib/components/Chip/Chip.namespace.js +16 -0
- package/lib/components/Chip/index.d.ts +3 -0
- package/lib/components/Chip/index.d.ts.map +1 -0
- package/lib/components/Divider/Divider.d.ts +31 -0
- package/lib/components/Divider/Divider.d.ts.map +1 -0
- package/lib/components/Divider/Divider.jsx +26 -0
- package/lib/components/Divider/index.d.ts +2 -0
- package/lib/components/Divider/index.d.ts.map +1 -0
- package/lib/components/Field/Field.jsx +1 -1
- package/lib/components/Icon/Icon.jsx +2 -2
- package/lib/components/ProgressCircle/ProgressCircle.jsx +2 -2
- package/lib/components/RadioGroup/RadioGroup.jsx +2 -2
- package/lib/components/Stack/Stack.jsx +1 -1
- package/lib/components/Switch/Switch.jsx +2 -2
- package/lib/components/Tabs/Tabs.d.ts +59 -0
- package/lib/components/Tabs/Tabs.d.ts.map +1 -0
- package/lib/components/Tabs/Tabs.jsx +419 -0
- package/lib/components/Tabs/Tabs.namespace.d.ts +2 -0
- package/lib/components/Tabs/Tabs.namespace.d.ts.map +1 -0
- package/lib/components/Tabs/Tabs.namespace.js +14 -0
- package/lib/components/Tabs/Tabs.utils.d.ts +18 -0
- package/lib/components/Tabs/Tabs.utils.d.ts.map +1 -0
- package/lib/components/Tabs/Tabs.utils.js +37 -0
- package/lib/components/Tabs/index.d.ts +3 -0
- package/lib/components/Tabs/index.d.ts.map +1 -0
- package/lib/components/TagGroup/TagGroup.jsx +2 -2
- package/lib/components/Text/Text.jsx +2 -2
- package/lib/components/TextField/TextField.jsx +2 -2
- package/lib/components/index.d.ts +5 -0
- package/lib/components/index.d.ts.map +1 -1
- package/lib/hooks/useIconColor.d.ts +2 -1
- package/lib/hooks/useIconColor.d.ts.map +1 -1
- package/lib/hooks/useIconColor.js +29 -5
- package/lib/hooks/usePressTap.d.ts.map +1 -1
- package/lib/hooks/usePressTap.js +1 -0
- package/lib/index.js +14 -5
- package/lib/utils/create-slot-recipe-context.jsx +1 -1
- package/package.json +2 -2
- package/src/components/Accordion/Accordion.namespace.ts +22 -0
- package/src/components/Accordion/Accordion.test.tsx +129 -0
- package/src/components/Accordion/Accordion.tsx +453 -0
- package/src/components/Accordion/index.ts +24 -0
- package/src/components/BottomSheet/BottomSheet.test.tsx +24 -0
- package/src/components/BottomSheet/BottomSheet.tsx +14 -2
- package/src/components/Callout/Callout.namespace.ts +14 -0
- package/src/components/Callout/Callout.test.tsx +188 -0
- package/src/components/Callout/Callout.tsx +272 -0
- package/src/components/Callout/index.ts +16 -0
- package/src/components/Checkbox/Checkbox.test.tsx +176 -0
- package/src/components/Checkbox/Checkbox.tsx +36 -2
- package/src/components/Chip/Chip.namespace.ts +20 -0
- package/src/components/Chip/Chip.test.tsx +113 -0
- package/src/components/Chip/Chip.tsx +373 -0
- package/src/components/Chip/index.ts +22 -0
- package/src/components/Divider/Divider.test.tsx +73 -0
- package/src/components/Divider/Divider.tsx +76 -0
- package/src/components/Divider/index.ts +1 -0
- package/src/components/Icon/Icon.test.tsx +129 -0
- package/src/components/Tabs/Tabs.namespace.ts +16 -0
- package/src/components/Tabs/Tabs.test.tsx +221 -0
- package/src/components/Tabs/Tabs.tsx +727 -0
- package/src/components/Tabs/Tabs.utils.ts +56 -0
- package/src/components/Tabs/index.ts +2 -0
- package/src/components/index.ts +5 -0
- package/src/hooks/useIconColor.ts +43 -5
- package/src/hooks/usePressTap.test.ts +13 -0
- package/src/hooks/usePressTap.ts +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from "@lynx-js/react";
|
|
2
|
+
|
|
3
|
+
import type { LynxAccessibilityProps, LynxStyledElementProps } from "../../types";
|
|
4
|
+
import type { StyleProps } from "../../utils/styled";
|
|
5
|
+
import { Box } from "../Box";
|
|
6
|
+
|
|
7
|
+
export interface DividerProps
|
|
8
|
+
extends Omit<LynxStyledElementProps, "children">,
|
|
9
|
+
LynxAccessibilityProps {
|
|
10
|
+
/**
|
|
11
|
+
* @default "stroke.neutralMuted"
|
|
12
|
+
*/
|
|
13
|
+
color?: StyleProps["borderColor"];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @default 1
|
|
17
|
+
*/
|
|
18
|
+
thickness?: StyleProps["borderWidth"];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @default "horizontal"
|
|
22
|
+
*/
|
|
23
|
+
orientation?: "horizontal" | "vertical";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Adds 16px of spacing to both ends of the divider.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
inset?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @platform Lynx
|
|
34
|
+
*
|
|
35
|
+
* 웹의 `<hr>` 대신 native `<view>`를 렌더링합니다. 구분선은 기본적으로 접근성
|
|
36
|
+
* 요소로 노출되며 `accessibility-role-description="separator"`를 사용합니다.
|
|
37
|
+
* 장식용 구분선은 `accessibility-element={false}`로 접근성 트리에서 제외하세요.
|
|
38
|
+
*/
|
|
39
|
+
export const Divider = React.forwardRef<unknown, DividerProps>((props, ref) => {
|
|
40
|
+
const {
|
|
41
|
+
color = "stroke.neutralMuted",
|
|
42
|
+
thickness = 1,
|
|
43
|
+
orientation = "horizontal",
|
|
44
|
+
inset = false,
|
|
45
|
+
style,
|
|
46
|
+
"accessibility-element": accessibilityElement = true,
|
|
47
|
+
"accessibility-role-description": accessibilityRoleDescription = "separator",
|
|
48
|
+
...nativeProps
|
|
49
|
+
} = props;
|
|
50
|
+
|
|
51
|
+
const isHorizontal = orientation === "horizontal";
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Box
|
|
55
|
+
{...nativeProps}
|
|
56
|
+
ref={ref}
|
|
57
|
+
borderColor={color}
|
|
58
|
+
borderWidth={0}
|
|
59
|
+
borderBottomWidth={isHorizontal ? thickness : 0}
|
|
60
|
+
borderRightWidth={isHorizontal ? 0 : thickness}
|
|
61
|
+
accessibility-element={accessibilityElement}
|
|
62
|
+
accessibility-role-description={accessibilityRoleDescription}
|
|
63
|
+
style={{
|
|
64
|
+
width: isHorizontal ? (inset ? "calc(100% - 32px)" : "100%") : undefined,
|
|
65
|
+
height: isHorizontal ? undefined : inset ? "calc(100% - 32px)" : "100%",
|
|
66
|
+
marginLeft: inset && isHorizontal ? "16px" : undefined,
|
|
67
|
+
marginRight: inset && isHorizontal ? "16px" : undefined,
|
|
68
|
+
marginTop: inset && !isHorizontal ? "16px" : undefined,
|
|
69
|
+
marginBottom: inset && !isHorizontal ? "16px" : undefined,
|
|
70
|
+
...style,
|
|
71
|
+
}}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
Divider.displayName = "Divider";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Divider, type DividerProps } from "./Divider";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as React from "@lynx-js/react";
|
|
2
|
+
import { act, render, waitSchedule } from "@lynx-js/react/testing-library";
|
|
3
|
+
import type { MainThread } from "@lynx-js/types";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
import type { LynxIconElementProps } from "../../types";
|
|
7
|
+
import { InternalIcon } from "./Icon";
|
|
8
|
+
|
|
9
|
+
const TestIcon = React.forwardRef<
|
|
10
|
+
MainThread.Element,
|
|
11
|
+
LynxIconElementProps & { children?: React.ReactNode }
|
|
12
|
+
>((props, ref) => {
|
|
13
|
+
const { children, ...nativeProps } = props;
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<image {...nativeProps} {...(ref ? { "main-thread:ref": ref } : {})}>
|
|
17
|
+
{children}
|
|
18
|
+
</image>
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
TestIcon.displayName = "TestIcon";
|
|
22
|
+
|
|
23
|
+
function getSourceAndImage() {
|
|
24
|
+
const source = elementTree.root?.querySelector<HTMLElement>("view");
|
|
25
|
+
const image = source?.querySelector<HTMLElement>("image");
|
|
26
|
+
|
|
27
|
+
if (!source || !image) {
|
|
28
|
+
throw new Error("Expected icon source and image elements to exist.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return { source, image };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function installMainThreadStyleMocks(getComputedColor: () => string) {
|
|
35
|
+
let nextFrameId = 1;
|
|
36
|
+
const frames = new Map<number, FrameRequestCallback>();
|
|
37
|
+
|
|
38
|
+
lynxTestingEnv.mainThread.globalThis["SystemInfo"] = {
|
|
39
|
+
...SystemInfo,
|
|
40
|
+
lynxSdkVersion: "3.5",
|
|
41
|
+
};
|
|
42
|
+
lynxTestingEnv.mainThread.globalThis["__GetComputedStyleByKey"] = getComputedColor;
|
|
43
|
+
lynxTestingEnv.mainThread.globalThis["requestAnimationFrame"] = (
|
|
44
|
+
callback: FrameRequestCallback,
|
|
45
|
+
) => {
|
|
46
|
+
const frameId = nextFrameId;
|
|
47
|
+
nextFrameId += 1;
|
|
48
|
+
frames.set(frameId, callback);
|
|
49
|
+
return frameId;
|
|
50
|
+
};
|
|
51
|
+
lynxTestingEnv.mainThread.globalThis["cancelAnimationFrame"] = (frameId: number) => {
|
|
52
|
+
frames.delete(frameId);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const runNextFrame = (timestamp = 16) => {
|
|
56
|
+
const nextFrame = frames.entries().next().value;
|
|
57
|
+
if (!nextFrame) {
|
|
58
|
+
throw new Error("Expected a scheduled animation frame.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const [frameId, callback] = nextFrame;
|
|
62
|
+
frames.delete(frameId);
|
|
63
|
+
lynxTestingEnv.switchToMainThread();
|
|
64
|
+
act(() => {
|
|
65
|
+
callback(timestamp);
|
|
66
|
+
});
|
|
67
|
+
lynxTestingEnv.switchToBackgroundThread();
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return { frames, runNextFrame };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe("InternalIcon", () => {
|
|
74
|
+
it("reads the updated computed color in the next frame", async () => {
|
|
75
|
+
let computedColor = "rgb(134, 139, 148)";
|
|
76
|
+
const { frames, runNextFrame } = installMainThreadStyleMocks(() => computedColor);
|
|
77
|
+
|
|
78
|
+
const renderIcon = (dependency: string) => (
|
|
79
|
+
<InternalIcon icon={<TestIcon />} className={dependency} deps={[dependency]} />
|
|
80
|
+
);
|
|
81
|
+
const { rerender } = render(renderIcon("unchecked"), {
|
|
82
|
+
enableMainThread: true,
|
|
83
|
+
enableBackgroundThread: true,
|
|
84
|
+
});
|
|
85
|
+
await waitSchedule();
|
|
86
|
+
|
|
87
|
+
const { image } = getSourceAndImage();
|
|
88
|
+
expect(frames.size).toBe(1);
|
|
89
|
+
runNextFrame();
|
|
90
|
+
|
|
91
|
+
expect(image.getAttribute("tint-color")).toBe("rgb(134, 139, 148)");
|
|
92
|
+
|
|
93
|
+
rerender(renderIcon("checked"));
|
|
94
|
+
await waitSchedule();
|
|
95
|
+
|
|
96
|
+
expect(frames.size).toBe(1);
|
|
97
|
+
expect(image.getAttribute("tint-color")).toBe("rgb(134, 139, 148)");
|
|
98
|
+
|
|
99
|
+
computedColor = "rgb(255, 102, 0)";
|
|
100
|
+
runNextFrame();
|
|
101
|
+
|
|
102
|
+
expect(image.getAttribute("tint-color")).toBe("rgb(255, 102, 0)");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("coalesces pending frame syncs across rapid dependency changes", async () => {
|
|
106
|
+
let computedColor = "rgb(134, 139, 148)";
|
|
107
|
+
const { frames, runNextFrame } = installMainThreadStyleMocks(() => computedColor);
|
|
108
|
+
const renderIcon = (dependency: string) => (
|
|
109
|
+
<InternalIcon icon={<TestIcon />} className={dependency} deps={[dependency]} />
|
|
110
|
+
);
|
|
111
|
+
const { rerender } = render(renderIcon("unchecked"), {
|
|
112
|
+
enableMainThread: true,
|
|
113
|
+
enableBackgroundThread: true,
|
|
114
|
+
});
|
|
115
|
+
await waitSchedule();
|
|
116
|
+
|
|
117
|
+
rerender(renderIcon("checked"));
|
|
118
|
+
await waitSchedule();
|
|
119
|
+
rerender(renderIcon("unchecked-again"));
|
|
120
|
+
await waitSchedule();
|
|
121
|
+
|
|
122
|
+
expect(frames.size).toBe(1);
|
|
123
|
+
|
|
124
|
+
computedColor = "rgb(73, 80, 88)";
|
|
125
|
+
runNextFrame();
|
|
126
|
+
|
|
127
|
+
expect(getSourceAndImage().image.getAttribute("tint-color")).toBe("rgb(73, 80, 88)");
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export {
|
|
2
|
+
TabsCarousel as Carousel,
|
|
3
|
+
TabsCarouselCamera as CarouselCamera,
|
|
4
|
+
TabsContent as Content,
|
|
5
|
+
TabsIndicator as Indicator,
|
|
6
|
+
TabsList as List,
|
|
7
|
+
TabsRoot as Root,
|
|
8
|
+
TabsTrigger as Trigger,
|
|
9
|
+
type TabsCarouselCameraProps as CarouselCameraProps,
|
|
10
|
+
type TabsCarouselProps as CarouselProps,
|
|
11
|
+
type TabsContentProps as ContentProps,
|
|
12
|
+
type TabsIndicatorProps as IndicatorProps,
|
|
13
|
+
type TabsListProps as ListProps,
|
|
14
|
+
type TabsRootProps as RootProps,
|
|
15
|
+
type TabsTriggerProps as TriggerProps,
|
|
16
|
+
} from "./Tabs";
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
2
|
+
import { fireEvent, render } from "@lynx-js/react/testing-library";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import * as Tabs from "./Tabs.namespace";
|
|
6
|
+
import { getTabsLayoutWidth, getTabsOrderedItems, getTabsTriggerRects } from "./Tabs.utils";
|
|
7
|
+
|
|
8
|
+
function BasicTabs(props: {
|
|
9
|
+
value?: string;
|
|
10
|
+
defaultValue?: string;
|
|
11
|
+
onValueChange?: (value: string) => void;
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<Tabs.Root {...props}>
|
|
15
|
+
<Tabs.List>
|
|
16
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
17
|
+
<Tabs.Trigger value="two">두 번째</Tabs.Trigger>
|
|
18
|
+
<Tabs.Indicator />
|
|
19
|
+
</Tabs.List>
|
|
20
|
+
<Tabs.Content value="one">첫 번째 콘텐츠</Tabs.Content>
|
|
21
|
+
<Tabs.Content value="two">두 번째 콘텐츠</Tabs.Content>
|
|
22
|
+
</Tabs.Root>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function getTrigger(container: HTMLElement, label: string) {
|
|
27
|
+
const trigger = Array.from(container.querySelectorAll<HTMLElement>(".seed-tabs__trigger")).find(
|
|
28
|
+
(element) => element.textContent === label,
|
|
29
|
+
);
|
|
30
|
+
if (!trigger) throw new Error(`Expected trigger for ${label} to exist.`);
|
|
31
|
+
return trigger;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe("Tabs", () => {
|
|
35
|
+
it("renders triggers inside the list content layout container", () => {
|
|
36
|
+
const { container } = render(<BasicTabs defaultValue="one" />);
|
|
37
|
+
const list = container.querySelector(".seed-tabs__list");
|
|
38
|
+
const listContent = list?.querySelector(":scope > .seed-tabs__listContent");
|
|
39
|
+
|
|
40
|
+
expect(listContent).not.toBeNull();
|
|
41
|
+
expect(listContent?.querySelectorAll(".seed-tabs__trigger")).toHaveLength(2);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("changes an uncontrolled value when a trigger is tapped", () => {
|
|
45
|
+
const onValueChange = vi.fn();
|
|
46
|
+
const { container } = render(<BasicTabs defaultValue="one" onValueChange={onValueChange} />);
|
|
47
|
+
|
|
48
|
+
const first = getTrigger(container, "첫 번째");
|
|
49
|
+
const second = getTrigger(container, "두 번째");
|
|
50
|
+
|
|
51
|
+
expect(first).toHaveAttribute("accessibility-value", "selected");
|
|
52
|
+
expect(second).toHaveAttribute("accessibility-value", "not selected");
|
|
53
|
+
|
|
54
|
+
fireEvent.tap(second);
|
|
55
|
+
|
|
56
|
+
expect(onValueChange).toHaveBeenCalledWith("two");
|
|
57
|
+
expect(second).toHaveAttribute("accessibility-value", "selected");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("derives trigger positions from ordered widths instead of platform coordinates", () => {
|
|
61
|
+
expect(getTabsLayoutWidth({ detail: { width: 128 }, params: { width: 128 } })).toBe(128);
|
|
62
|
+
expect(
|
|
63
|
+
getTabsTriggerRects(["one", "two", "three"], {
|
|
64
|
+
one: 128,
|
|
65
|
+
two: 128,
|
|
66
|
+
three: 128,
|
|
67
|
+
}),
|
|
68
|
+
).toEqual({
|
|
69
|
+
one: { left: 0, width: 128 },
|
|
70
|
+
two: { left: 128, width: 128 },
|
|
71
|
+
three: { left: 256, width: 128 },
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("waits for every preceding trigger width before positioning later triggers", () => {
|
|
76
|
+
expect(getTabsTriggerRects(["one", "two", "three"], { one: 80, three: 120 })).toEqual({
|
|
77
|
+
one: { left: 0, width: 80 },
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("ignores inherited object properties used as trigger values", () => {
|
|
82
|
+
expect(getTabsTriggerRects(["toString"], {})).toEqual({});
|
|
83
|
+
expect(getTabsTriggerRects(["constructor"], {})).toEqual({});
|
|
84
|
+
expect(getTabsTriggerRects(["__proto__"], {})).toEqual({});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("updates trigger positions when keyed triggers are reordered", () => {
|
|
88
|
+
const items = [{ value: "one" }, { value: "two" }, { value: "three" }];
|
|
89
|
+
const reordered = getTabsOrderedItems(items, ["three", "two", "one"]);
|
|
90
|
+
const rects = getTabsTriggerRects(
|
|
91
|
+
reordered.map((item) => item.value),
|
|
92
|
+
{ one: 80, two: 80, three: 80 },
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(reordered.map((item) => item.value)).toEqual(["three", "two", "one"]);
|
|
96
|
+
expect(rects["three"]?.left).toBe(0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("does not select a disabled trigger", () => {
|
|
100
|
+
const onValueChange = vi.fn();
|
|
101
|
+
const { container } = render(
|
|
102
|
+
<Tabs.Root defaultValue="one" onValueChange={onValueChange}>
|
|
103
|
+
<Tabs.List>
|
|
104
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
105
|
+
<Tabs.Trigger value="two" disabled>
|
|
106
|
+
두 번째
|
|
107
|
+
</Tabs.Trigger>
|
|
108
|
+
</Tabs.List>
|
|
109
|
+
</Tabs.Root>,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const disabled = getTrigger(container, "두 번째");
|
|
113
|
+
fireEvent.tap(disabled);
|
|
114
|
+
|
|
115
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
116
|
+
expect(disabled).toHaveAttribute("accessibility-traits", "disabled");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("keeps controlled selection until the value prop changes", () => {
|
|
120
|
+
const onValueChange = vi.fn();
|
|
121
|
+
const { container, rerender } = render(<BasicTabs value="one" onValueChange={onValueChange} />);
|
|
122
|
+
|
|
123
|
+
const second = getTrigger(container, "두 번째");
|
|
124
|
+
fireEvent.tap(second);
|
|
125
|
+
|
|
126
|
+
expect(onValueChange).toHaveBeenCalledWith("two");
|
|
127
|
+
expect(second).toHaveAttribute("accessibility-value", "not selected");
|
|
128
|
+
|
|
129
|
+
rerender(<BasicTabs value="two" onValueChange={onValueChange} />);
|
|
130
|
+
expect(second).toHaveAttribute("accessibility-value", "selected");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("keeps carousel contents as views without a carousel camera", () => {
|
|
134
|
+
const { container } = render(
|
|
135
|
+
<Tabs.Root defaultValue="one">
|
|
136
|
+
<Tabs.List>
|
|
137
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
138
|
+
</Tabs.List>
|
|
139
|
+
<Tabs.Carousel>
|
|
140
|
+
<Tabs.Content value="one">첫 번째 콘텐츠</Tabs.Content>
|
|
141
|
+
</Tabs.Carousel>
|
|
142
|
+
</Tabs.Root>,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(container.querySelector("viewpager-item")).toBeNull();
|
|
146
|
+
expect(container.querySelector(".seed-tabs__content")).not.toBeNull();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("renders carousel camera contents as native viewpager items", () => {
|
|
150
|
+
const { container } = render(
|
|
151
|
+
<Tabs.Root defaultValue="one">
|
|
152
|
+
<Tabs.List>
|
|
153
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
154
|
+
<Tabs.Trigger value="two">두 번째</Tabs.Trigger>
|
|
155
|
+
</Tabs.List>
|
|
156
|
+
<Tabs.Carousel swipeable>
|
|
157
|
+
<Tabs.CarouselCamera>
|
|
158
|
+
<Tabs.Content value="one">첫 번째 콘텐츠</Tabs.Content>
|
|
159
|
+
<Tabs.Content value="two">두 번째 콘텐츠</Tabs.Content>
|
|
160
|
+
</Tabs.CarouselCamera>
|
|
161
|
+
</Tabs.Carousel>
|
|
162
|
+
</Tabs.Root>,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const pager = container.querySelector("viewpager");
|
|
166
|
+
expect(pager).not.toBeNull();
|
|
167
|
+
expect(pager?.querySelectorAll("viewpager-item")).toHaveLength(2);
|
|
168
|
+
expect(pager).toHaveAttribute("enable-scroll");
|
|
169
|
+
expect(pager).toHaveAttribute("ios-gesture-offset", "32");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("supports a custom iOS back gesture edge width", () => {
|
|
173
|
+
const { container } = render(
|
|
174
|
+
<Tabs.Root defaultValue="one">
|
|
175
|
+
<Tabs.List>
|
|
176
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
177
|
+
</Tabs.List>
|
|
178
|
+
<Tabs.Carousel swipeable iosBackGestureEdgeWidth={48}>
|
|
179
|
+
<Tabs.CarouselCamera>
|
|
180
|
+
<Tabs.Content value="one">첫 번째 콘텐츠</Tabs.Content>
|
|
181
|
+
</Tabs.CarouselCamera>
|
|
182
|
+
</Tabs.Carousel>
|
|
183
|
+
</Tabs.Root>,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
expect(container.querySelector("viewpager")).toHaveAttribute("ios-gesture-offset", "48");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("maps pager indexes from content order when a disabled trigger has no content", () => {
|
|
190
|
+
const { container } = render(
|
|
191
|
+
<Tabs.Root defaultValue="two">
|
|
192
|
+
<Tabs.List>
|
|
193
|
+
<Tabs.Trigger value="one">첫 번째</Tabs.Trigger>
|
|
194
|
+
<Tabs.Trigger value="disabled" disabled>
|
|
195
|
+
비활성
|
|
196
|
+
</Tabs.Trigger>
|
|
197
|
+
<Tabs.Trigger value="two">두 번째</Tabs.Trigger>
|
|
198
|
+
</Tabs.List>
|
|
199
|
+
<Tabs.Carousel swipeable>
|
|
200
|
+
<Tabs.CarouselCamera>
|
|
201
|
+
<Tabs.Content value="one">첫 번째 콘텐츠</Tabs.Content>
|
|
202
|
+
<Tabs.Content value="two">두 번째 콘텐츠</Tabs.Content>
|
|
203
|
+
</Tabs.CarouselCamera>
|
|
204
|
+
</Tabs.Carousel>
|
|
205
|
+
</Tabs.Root>,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const pager = container.querySelector("viewpager");
|
|
209
|
+
expect(pager).toHaveAttribute("initial-select-index", "1");
|
|
210
|
+
expect(getTrigger(container, "두 번째")).toHaveAttribute("accessibility-value", "selected");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("exposes tab semantics through Lynx accessibility attributes", () => {
|
|
214
|
+
const { container } = render(<BasicTabs defaultValue="one" />);
|
|
215
|
+
const first = getTrigger(container, "첫 번째");
|
|
216
|
+
|
|
217
|
+
expect(first).toHaveAttribute("accessibility-role-description", "tab");
|
|
218
|
+
expect(first).toHaveAttribute("accessibility-label", "첫 번째");
|
|
219
|
+
expect(first).toHaveAttribute("accessibility-traits", "selected");
|
|
220
|
+
});
|
|
221
|
+
});
|