Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for popover in nav bar and z-index on ControlledPopover #786

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions packages/panels/src/components/nav-bar/NavBarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { FlatButton, FlatButtonProps } from "@stenajs-webui/elements";
import * as React from "react";
import { forwardRef } from "react";
import cx from "classnames";
import styles from "./NavBarButton.module.css";

export interface NavBarButtonProps extends FlatButtonProps {
selected?: boolean;
}

export const NavBarButton: React.FC<NavBarButtonProps> = ({
selected,
className,
...buttonProps
}) => {
return (
<FlatButton
{...buttonProps}
className={cx(
styles.navBarButton,
selected && styles.selected,
className
)}
/>
);
};
export const NavBarButton = forwardRef<HTMLButtonElement, NavBarButtonProps>(
function ({ selected, className, ...buttonProps }, ref) {
return (
<FlatButton
{...buttonProps}
ref={ref}
className={cx(
styles.navBarButton,
selected && styles.selected,
className
)}
/>
);
}
);
27 changes: 13 additions & 14 deletions packages/panels/src/components/nav-bar/NavBarPopoverButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from "react";
import { ReactNode } from "react";
import { NavBarButton, NavBarButtonProps } from "./NavBarButton";
import { Popover } from "@stenajs-webui/tooltip";
import { Box, Row } from "@stenajs-webui/core";
import { ControlledPopover } from "@stenajs-webui/tooltip";
import { Box, useBoolean } from "@stenajs-webui/core";

type RenderProp = (args: RenderPropArgs) => ReactNode;

Expand All @@ -20,21 +20,20 @@ export const NavBarPopoverButton: React.FC<NavBarPopoverButtonProps> = ({
children,
...navBarButtonProps
}) => {
const [isOpen, , close, toggle] = useBoolean(false);

return (
<Popover
<ControlledPopover
renderTrigger={(props) => (
<Row {...props}>
<NavBarButton {...navBarButtonProps} />
</Row>
<NavBarButton {...navBarButtonProps} {...props} onClick={toggle} />
)}
trigger={"click"}
open={isOpen}
onRequestClose={close}
>
{({ onRequestClose }) => (
<Box>
{content && content({ close: onRequestClose })}
{children}
</Box>
)}
</Popover>
<Box>
{content && content({ close })}
{children}
</Box>
</ControlledPopover>
);
};
8 changes: 6 additions & 2 deletions packages/tooltip/src/components/popover/ControlledPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ControlledPopoverProps extends PropsWithChildren {
disablePadding?: boolean;
restoreFocus?: boolean;
returnFocus?: boolean;
appendTo?: HTMLElement | null | React.MutableRefObject<HTMLElement | null>;
zIndex?: number;
}

const ARROW_WIDTH = 12;
Expand All @@ -44,6 +46,8 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
onRequestClose,
restoreFocus,
returnFocus,
appendTo,
zIndex,
}) => {
const arrowRef = useRef(null);

Expand Down Expand Up @@ -88,7 +92,7 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
{renderTrigger({ ref: refs.setReference, ...getReferenceProps() })}

{isMounted && (
<FloatingPortal>
<FloatingPortal root={appendTo}>
<FloatingFocusManager
context={context}
modal={false}
Expand All @@ -97,7 +101,7 @@ export const ControlledPopover: React.FC<ControlledPopoverProps> = ({
>
<div
ref={refs.setFloating}
style={floatingStyles}
style={{ zIndex, ...floatingStyles }}
{...getFloatingProps}
>
<div
Expand Down
Loading