Search code examples
htmltwitter-bootstrap-3bootstrap-modalaccessibility

How to prevent keyboard focus outside of modal window of Bootstrap 3?


I am working on accessibility. The expert says that when Modal popup the keyboard user should not interact out side the Modal window. I am using the Bootstrap modal. The Bootstrap version is 3. I think there is a issue regarding this on GitHub!

Here is the code snippet for the Modal.

<div class="modal fade in" id="unenrollmentWarningModal" role="dialog" aria-labelledby="myModalLabel" aria-modal="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" aria-label="Close Dialog" data-dismiss="modal">&times;</button>
                <h2 class="modal-title" id="myModalLabel">Unenrollment Warning!</h2>                    
                <div class="row">
                    <div class="col-md-6" style="text-align: center;">
                        <button class="btn btn-danger btn-block declineUnenrollment enrollButton" data-dismiss="modal">Nevermind!</button>
                    </div>
                    <div class="col-md-6" style="text-align: center;">
                        <button class="btn btn-success btn-block acceptUnenrollment enrollButton">I Understand</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

How can I resolve this issue?


Solution

  • If I get your question right, you need to use the tabindex="-1" attribute. See here: What's the tabindex="-1" in bootstrap for