@sproutsocial/seeds-react-tooltip 1.1.33 → 1.1.35

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.
@@ -1,285 +0,0 @@
1
- import React from "react";
2
- import {
3
- render,
4
- screen,
5
- waitFor,
6
- } from "@sproutsocial/seeds-react-testing-library";
7
- import Icon from "@sproutsocial/seeds-react-icon";
8
- import Tooltip from "../Tooltip";
9
- import Button from "@sproutsocial/seeds-react-button";
10
-
11
- jest.mock("@sproutsocial/seeds-react-portal", () => {
12
- const Portal = ({ children }: { children: React.ReactNode }) => (
13
- <div>{children}</div>
14
- );
15
- Portal.DisablePortalToBodyContext = require("react").createContext(false);
16
- return {
17
- __esModule: true,
18
- default: Portal,
19
- DisablePortalToBodyContext: Portal.DisablePortalToBodyContext,
20
- };
21
- });
22
-
23
- describe("Tooltip", () => {
24
- describe("rendering all valid `React.Node`s", () => {
25
- it("should render string content", async () => {
26
- const contentText = "hey";
27
- const { user } = render(<Tooltip content={contentText}>hi</Tooltip>);
28
- await user.hover(screen.getByText("hi"));
29
- await screen.findByText(contentText);
30
- expect(screen.getByText(contentText)).toBeInTheDocument();
31
- });
32
-
33
- it("should render number content", async () => {
34
- const contentText = 123;
35
- const { user } = render(<Tooltip content={contentText}>hi</Tooltip>);
36
- await user.hover(screen.getByText("hi"));
37
- await screen.findByDataQaLabel({
38
- "popout-isopen": "true",
39
- });
40
- expect(screen.getByText(`${contentText}`)).toBeInTheDocument();
41
- });
42
-
43
- it("should render React Element content", async () => {
44
- const { user } = render(<Tooltip content={<p>hey</p>}>hi</Tooltip>);
45
- await user.hover(screen.getByText("hi"));
46
- await screen.findByDataQaLabel({
47
- "popout-isopen": "true",
48
- });
49
- expect(screen.getByText("hey")).toBeInTheDocument();
50
- });
51
-
52
- it("should render $Iterable<string> content", async () => {
53
- const { user } = render(
54
- <Tooltip content={["hello", "world"]}>hi</Tooltip>
55
- );
56
- await user.hover(screen.getByText("hi"));
57
- await screen.findByText(/hello/i);
58
- expect(screen.getByText(/hello/i)).toBeInTheDocument();
59
- await screen.findByText(/world/i);
60
- expect(screen.getByText(/world/i)).toBeInTheDocument();
61
- });
62
-
63
- it("should render $Iterable<React$Element<any>> content", async () => {
64
- const { user } = render(
65
- <Tooltip content={[<p key="1">hello</p>, <p key="2">world</p>]}>
66
- hi
67
- </Tooltip>
68
- );
69
- await user.hover(screen.getByText("hi"));
70
- await screen.findByText(/hello/i);
71
- expect(screen.getByText(/hello/i)).toBeInTheDocument();
72
- await screen.findByText(/world/i);
73
- expect(screen.getByText(/world/i)).toBeInTheDocument();
74
- });
75
-
76
- it("should not render null content", async () => {
77
- expect.assertions(1);
78
- const { user } = render(<Tooltip content={null}>hi</Tooltip>);
79
- await user.hover(screen.getByText("hi"));
80
- await expect(
81
- screen.findByDataQaLabel({
82
- "popout-isopen": "true",
83
- })
84
- ).rejects.toBeTruthy();
85
- });
86
-
87
- it("should not render undefined content", async () => {
88
- expect.assertions(1);
89
- const { user } = render(<Tooltip content={undefined}>hi</Tooltip>);
90
- await user.hover(screen.getByText("hi"));
91
- await expect(
92
- screen.findByDataQaLabel({
93
- "popout-isopen": "true",
94
- })
95
- ).rejects.toBeTruthy();
96
- });
97
-
98
- it("should not add aria-expanded to elements without it", async () => {
99
- const { user } = render(
100
- <Tooltip content="hello">
101
- <Button>hi</Button>
102
- </Tooltip>
103
- );
104
-
105
- const button = screen.getByRole("button", { name: "hi" });
106
-
107
- expect(button).not.toHaveAttribute("aria-expanded");
108
-
109
- await user.hover(button.closest("[data-qa-tooltip]")!);
110
-
111
- await screen.findByText(/hello/i);
112
-
113
- expect(button).not.toHaveAttribute("aria-expanded");
114
- });
115
-
116
- it("should preserve existing aria-expanded attribute", async () => {
117
- const { user } = render(
118
- <Tooltip content="hello">
119
- <Button aria-expanded="false">hi</Button>
120
- </Tooltip>
121
- );
122
-
123
- const button = screen.getByRole("button", { name: "hi" });
124
-
125
- expect(button).toHaveAttribute("aria-expanded", "false");
126
-
127
- await user.hover(button.closest("[data-qa-tooltip]")!);
128
-
129
- await screen.findByText(/hello/i);
130
-
131
- expect(button).toHaveAttribute("aria-expanded", "false");
132
- });
133
-
134
- it("should not add aria-expanded to non-interactive elements", () => {
135
- render(
136
- <Tooltip content="Tooltip text">
137
- <span data-testid="text-element">Static text</span>
138
- </Tooltip>
139
- );
140
-
141
- const textElement = screen.getByTestId("text-element");
142
-
143
- expect(textElement).not.toHaveAttribute("aria-expanded");
144
- });
145
- });
146
-
147
- it("should render when wrapped around an icon", async () => {
148
- const { user } = render(
149
- <Tooltip content="hey">
150
- <Icon
151
- data-testid="icon"
152
- name="globe-outline"
153
- aria-label="Open Tooltip"
154
- />
155
- </Tooltip>
156
- );
157
- await user.hover(screen.getByTestId("icon").closest("[data-qa-tooltip]")!);
158
- await expect(
159
- screen.findByDataQaLabel({
160
- "popout-isopen": "true",
161
- })
162
- ).resolves.toBeTruthy();
163
- });
164
-
165
- describe("ARIA attributes", () => {
166
- it("should not have aria-describedby when tooltip is closed", () => {
167
- render(
168
- <Tooltip content="Tooltip content">
169
- <Button data-testid="trigger">Trigger</Button>
170
- </Tooltip>
171
- );
172
-
173
- const trigger = screen.getByTestId("trigger");
174
- expect(trigger).not.toHaveAttribute("aria-describedby");
175
- });
176
-
177
- it("should have aria-describedby when tooltip is open", async () => {
178
- const { user } = render(
179
- <Tooltip content="Tooltip content">
180
- <Button data-testid="trigger">Trigger</Button>
181
- </Tooltip>
182
- );
183
-
184
- const trigger = screen.getByTestId("trigger");
185
-
186
- await user.hover(trigger.closest("[data-qa-tooltip]")!);
187
-
188
- await screen.findByText("Tooltip content");
189
-
190
- expect(trigger).toHaveAttribute("aria-describedby");
191
- const tooltipId = trigger.getAttribute("aria-describedby");
192
- expect(tooltipId).toBeTruthy();
193
- expect(tooltipId).toMatch(/^Racine-tooltip-\d+$/);
194
- });
195
-
196
- it("should remove aria-describedby when tooltip closes", async () => {
197
- const { user } = render(
198
- <Tooltip content="Tooltip content">
199
- <Button data-testid="trigger">Trigger</Button>
200
- </Tooltip>
201
- );
202
-
203
- const trigger = screen.getByTestId("trigger");
204
-
205
- await user.hover(trigger.closest("[data-qa-tooltip]")!);
206
-
207
- await screen.findByText("Tooltip content");
208
-
209
- expect(trigger).toHaveAttribute("aria-describedby");
210
-
211
- await user.unhover(trigger.closest("[data-qa-tooltip]")!);
212
-
213
- await waitFor(() => {
214
- expect(trigger).not.toHaveAttribute("aria-describedby");
215
- });
216
- });
217
-
218
- it("should have aria-describedby pointing to element with role='tooltip'", async () => {
219
- const { user } = render(
220
- <Tooltip content="Tooltip content">
221
- <Button data-testid="trigger">Trigger</Button>
222
- </Tooltip>
223
- );
224
-
225
- const trigger = screen.getByTestId("trigger");
226
-
227
- await user.hover(trigger.closest("[data-qa-tooltip]")!);
228
-
229
- const tooltipElement = await screen.findByText("Tooltip content");
230
-
231
- const tooltipId = trigger.getAttribute("aria-describedby");
232
- expect(tooltipId).toBeTruthy();
233
-
234
- const tooltipByRole = screen.getByRole("tooltip");
235
- expect(tooltipByRole).toBeInTheDocument();
236
-
237
- expect(tooltipByRole).toHaveAttribute("id", tooltipId);
238
-
239
- expect(tooltipByRole).toContainElement(tooltipElement);
240
- });
241
- });
242
-
243
- describe("legacyMouseInteraction prop", () => {
244
- it("should allow hovering over tooltip content when legacyMouseInteraction is true", async () => {
245
- const { user } = render(
246
- <Tooltip content="Tooltip content" legacyMouseInteraction>
247
- <Button data-testid="trigger">Trigger</Button>
248
- </Tooltip>
249
- );
250
-
251
- const trigger = screen.getByTestId("trigger");
252
-
253
- await user.hover(trigger.closest("[data-qa-tooltip]")!);
254
-
255
- const tooltipContent = await screen.findByText("Tooltip content");
256
- expect(tooltipContent).toBeInTheDocument();
257
-
258
- await user.unhover(trigger.closest("[data-qa-tooltip]")!);
259
- await user.hover(tooltipContent);
260
-
261
- await waitFor(() => {
262
- expect(tooltipContent).toBeInTheDocument();
263
- });
264
-
265
- await user.unhover(tooltipContent);
266
- });
267
-
268
- it("should not have mouse handlers on tooltip content when legacyMouseInteraction is false", async () => {
269
- const { user } = render(
270
- <Tooltip content="Tooltip content">
271
- <Button data-testid="trigger">Trigger</Button>
272
- </Tooltip>
273
- );
274
-
275
- const trigger = screen.getByTestId("trigger");
276
-
277
- await user.hover(trigger.closest("[data-qa-tooltip]")!);
278
-
279
- const tooltipContent = await screen.findByText("Tooltip content");
280
- expect(tooltipContent).toBeInTheDocument();
281
-
282
- await user.unhover(trigger.closest("[data-qa-tooltip]")!);
283
- });
284
- });
285
- });
@@ -1,27 +0,0 @@
1
- import * as React from "react";
2
- import Tooltip from "../Tooltip";
3
- import { Text } from "@sproutsocial/seeds-react-text";
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- function TooltipTypes() {
7
- return (
8
- <>
9
- <Tooltip content="This is a tooltip on a text element">
10
- <Text>Hello World</Text>
11
- </Tooltip>
12
- <Tooltip onFocus={() => {}} content="This is a tooltip on a text element">
13
- <Text>Hello World</Text>
14
- </Tooltip>
15
- <Tooltip
16
- content="foo"
17
- ariaProps={{
18
- role: "link",
19
- }}
20
- >
21
- <Text>Yo</Text>
22
- </Tooltip>
23
- {/* @ts-expect-error - test that invalid props are rejected */}
24
- <Tooltip />
25
- </>
26
- );
27
- }
@@ -1,56 +0,0 @@
1
- import { mapPlacement } from "../Tooltip";
2
-
3
- describe("mapPlacement", () => {
4
- it("maps top placements", () => {
5
- expect(mapPlacement("top")).toEqual({ side: "top", align: "center" });
6
- expect(mapPlacement("top-start")).toEqual({ side: "top", align: "start" });
7
- expect(mapPlacement("top-end")).toEqual({ side: "top", align: "end" });
8
- });
9
-
10
- it("maps bottom placements", () => {
11
- expect(mapPlacement("bottom")).toEqual({ side: "bottom", align: "center" });
12
- expect(mapPlacement("bottom-start")).toEqual({
13
- side: "bottom",
14
- align: "start",
15
- });
16
- expect(mapPlacement("bottom-end")).toEqual({
17
- side: "bottom",
18
- align: "end",
19
- });
20
- });
21
-
22
- it("maps left placements", () => {
23
- expect(mapPlacement("left")).toEqual({ side: "left", align: "center" });
24
- expect(mapPlacement("left-start")).toEqual({
25
- side: "left",
26
- align: "start",
27
- });
28
- expect(mapPlacement("left-end")).toEqual({ side: "left", align: "end" });
29
- });
30
-
31
- it("maps right placements", () => {
32
- expect(mapPlacement("right")).toEqual({ side: "right", align: "center" });
33
- expect(mapPlacement("right-start")).toEqual({
34
- side: "right",
35
- align: "start",
36
- });
37
- expect(mapPlacement("right-end")).toEqual({ side: "right", align: "end" });
38
- });
39
-
40
- // `auto*` deliberately anchors to `side: "top"` and relies on base-ui's
41
- // runtime collision flipping rather than Popper-style best-initial-side
42
- // selection. This is the documented, intentional behavior — see the
43
- // changeset and the `placement` prop JSDoc in TooltipTypes.ts.
44
- it("anchors auto placements to top with align from the suffix", () => {
45
- expect(mapPlacement("auto")).toEqual({ side: "top", align: "center" });
46
- expect(mapPlacement("auto-start")).toEqual({
47
- side: "top",
48
- align: "start",
49
- });
50
- expect(mapPlacement("auto-end")).toEqual({ side: "top", align: "end" });
51
- });
52
-
53
- it("falls back to top/center for unknown placements", () => {
54
- expect(mapPlacement("nonsense")).toEqual({ side: "top", align: "center" });
55
- });
56
- });
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- import Tooltip from "./Tooltip";
2
-
3
- export default Tooltip;
4
- export { Tooltip };
5
- export * from "./TooltipTypes";
package/src/styled.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import "styled-components";
2
- import { TypeTheme } from "@sproutsocial/seeds-react-theme";
3
-
4
- declare module "styled-components" {
5
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
6
- export interface DefaultTheme extends TypeTheme {}
7
- }
package/src/styles.ts DELETED
@@ -1,11 +0,0 @@
1
- import styled from "styled-components";
2
- import Box from "@sproutsocial/seeds-react-box";
3
- import type { TypeTooltipContent } from "./TooltipTypes";
4
-
5
- export const StyledTooltipContent = styled(Box)<
6
- Pick<TypeTooltipContent, "appearance">
7
- >`
8
- font-family: ${(props) => props.theme.fontFamily};
9
- ${(props) => props.theme.typography[200]}
10
- text-align: ${(props) => (props.appearance === "box" ? "left" : "center")};
11
- `;
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "extends": "@sproutsocial/seeds-tsconfig/bundler/dom/library-monorepo",
3
- "compilerOptions": {
4
- "jsx": "react-jsx",
5
- "module": "esnext"
6
- },
7
- "include": ["src/**/*"],
8
- "exclude": [
9
- "node_modules",
10
- "dist",
11
- "coverage",
12
- "**/*.stories.tsx",
13
- "**/*.stories.ts"
14
- ]
15
- }
package/tsup.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig((options) => ({
4
- entry: ["src/index.ts"],
5
- format: ["cjs", "esm"],
6
- clean: true,
7
- legacyOutput: true,
8
- dts: options.dts,
9
- external: ["react"],
10
- sourcemap: true,
11
- metafile: options.metafile,
12
- }));