diff --git a/lib/components/ActionsMenu/index.js b/lib/components/ActionsMenu/index.js index 64e88792..90e8f76a 100644 --- a/lib/components/ActionsMenu/index.js +++ b/lib/components/ActionsMenu/index.js @@ -68,6 +68,16 @@ const StyledActionsMenuContainer = styled.div` opacity: 0; visibility: hidden; + &.hack-for-legacy-tests { + position: absolute; + pointer-events: none; + opacity: 0; + visibility: hidden; + height: 0; + width: 0; + padding: 0; + } + &.visible { visibility: visible; opacity: 1; @@ -288,19 +298,31 @@ export const ActionsMenuBody = ({ const triggerRef = useMergeRefs([actionMenu.refs.setReference, childrenRef]); const ref = useMergeRefs([actionMenu.refs.setFloating]); - const triggerProps = { - ariaLabel, - "aria-label": ariaLabel, - onFocus: onTriggerFocus, - id, - ...actionMenu.getReferenceProps({ - ...props, - onClick: onToggle, - ref: triggerRef, - "data-state": actionMenu.open ? "open" : "closed", - "data-testid": dataTestId - }) - }; + const triggerProps = useMemo( + () => ({ + ariaLabel, + "aria-label": ariaLabel, + onFocus: onTriggerFocus, + id, + ...actionMenu.getReferenceProps({ + ...props, + onClick: onToggle, + ref: triggerRef, + "data-state": actionMenu.open ? "open" : "closed", + "data-testid": dataTestId + }) + }), + [ + ariaLabel, + onTriggerFocus, + id, + actionMenu, + onToggle, + props, + triggerRef, + dataTestId + ] + ); let triggerComponent = ( @@ -328,25 +350,21 @@ export const ActionsMenuBody = ({ [closeOnClick, closeMenu, id, actionMenu] ); - const visible = actionMenu.context.open; + const style = useMemo( + () => ({ + ...actionMenu.floatingStyles, + zIndex: getFloatingUiZIndex(actionMenu.refs.reference) + }), + [actionMenu.floatingStyles, actionMenu.refs.reference] + ); - const ActionMenuContent = ( - - - {children} - - + const menuDataTestId = useMemo(() => `${dataTestId}__menu`, [dataTestId]); + + const { getFloatingProps } = actionMenu; + + const floatingProps = useMemo( + () => getFloatingProps(props), + [getFloatingProps, props] ); const component = ( @@ -359,7 +377,19 @@ export const ActionsMenuBody = ({ root={getFloatingUiRootElement(actionMenu.refs.reference)} > - {ActionMenuContent} + + + {children} + + ) : ( @@ -369,7 +399,15 @@ export const ActionsMenuBody = ({ but in a hidden state ensures that tests pass. * Ideally, we would update all the tests in teamform-app-ui to open the ActionsMenu * before assertion. **/ - ActionMenuContent + + + {children} + + )} diff --git a/lib/components/Popover/index.js b/lib/components/Popover/index.js index 0d3f6b5b..f790542e 100644 --- a/lib/components/Popover/index.js +++ b/lib/components/Popover/index.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useMemo } from "react"; import { useFloating, autoUpdate, @@ -79,9 +79,15 @@ const StyledPopover = styled.div` box-shadow: ${themeGet("shadows.boxDefault")}; user-select: ${(props) => (props.enableSelectAll ? "all" : "auto")}; - pointer-events: none; - opacity: 0; - visibility: hidden; + &.hack-for-legacy-tests { + position: absolute; + pointer-events: none; + opacity: 0; + visibility: hidden; + height: 0; + width: 0; + padding: 0; + } &.visible { opacity: 1; @@ -312,37 +318,42 @@ export default function Popover({ role ]); - const triggerProps = { - ...getReferenceProps({ ref: refs.setReference }), - tabIndex: "0" - }; + const triggerProps = useMemo( + () => ({ + ...getReferenceProps({ ref: refs.setReference }), + tabIndex: "0" + }), + [getReferenceProps, refs.setReference] + ); - const directionClass = - context.placement === DIRECTIONS_MAP[direction] - ? direction - : context.placement; + const directionClass = useMemo( + () => + context.placement === DIRECTIONS_MAP[direction] + ? direction + : context.placement, + [context.placement, direction] + ); - const Popover = ( - - {text} - + const style = useMemo( + () => ({ + ...floatingStyles, + zIndex: getFloatingUiZIndex(context.refs.reference) + }), + [floatingStyles, context.refs.reference] ); + const containsLinks = refs.floating?.current?.querySelectorAll("a").length; + const visiblePopoverClassName = useMemo( + () => `Tooltip popover visible ${directionClass}`, + [directionClass] + ); + + const floatingProps = useMemo( + () => getFloatingProps(props), + [getFloatingProps, props] + ); + return ( - {Popover} + + {text} + ) : ( - Popover + + {text} + )} ) : ( - Popover /* * HACK: Fixing all the broken tests in teamform-app-ui is too time consuming * right this moment with a lot of the tests asserting against Popover items. @@ -389,6 +421,12 @@ export default function Popover({ * Ideally, we would update all the tests in teamform-app-ui to open the Popover * before assertion. **/ + + {text} + ))} {children} diff --git a/package-lock.json b/package-lock.json index 477787b9..9f47a410 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orcs-design-system", - "version": "3.2.36", + "version": "3.2.37", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orcs-design-system", - "version": "3.2.36", + "version": "3.2.37", "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", diff --git a/package.json b/package.json index a73a468a..910aef93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orcs-design-system", - "version": "3.2.36", + "version": "3.2.37", "engines": { "node": "20.12.2" },