To demonstrate the issue clearly, checkout this codepen - https://codepen.io/hunyoboy/pen/zmLZLE. Try opening all the stacked modals. Once all are opened, use the ESC key to close them one by one. If you notice, pressing “ESC” will not close all the modals.
I’m not sure if this intentional or just a bad design but I certainly consider this a bug on my current project. The main reason why this happens is because as you opened a new modal, the lower stacked modal loses its focus since the new one took over. So the fix is somehow to return the focus to the next lower stacked modal once you close the higher stacked modal. I ended up with a fix here - https://codepen.io/hunyoboy/pen/xaNKrW
If you have another solution on this issue, please let me know. Thanks for reading :).