Unhandled Input triggering when it shouldn't

So I have a menu and a text writer, and when ui_accept is pressed the text deletes itself, but only if it is an unhandled input. The problem is I have a menu which also uses ui_accept, and instead of only the menu triggering, both trigger. Here is the code of the writer that handles deleting the text on an unhandled input:

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("ui_accept"):
		if visible_ratio >= 1.0 and requireInput:
			textFinished.emit()
			queue_free()

What I believe the problem may be is that instead of the buttons checking for input, they send a signal on when they are pressed and the unhandled input isn’t regestering that? I don’t know. Here’s an example of one of the buttons (all of them are coded like this):

func _on_item_pressed() -> void:
	menustate = "Item"
	$"Item Panel".show()
	$"Selection Panel/Item".focus_mode = FOCUS_NONE
	$"Item Panel/VBoxContainer".get_child(0).grab_focus()

Update: I figured out about Viewport.set_input_as_handled` however its doing the exact opposite of what I want. Its making the text delete itself first and then the other code happens.

Update: The problem has been fixed. All that has to happen is focused must be removed from other UI. I am unsure if there is a better way to do this, so if anybody does know, I ask that you respond.

func _unhandled_input(event: InputEvent) -> void:
	if event.is_action_pressed("ui_accept"):
		if visible_ratio >= 1.0 and requireInput:
			textFinished.emit()
			get_viewport().set_input_as_handled()
			queue_free()