Problem with making a tab box disappear when clicking outside the box

Godot Version

Godot4.3

Question

Hello everyone,

I am new to Godot.
I was try to make my tab box disappear if I click the mouse outside the box. However, it didn’t work. Here is the script I wrote in the node of the tab box:

func _gui_input(event: InputEvent) → void:
if event is InputEventMouseButton and event.pressed:
# Check if the mouse click occurred outside the tab box area
if not get_global_rect().has_point(event.position):
self.visible = false

Please help me point out the error or if you guys have any idea to make the box disappear.

Many Thanks.

Best regards,
Jing Sun

Your code will not work since it’s not going to detect a click that happens outside it’s boundaries.

My recommendation is using the popup Popup — Godot Engine (stable) documentation in English which has this behaviour by default.

Thanks for reply. But I have figured out the problem.
It’s due to the ColoerRect prevent the signal of clicking.
(Click on buttons underneath a ColorRect - #2 by system)