Skip to content

Commit

Permalink
TPP-849 fixed click/focus issues (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
KitoC authored Aug 1, 2024
1 parent 8ae0fa4 commit 84e6b89
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/components/ActionsMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const ActionsMenuBody = ({
>
<div
ref={ref}
style={{ ...actionMenu.floatingStyles }}
style={{ ...actionMenu.floatingStyles, zIndex: 21 }}
aria-labelledby={actionMenu.labelId}
{...actionMenu.getFloatingProps(props)}
className="actionMenu-content"
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Popover/Popover.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {

export const defaultPopover = () => (
<Popover text="Description that explains child element">
<Button>Hover Me!</Button>
<Button onClick={() => alert("Maintains original click")}>Hover Me!</Button>
</Popover>
);
defaultPopover.storyName = "Default";
Expand Down
64 changes: 33 additions & 31 deletions lib/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
useInteractions,
FloatingPortal,
safePolygon,
useClick
FloatingFocusManager
} from "@floating-ui/react";
import themeGet from "@styled-system/theme-get";
import styled from "styled-components";
import Icon from "../Icon";
import { PropTypes } from "prop-types";
import Box from "../Box";

const DIRECTIONS_MAP = {
topLeft: "top-start",
Expand All @@ -36,7 +37,7 @@ const StyledPopoverContainer = styled.div`
transition: all 300ms ease-in-out;
transition-delay: 300ms;
&.isOpen {
&.visible {
opacity: 1;
pointer-events: auto;
}
Expand Down Expand Up @@ -267,11 +268,11 @@ export default function Popover({
ariaLabel,
...props
}) {
const [isOpen, setIsOpen] = useState(false);
const [visible, setVisible] = useState(false);

const { refs, floatingStyles, context } = useFloating({
open: isOpen,
onOpenChange: setIsOpen,
open: visible,
onOpenChange: setVisible,
placement: DIRECTIONS_MAP[direction] || direction || "right",
whileElementsMounted: autoUpdate,
middleware: [
Expand All @@ -286,37 +287,35 @@ export default function Popover({

const hover = useHover(context, { move: false, handleClose: safePolygon() });
const focus = useFocus(context);
const click = useClick(context, {
enabled: true
});
const dismiss = useDismiss(context);
const role = useRole(context, { role: "tooltip" });

const { getReferenceProps, getFloatingProps } = useInteractions([
hover,
focus,
dismiss,
role,
click
role
]);

const triggerProps = {
...getReferenceProps({ ref: refs.setReference })
...getReferenceProps({
ref: refs.setReference
})
};

let triggerComponent = null;

if (variant === "tooltip") {
triggerComponent = (
<TooltipControl {...triggerProps} active={isOpen}>
<TooltipControl {...triggerProps} active={visible} tabIndex="0">
<Icon
transform="grow-4"
icon={["fas", "question-circle"]}
fontSize="2"
/>
</TooltipControl>
);
} else if (children.type.$$typeof === Symbol.for("react.forward_ref")) {
} else if (children?.type?.$$typeof === Symbol.for("react.forward_ref")) {
triggerComponent = cloneElement(children, triggerProps);
} else {
triggerComponent = <div {...triggerProps}>{children}</div>;
Expand All @@ -328,34 +327,37 @@ export default function Popover({
: context.placement;

return (
<div {...props}>
<Box {...props}>
{triggerComponent}

<FloatingPortal>
<FloatingPortal preserveTabOrder={true}>
{text && (
<StyledPopoverContainer
className={`Tooltip ${isOpen ? "isOpen" : ""}`}
className={`Tooltip popover ${visible ? "visible" : ""}`}
ref={refs.setFloating}
style={floatingStyles}
{...getFloatingProps({
onMouseEnter: () => setIsOpen(true),
onMouseLeave: () => setIsOpen(false)
})}
style={{ ...floatingStyles, zIndex: 21 }}
{...getFloatingProps()}
>
<StyledPopover
className={`${directionClass}`}
role="tooltip"
textAlign={textAlign}
width={width}
enableSelectAll={enableSelectAll}
ariaLabel={ariaLabel}
<FloatingFocusManager
initialFocus={context.refs?.reference}
context={context}
modal={false}
>
{text}
</StyledPopover>
<StyledPopover
className={`${directionClass}`}
role="tooltip"
textAlign={textAlign}
width={width}
enableSelectAll={enableSelectAll}
ariaLabel={ariaLabel}
>
{text}
</StyledPopover>
</FloatingFocusManager>
</StyledPopoverContainer>
)}
</FloatingPortal>
</div>
</Box>
);
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orcs-design-system",
"version": "3.2.12",
"version": "3.2.13",
"engines": {
"node": "20.12.2"
},
Expand Down

0 comments on commit 84e6b89

Please sign in to comment.