tab order for links in a simplemodal dialog

≯℡__Kan透↙ 提交于 2019-12-05 18:06:43

I just ran into this problem myself. Here's what I worked out so far. Simplemodal has to add to tab navigation in the functions 'watchTab' and 'focus' in order to keep focus inside the modal. It achieves this by recording the first and last inputs and when you tab past them, focusing on the appropriate other one. Unfortunately, it is only looking at the inputs and not the links. This means that you can only tab to the links that are located between the first and last input elements. You can overwrite or modify these functions to get the desired behavior. Something like this:

replace line 473 with var input = $('#simplemodal-data :input:visible:enabled, #simplemodal-data a:visible')[p]();

replace line 592 with s.inputs = $('#simplemodal-data :input:visible:enabled, #simplemodal-data a:visible');

This is a simplistic solution which will probably break in the case of a browser which doesn't tab over links. I will try to come up with something better.

I found an solution with SimpleModal 1.4.2

On line 609

Change this s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);

To this s.inputs = $('a:visible, :input:enabled:visible', s.d.data[0]).filter(':first,:last');

s.d.data[0]s.d.data[0]note also that neither the existing implementation, with following selector:

s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);

nor the answer above, properly handle tabindexes - the switch after last element will be done the first element in dom, not the one with the least tabindex (and vice versa) to fix this, you must do sth like this:

s.inputs = $.merge(self.smallestTabindex(s.d.data[0]), self.biggestTabindex(s.d.data[0]));

where the functions smallest/biggestTabindex return the appropriate elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!