Check if Focus is outside of TextField and Grid

So I have a TextField and a Grid which works as a type of combobox. I want to close the popup if the focus outside of the textfield and the grid. I already tried using the blur and focus events but at the time the blur event from the textfield is called the grid doesnt get focus. What should I do here?

If both are wrapped e.g. in a div, you can apply some Javascript on the client wide which checks that the focus is within the div (field, grid)

Can I do this with Vaadin?

Sure, you can execute any Javascript you want

I will try that, thank you

So I got some news: The Grid is very much not in the same div. It appears to be in another shadow dom

Before it gets crazy: why are you doing it like this? You can theoretically use a normal combo box and just add a lit template based renderer with multiple columns instead of a full fledged grid

Another batch of news: I found a function on the client side that a coworker had implemented that works just fine. Thank you for your advice tho