playbook_ui 16.7.0.pre.alpha.play2924tooltipmisalignment16199 → 16.7.0.pre.alpha.play2924tooltipmisalignment16200

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c7c7804406ddf89dd94895bb1223d17244e37fd4b62648847708557f0c879c6
4
- data.tar.gz: bb3cad46ebc29326ce281440c1b6d17ac65c45e7d794cd80011d9d57ce1d3cf6
3
+ metadata.gz: bd1098414a7534b24fca41a8ffeffd3acf6a7a1f48e835bbd318c7a17a42ff1e
4
+ data.tar.gz: 4b5eabe98006633e85de5678573ff1a1a58c3b79fda27d1edbee1cb93af27fd3
5
5
  SHA512:
6
- metadata.gz: be4d9cfd2a3dc813d0746783e14fb55d6ff4c3d9f003bb0cd62efb80ffeaa4ea2bd82a908b1b8acb772019a27292aca2b0d81df29356829ff8011672e1c500c4
7
- data.tar.gz: 1b395492389b12ee2c69d690a954720b809e3cd0b61d9f7c2182256ca79c34aec2e2b593cc326cca84b9166df778cdd6ab2a060f9f2d5e286a33443ae53c1051
6
+ metadata.gz: ba8a28d2434fdca87f08fae27a2c20143adb0734b7553b93c7732fe59c41c6f0320e095725bd64d8e38dbe169761483d4e2c8134a799a5f40b5bce3f615e188b
7
+ data.tar.gz: '0270209c6293af2cf5133bf9530998ed0a0199ecd060fe257b521808531045928da31cb41cda3fd47d718624e7c490d6854faa9b075bd2291db6b96c58fbb11f'
@@ -86,7 +86,7 @@ const Tooltip = forwardRef((props: TooltipProps, ref: ForwardedRef<unknown>): Re
86
86
 
87
87
  const {
88
88
  context,
89
- middlewareData: { arrow: { centerOffset = 0, x: arrowX, y: arrowY } = {}, },
89
+ middlewareData: { arrow: { x: arrowX, y: arrowY } = {}, },
90
90
  placement,
91
91
  refs,
92
92
  strategy,
@@ -144,7 +144,6 @@ const Tooltip = forwardRef((props: TooltipProps, ref: ForwardedRef<unknown>): Re
144
144
  top: "bottom",
145
145
  }[placement.split("-")[0]]
146
146
  const arrowPlacementStyle = staticSide ? { [staticSide]: "-5px" } : {}
147
- const shouldHideArrow = centerOffset !== 0
148
147
 
149
148
  const tooltipSizing = () => {
150
149
  return Object.assign(
@@ -217,7 +216,6 @@ const Tooltip = forwardRef((props: TooltipProps, ref: ForwardedRef<unknown>): Re
217
216
  className="arrow_bg"
218
217
  ref={arrowRef}
219
218
  style={{
220
- opacity: shouldHideArrow ? 0 : 1,
221
219
  position: "absolute",
222
220
  left: arrowX != null ? `${arrowX}px` : "",
223
221
  top: arrowY != null ? `${arrowY}px` : "",
@@ -2,6 +2,17 @@ import React from "react";
2
2
  import { cleanup, render, screen, fireEvent, waitFor } from "../utilities/test-utils";
3
3
  import { Button, Tooltip } from "playbook-ui";
4
4
 
5
+ jest.mock("@floating-ui/react", () => {
6
+ const actual = jest.requireActual("@floating-ui/react")
7
+
8
+ return {
9
+ ...actual,
10
+ useFloating: jest.fn(actual.useFloating),
11
+ }
12
+ })
13
+
14
+ const { useFloating } = require("@floating-ui/react")
15
+
5
16
  function TooltipTest() {
6
17
  const text = "this is a text",
7
18
  placement = "top",
@@ -131,4 +142,47 @@ test("doesn't display tooltip with showTooltip set to false", async () => {
131
142
  })
132
143
 
133
144
  cleanup();
134
- });
145
+ });
146
+
147
+ test("keeps the arrow visible when placement flips left with center offset", async () => {
148
+ const actual = jest.requireActual("@floating-ui/react")
149
+
150
+ useFloating.mockImplementationOnce((options) => {
151
+ const result = actual.useFloating(options)
152
+
153
+ return {
154
+ ...result,
155
+ middlewareData: {
156
+ ...result.middlewareData,
157
+ arrow: {
158
+ centerOffset: 12,
159
+ x: 6,
160
+ y: 10,
161
+ },
162
+ },
163
+ open: true,
164
+ placement: "left",
165
+ x: 20,
166
+ y: 30,
167
+ }
168
+ })
169
+
170
+ render(
171
+ <Tooltip
172
+ data={{ testid: "left-placement-arrow-test" }}
173
+ forceOpenTooltip
174
+ placement="left"
175
+ text="left placement"
176
+ zIndex="10"
177
+ >
178
+ <Button text="hover me" />
179
+ </Tooltip>
180
+ )
181
+
182
+ const tooltip = await screen.findByRole("tooltip")
183
+ const arrow = tooltip.querySelector(".arrow_bg")
184
+
185
+ expect(tooltip).toHaveAttribute("data-placement", "left")
186
+ expect(arrow).toBeInTheDocument()
187
+ expect(arrow).not.toHaveStyle({ opacity: "0" })
188
+ })