Skip to content

Fix: menu popup can not be closed again #35452

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

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -208,6 +208,7 @@ function BaseReportActionContextMenu({
undefined,
undefined,
filteredContextMenuActions,
true,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function PopoverReportActionContextMenu(_props: never, ref: ForwardedRef<ReportA
const [disabledActions, setDisabledActions] = useState<ContextMenuAction[]>([]);

const contentRef = useRef<View>(null);
const anchorRef = useRef<View | HTMLDivElement>(null);
const anchorRef = useRef<HTMLDivElement | null>(null);
const dimensionsEventListener = useRef<EmitterSubscription | null>(null);
const contextMenuAnchorRef = useRef<ContextMenuAnchor | null>(null);
const contextMenuTargetNode = useRef<HTMLElement | null>(null);
Expand Down Expand Up @@ -163,11 +163,14 @@ function PopoverReportActionContextMenu(_props: never, ref: ForwardedRef<ReportA
isPinnedChat = false,
isUnreadChat = false,
disabledOptions = [],
isThreeDotButton = false,
) => {
const {pageX = 0, pageY = 0} = extractPointerEvent(event);
contextMenuAnchorRef.current = contextMenuAnchor;
contextMenuTargetNode.current = event.target as HTMLElement;

if (isThreeDotButton) {
anchorRef.current = event.target as HTMLDivElement;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (isThreeDotButton) {
anchorRef.current = event.target as HTMLDivElement;
}
anchorRef.current = event.target as HTMLDivElement;

Then control the prop value based on the new prop.

	anchorRef={shouldCloseOnTarget && anchorRef}

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 think we should

        if (shouldCloseOnTarget) {
            anchorRef.current = event.target as HTMLDivElement;
        } else {
            anchorRef.current = null;
        }

and keep anchorRef = {anchorRef} to avoid changing anchorRef type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I am not fully sold on this. IMO, anchorRef should always be set and we should control if we want to close the menu on target via a different way.

Copy link
Member

Choose a reason for hiding this comment

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

Let's see what Internal Engineer has to say about this.

setInstanceID(Math.random().toString(36).substr(2, 5));

onPopoverShow.current = onShow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ShowContextMenu = (
isPinnedChat?: boolean,
isUnreadChat?: boolean,
disabledOptions?: ContextMenuAction[],
isThreeDotButton?: boolean,
) => void;

type ReportActionContextMenu = {
Expand Down Expand Up @@ -113,6 +114,7 @@ function showContextMenu(
isPinnedChat = false,
isUnreadChat = false,
disabledActions: ContextMenuAction[] = [],
isThreeDotButton = false,
) {
if (!contextMenuRef.current) {
return;
Expand Down Expand Up @@ -140,6 +142,7 @@ function showContextMenu(
isPinnedChat,
isUnreadChat,
disabledActions,
isThreeDotButton,
);
}

Expand Down