Git Product home page Git Product logo

jquery-trap-input's Introduction

jQuery trap input plugin

The jQuery trap input plugin implements input trapping as described by the Web Accessibility Initiative.

Why this is useful

As explained in the W3C document aria-practices in the WAI, modal dialogs should trap the keyboard input.

This means that when a user navigates in the dialog using the tab key (with or without shift), the focus should not go outside of the dialog.

jQuery UI Dialog implements this when the dialog is modal, in a limited way, but I found this in no other libraries.

This implementation is better than the one is jQuery UI Dialog: faster, it works with tabIndex attributes (see the dialog example), and it works with other browsers than Firefox.

This library does not work with usemaps for now.

I think it is a must for the accessibility of our rich web pages, so I made this plugin because I thought at first that jQuery UI didn't implement this.

Usage

Include jQuery and this plugin. Then, call the trap function on the element which should trap the tabbing.

Here is a simple example

<!doctype html>

<html>
	<head>
		<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
		<script src='jquery.trap.min.js'></script>
	<script>
	function init() {
		/* this is the init function
		 *we find all elements with the "trap" class and we call the
		 * "trap" function on it.
		 * Yes, this is _that_ simple.
		 */
		$(".trap").trap();
	}
	
	// on dom content ready
	$(init);
	</script>
	</head>
<body>
<div id='first'>
<a href='http://perdu.com'>perdu</a>
<a href='http://google.fr'>google</a>
<a href='http://lemonde.fr'>le monde</a>

</div>
<!-- once the focus get inside, it will be trapped -->
<div id='second' class='trap'>
<a href='http://perdu.com'>perdu</a>
<a href='http://google.fr'>google</a>
<a href='http://lemonde.fr'>le monde</a>

</div>

<div id='third'>
<a href='http://perdu.com'>perdu</a>
<a href='http://google.fr'>google</a>
<a href='http://lemonde.fr'>le monde</a>

</div>

</body>

</html>

See the examples directory for some more examples.

Known problems

Version 1.1.0 had problems with IE6 and IE7 which got fixed in version 1.2.0

We don't support Opera's navigation shortcuts.

Useful links

jquery-trap-input's People

Contributors

julienw avatar m-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jquery-trap-input's Issues

What about untrapping?

Haven't even tried it yet, but I couldn't find any information on how to "untrap" focus from an element.

If you have to remove the element from the DOM for it to work it should be listed somewhere in the doco, otherwise an untrap function would be useful.

Is this still supported?

Hi
We are upgrading an app to the latest jQuery and found that the original suppliers had used your library in this Git repository. Is this still supported - or do you know of any equivalents for the most up to date jQuery version?
Thanks
Pete

Non-tabbable elements become part of tab order in IE7

Hi,

First up, thanks for a really useful plugin! :-)

This is working fine for me - except in IE7:

In IE7 elements that aren't natively tabbable become part of the tab order.

This is problematic for accessibility as the user has to tab through elements that aren't inputs or links, to access ones that are, and the visual focus is lost at this time, so it affects both sighted and screen reader users.

In your complex 'trapping dialog' example (http://julienw.github.com/jquery-trap-input/examples/dialog.html), this means that the some div containers and the .ui-resizable-handle elements become part of the tab order.

In my usage the markup is more complex, with more div elements wrapping inputs, plus there are label elements etc. All of these seem to become part of the tab order in IE7 when the trap input plugin is active on the jQuery UI modal.

To replicate this:

  1. Open IE8
  2. Navigate to http://julienw.github.com/jquery-trap-input/examples/dialog.html
  3. Click the broken page icon in the browser chrome to enter Compatibility (IE7) View (you can use IE7 if you prefer but it doesn't have a Console out of the box)
  4. Click your 'trapping dialog' button to launch the modal
  5. Open the developer toolbar: Tools > Developer tools
  6. Select the toolbar's Script tab
  7. Open the toolbar's Console
  8. Enter this string into the Console and hit Enter: $('*').bind('focus', function(e) { $(e.target).css('border', '1px solid red'); });
  9. Tab through the modal
  10. Every element that traps the focus will get a red border

This may also affect IE6, I don't have a Console I can use in that browser, but am experiencing a lot of tab presses between inputs in the same way as IE7.

Thanks,
Dan

Include specific external elements

This works great, except that there's no way for my users to toggle the "close dialog" button, as it's a global overlay not within the same menu. I'll see if I can change my code to make it work as I need it to, but it'd be awesome to say "trap within this div, except also include this one"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.