How to keep focus within modal dialog?

后端 未结 9 939
醉酒成梦
醉酒成梦 2020-12-17 17:29

I\'m developing an app with Angular and Semantic-UI. The app should be accessible, this means it should be compliant with WCAG 2.0. To reach this p

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 18:33

    I used one of the methods suggested by Steven Lambert, namely, listening to keydown events and intercepting "tab" and "shift+tab" keys. Here's my sample code (Angular 5):

    import { Directive, ElementRef, Attribute, HostListener, OnInit } from '@angular/core';
    
    /**
     * This directive allows to override default tab order for page controls.
     * Particularly useful for working around the modal dialog TAB issue
     * (when tab key allows to move focus outside of dialog).
     *
     * Usage: add "custom-taborder" and "tab-next='next_control'"/"tab-prev='prev_control'" attributes
     * to the first and last controls of the dialog.
     *
     * For example, the first control is 
     * and the last one is 

    To use this directive, just import it to your module and add to Declarations section.

提交回复
热议问题