Bootstrap のモーダルをラップする Backbone ビューがあります。そのビューでは、Esc キーでモーダルを閉じるようにしようとしていますが、それが機能するかどうかは、<div>
のtabindex
属性の存在に依存するようです:
var ModalView = Backbone.View.extend({
el: '#modalOverlay', // is an existing container for modals
events: {
'keypress': function(event) { ... }
},
initialize: function(options) {
// the view pattern
this.compiledTemplate = Handlebars.compile(yesNoQuestionAlertTemplate);
this.options = options;
this.render(options);
},
});
には、エスケープ キーの正しい処理を定義する属性がyesNoQuestionAlertTemplate
含まれています。tabindex
属性を削除すると、エスケープが機能しません。元に戻すと、ハンドラーが正しくトリガーされます。
<div id="yesNoQuestion" class="modal large" tabindex="-1" aria-hidden="true">
<!-- modal definition -->
</div>
この奇妙な依存関係が存在するのはなぜですか?