Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

joelpurra/skipontab

Repository files navigation

SkipOnTab javascript library

Donate $5 now Donate $25 now Donate $100 now More options

  • A jQuery plugin to
    • exempt selected fields from the forward tab order.
    • include excluded fields in the reverse tab order.

⚠️ This project has been archived

No future updates are planned. Feel free to continue using it, but expect no support.

When using tab to navigate through a form, skipping some fields will reduce key presses for the normal use cases. Skipped fields can still be navigated to by keyboard; once skipped and focusing the next form field, use shift-tab to step back. Mouse or touch navigation is unaffected.

This library is most useful when the users are familiar with the form, and uses it regularly. Casual users may not feel as comfortable - then again, if they are already using the tab button, they might see it as an optimization.

Get it

bower install jquery-skipontab

Demos

Usage

HTML

<!-- Can be applied to skippable elements one by one -->
<input type="text" data-skip-on-tab="true" />
<textarea data-skip-on-tab="true"></textarea>
<a href="https://joelpurra.com/" data-skip-on-tab="true">Joel Purra</a>

<input type="button" value="This button is not skipped" />

<!-- Can be applied using a class name -->
<input type="text" value="" class="skip-on-tab" />

<!-- Can be applied to all skippable elements within a container -->
<ol data-skip-on-tab="true">
	<li><input type="checkbox" /> Checkbox</li>
	<li><input type="checkbox" /> Another checkbox</li>

	<!-- Can be explicitly exluded from skipping -->
	<li><input type="checkbox" data-skip-on-tab="false" /> Important checkbox</li>
	<li><input type="checkbox" class="disable-skip-on-tab" /> Another important checkbox</li>
</ol>

Javascript

// Apply skip on tab to the selected elements/containers
$(selector).skipOnTab();

// Exclude skip on tab to the selected elements/containers
$(selector).skipOnTab(false);

// Equivalent static function
JoelPurra.SkipOnTab.skipOnTab($(selector));
JoelPurra.SkipOnTab.skipOnTab($(selector), false);

Skippable elements

Elements that can be focused/tabbed include <input>, <select>, <textarea>, <button> and <a href="..."> (the href attribute must exist and the tag must have some contents). These are also the elements that can be skipped.

Note that <input type="hidden" />, <a> (without href or empty contents), disabled="disabled" or display: none; elements cannot be focused.

Static elements

Static skippable html elements can have, or be contained within elements that have, the attribute data-skip-on-tab="true" or the class .skip-on-tab. They are enabled automatically when the library has been loaded/executed.

Dynamic elements

Dynamic elements are initialized to SkipOnTab in code after adding them to the DOM; $("#my-optional-input").skipOnTab(). This is not necessary if the added element already is contained within an element that is marked for skipping. You can also call .skipOnTab() on containers.

Containers

When SkipOnTab is applied to html containers, like <div>, <ul> or <fieldset>, all skippable child elements are implicitly skipped. This applies to static html and subsequently added child elements.

Disabling skipping

Skippable elements, or containers with skippable children, marked with class .disable-skip-on-tab or attribute data-skip-on-tab="false" are never skipped. Disabling can also be done dynamically on elements/containers with $(selector).skipOnTab(false). If skipping is disabled for the element when it receives focus, or any of its elements parents, it will not be skipped. Disabling skipping takes precedence over enabling skipping.

Original purpose

Developed to skip less used form fields in a web application for registering and administering letters. Examples of skipped fields are dropdowns with sensible defaults, the second address line fields in address forms and buttons for seldom used actions.

SkipOnTab does not rely on setting tabindex on elements - it uses javascript events instead. Read more on the wiki page SkipOnTab versus tabindex.

Dependencies

SkipOnTab's runtime dependencies are

Browser compatibility

Should be about as compatible as jQuery is, since most functions depend on jQuery's normalization. You are engouraged to run the SkipOnTab test suite and then report any issues.

Todo

  • Break out reusable key press functions from tests.
  • Investigate how usable data-skip-on-tab="#id-of-next-element-in-the-order" would be.

See also

PlusAsTab's sister projects.

  • PlusAsTab - use the + key on the keypad as a tab key equivalent for faster numeric input.
  • EmulateTab - the tab emulator used by both SkipOnTab and PlusAsTab.

SkipOnTab copyright © 2011, 2012, 2013, 2014, 2015, 2016, 2017, The Swedish Post and Telecom Authority (PTS). All rights reserved. Released under the BSD license. Developed for PTS by Joel Purra. Your donations are appreciated!