How can I make a UI menu appear with its top left corner in the position of the mouse on screen?

I made a menu that appears when you right click an object. It’s just a panel, and i need to make the top left corner of the panel be in the position where i clicked. I am using transform.position to place the menu on the position of the mouse, but the result is that the menu appears with its center on the mouse position. When I try to change the position with a new Vector3, the menu shrinks for some reason. Is there a better way to achieve the result?

using UnityEngine.UI;

public RectTransform menu; //This one is already in your canvas, just turn the gameObject off

void Update(){
if (//whatever key pressed){
menu.gameObject.SetActive(true);
Vector2 menuPosition = Input.mousePosition;
menu.position = new Vector3(menuPosition.x, menuPosition.y, 0); //You might have to divide by screen heigh/length and some variable if your canvas is set to 800x600 for example, and your screenresolution is different.
}
}