i am coding a Dialog component, and it will allow to close by pressing the Esc key on the keyboard and it works fine.
The problem I have is when using multiple Dialogs on top of each other, when I press Esc they all get closed while I just want to close the top Dialog one by one.
The point is know the dialog isOnTop or isNotOnTop and blocking keyboard event. I have tried using props drilling to check if DialogB is opened then DialogA isNotOnTop and prevent to closing but with more complex components this method seems difficult.
Can anyone give me some suggestions on how to implement my idea in a better way? I'm a newbie with reactjs, thanks.
This is how the idea looklike: youtube
Below code is written on codesanbox.