Currently, I am in the process of developing a component library in Angular 2 for our app teams to utilize. One of the components I recently created is a modal, but I am encountering some accessibility challenges. Specifically, I want the modal to close when the user presses the ESC key, unless there is an internal component like a dropdown that should handle the ESC event instead. The flexible structure of the modal, which allows different content to be displayed using <ng-content>
, creates additional complexity because I cannot predict what will be inside the modal.
Ideally, I would like to find a way to check if a projected component is listening for (keydown)
or (keyup)
events, or better yet, determine if another component has already handled the event. If this were an application I was building instead of providing a library, I could add attributes to the events within the projected components or create a custom event handler as discussed here. Unfortunately, those options are not available to me in this context.