Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const containedElements = [
const SavedPipelinesButton: React.FunctionComponent = () => {
const [isVisible, setIsVisible] = useState(false);
return (
<InteractivePopover
<InteractivePopover<HTMLButtonElement>
className={savedAggregationsPopoverStyles}
// To prevent popover from closing when confirmation modal is shown
containedElements={containedElements}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const closeButtonStyles = css({
right: spacing[2],
});

type InteractivePopoverProps = {
type InteractivePopoverProps<TriggerElement extends HTMLElement> = {
Copy link
Contributor Author

@kraenhansen kraenhansen Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have followed a pattern and be named T but it felt a bit too vague 🤔

className?: string;
children: React.ReactNode;
trigger: (triggerProps: {
onClick: React.MouseEventHandler<HTMLButtonElement>;
ref: React.LegacyRef<HTMLButtonElement>;
onClick: React.MouseEventHandler<TriggerElement>;
ref: React.Ref<TriggerElement>;
children: React.ReactNode;
}) => React.ReactElement;
hideCloseButton?: boolean;
Expand All @@ -64,7 +64,7 @@ type InteractivePopoverProps = {
'align' | 'justify' | 'spacing' | 'popoverZIndex'
>;

function InteractivePopover({
function InteractivePopover<TriggerElement extends HTMLElement>({
className,
children,
trigger,
Expand All @@ -79,9 +79,9 @@ function InteractivePopover({
popoverZIndex,
containerClassName,
closeButtonClassName,
}: InteractivePopoverProps): React.ReactElement {
}: InteractivePopoverProps<TriggerElement>): React.ReactElement {
const darkMode = useDarkMode();
const triggerRef = useRef<HTMLButtonElement>(null);
const triggerRef = useRef<TriggerElement>(null);
const closeButtonRef = useRef<HTMLButtonElement>(null);
const popoverContentContainerRef = useRef<HTMLDivElement>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ const SignalPopover: React.FunctionComponent<SignalPopoverProps> = ({
`calc(14px + ${' insight'.length}ch)`;

return (
<InteractivePopover
<InteractivePopover<HTMLButtonElement>
className={cx(
popoverStyles,
// If trigger is not visible, we are in this weird state where trigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const QueryHistoryButtonPopover = ({
}, [setIsOpen]);

return (
<InteractivePopover
<InteractivePopover<HTMLButtonElement>
className={queryHistoryPopoverStyles}
trigger={({ onClick, ref, children }) => (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function ConnectionsFilterPopover({
onMouseLeave={handleButtonMouseLeave}
active={open}
aria-label="Filter connections"
ref={ref as React.Ref<unknown>}
ref={ref}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's possible to pass the ref here without having to provide an explicit type parameter to the InteractivePopover above, is possible because the IconButton use the forwardRef utility internally.

>
<Icon glyph="Filter" />
{isActivated && (
Expand Down
Loading