A curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
jQuery UI provides core utilities and helper functions that support the widget system and can be used independently for common UI tasks.
Advanced element positioning system with collision detection and flexible alignment options.
/**
* Positions element relative to another element with collision detection
* @param {PositionOptions} options - Position configuration
* @returns {jQuery} Positioned element for chaining
*/
$(element).position(options);
/**
* Gets browser scrollbar width
* @returns {number} Scrollbar width in pixels
*/
$.position.scrollbarWidth();
interface PositionOptions {
my?: string; // Position of element to align (default: "center")
at?: string; // Position of target to align to (default: "center")
of?: string | Element | Event; // Target element or position
collision?: string; // Collision handling: "flip", "fit", "flipfit", "none"
using?: (position: {top: number, left: number}, feedback: object) => void; // Custom positioning function
within?: string | Element; // Constraining element (default: window)
}Position Values:
"left", "center", "right", or offset like "left+10""top", "center", "bottom", or offset like "top-5""left top", "center center", "right bottom", etc.Collision Detection:
// Collision handlers available
$.ui.position.fit.left; // Fit collision handler for left edge
$.ui.position.fit.right; // Fit collision handler for right edge
$.ui.position.fit.top; // Fit collision handler for top edge
$.ui.position.fit.bottom; // Fit collision handler for bottom edge
$.ui.position.flip.left; // Flip collision handler for left edge
$.ui.position.flip.right; // Flip collision handler for right edge
$.ui.position.flip.top; // Flip collision handler for top edge
$.ui.position.flip.bottom; // Flip collision handler for bottom edgeUsage Examples:
// Center dialog in window
$('#dialog').position({
my: "center",
at: "center",
of: window
});
// Position tooltip above element
$('#tooltip').position({
my: "center bottom",
at: "center top",
of: "#trigger",
collision: "flip"
});
// Position with custom logic
$('#menu').position({
my: "left top",
at: "left bottom",
of: "#button",
using: function(position, feedback) {
$(this).css(position);
$(this).addClass(feedback.horizontal + " " + feedback.vertical);
}
});Standardized key code constants for keyboard event handling.
// Key code constants
$.ui.keyCode.BACKSPACE; // 8
$.ui.keyCode.COMMA; // 188
$.ui.keyCode.DELETE; // 46
$.ui.keyCode.DOWN; // 40
$.ui.keyCode.END; // 35
$.ui.keyCode.ENTER; // 13
$.ui.keyCode.ESCAPE; // 27
$.ui.keyCode.HOME; // 36
$.ui.keyCode.LEFT; // 37
$.ui.keyCode.PAGE_DOWN; // 34
$.ui.keyCode.PAGE_UP; // 33
$.ui.keyCode.PERIOD; // 190
$.ui.keyCode.RIGHT; // 39
$.ui.keyCode.SPACE; // 32
$.ui.keyCode.TAB; // 9
$.ui.keyCode.UP; // 38Usage Examples:
$(document).keydown(function(event) {
switch(event.keyCode) {
case $.ui.keyCode.ESCAPE:
closeDialog();
break;
case $.ui.keyCode.ENTER:
submitForm();
break;
case $.ui.keyCode.TAB:
// Handle tab navigation
break;
}
});Utilities for managing focus and determining focusable elements.
/**
* Determines if element can receive focus
* @param {Element} element - Element to test
* @param {boolean} hasTabindex - Whether element has explicit tabindex
* @returns {boolean} True if element is focusable
*/
$.ui.focusable(element, hasTabindex);
/**
* Determines if element can be tabbed to
* @param {Element} element - Element to test
* @returns {boolean} True if element is tabbable
*/
$.ui.tabbable(element);
/**
* Custom selectors for focusable elements
*/
$(':focusable'); // Selects all focusable elements
$(':tabbable'); // Selects all tabbable elementsUsage Examples:
// Find all focusable elements in container
var focusableElements = $('#container').find(':focusable');
// Check if specific element can receive focus
if ($.ui.focusable($('#my-element')[0])) {
$('#my-element').focus();
}
// Trap focus within dialog
$('#dialog').on('keydown', function(event) {
if (event.keyCode === $.ui.keyCode.TAB) {
var tabbableElements = $(this).find(':tabbable');
// Handle tab navigation within dialog
}
});Utilities for safely accessing DOM elements and their properties.
/**
* Safely gets document.activeElement avoiding IE errors
* @param {Document} document - Document to check
* @returns {Element} Active element or body if error
*/
$.ui.safeActiveElement(document);
/**
* Safely blurs an element without errors
* @param {Element} element - Element to blur
*/
$.ui.safeBlur(element);Usage Examples:
// Get currently focused element safely
var activeElement = $.ui.safeActiveElement(document);
// Safely blur element before focusing another
$.ui.safeBlur(currentElement);
newElement.focus();Finds the nearest scrollable parent element for positioning calculations.
/**
* Finds the nearest scrollable parent element
* @param {boolean} includeHidden - Include elements with hidden overflow
* @returns {jQuery} Scrollable parent element
*/
$(element).scrollParent(includeHidden);Usage Examples:
// Find scrollable container for positioning
var scrollContainer = $('#element').scrollParent();
// Monitor scroll events on correct container
$('#element').scrollParent().on('scroll', function() {
// Reposition element
});Generates and manages unique IDs for elements that need them.
/**
* Generates unique ID for element if it doesn't have one
* @returns {jQuery} Element for chaining
*/
$(element).uniqueId();
/**
* Removes generated unique ID from element
* @returns {jQuery} Element for chaining
*/
$(element).removeUniqueId();Usage Examples:
// Ensure element has ID for ARIA references
$('#form-field').uniqueId();
var fieldId = $('#form-field').attr('id');
$('#field-label').attr('for', fieldId);
// Clean up generated IDs
$('#form-field').removeUniqueId();Escapes special characters in CSS selectors for safe use.
/**
* Escapes CSS selector special characters
* @param {string} selector - Selector string to escape
* @returns {string} Escaped selector string
*/
$.ui.escapeSelector(selector);Usage Examples:
// Safely use dynamic IDs as selectors
var elementId = 'item:1.2';
var escapedId = $.ui.escapeSelector(elementId);
$('#' + escapedId).addClass('selected');
// Escape user input for selector use
var userInput = $('.special[chars]');
var safeSelector = $.ui.escapeSelector(userInput);Prevents text selection on elements during interactions.
/**
* Disables text selection on element
* @returns {jQuery} Element for chaining
*/
$(element).disableSelection();
/**
* Enables text selection on element
* @returns {jQuery} Element for chaining
*/
$(element).enableSelection();Usage Examples:
// Prevent text selection during drag operations
$('#draggable').draggable({
start: function() {
$(this).disableSelection();
},
stop: function() {
$(this).enableSelection();
}
});
// Disable selection on UI controls
$('.ui-button, .ui-slider').disableSelection();Access to jQuery UI version information.
/**
* jQuery UI version string
*/
$.ui.version; // "1.13.3"Enhanced data storage utilities used by widgets.
/**
* Widget-safe data storage (avoids conflicts)
* @param {string} key - Data key
* @param {any} value - Data value
* @returns {any} Stored value when getting
*/
$(element).data(key, value);Usage Examples:
// Store widget instance data
$('#element').data('ui-widget', widgetInstance);
// Check for existing widget instance
if ($('#element').data('ui-dialog')) {
$('#element').dialog('open');
}Special utilities for form element handling and reset detection.
/**
* Form reset mixin for widgets that need to respond to form resets
*/
$.ui.formResetMixin;
/**
* Gets form element for input
* @returns {jQuery} Form element or empty jQuery object
*/
$(input).form();
/**
* Gets all labels associated with form element
* @returns {jQuery} Associated label elements
*/
$(input).labels();Usage Examples:
// Handle form reset in custom widget
$.widget('ui.customWidget', {
_create: function() {
this._on(this.element.form(), {
reset: this.refresh
});
}
});
// Update labels when widget changes
var labels = $('#input').labels();
labels.addClass('widget-active');// Position utility types
interface PositionOptions {
my?: string;
at?: string;
of?: string | Element | Event | { pageX: number, pageY: number };
collision?: string;
using?: (position: { top: number, left: number }, feedback: PositionFeedback) => void;
within?: string | Element;
}
interface PositionFeedback {
element: {
element: jQuery;
left: number;
top: number;
width: number;
height: number;
};
target: {
element: jQuery;
left: number;
top: number;
width: number;
height: number;
};
horizontal: 'left' | 'center' | 'right';
vertical: 'top' | 'middle' | 'bottom';
important: 'horizontal' | 'vertical';
}
// Key code enumeration
interface KeyCodes {
BACKSPACE: 8;
COMMA: 188;
DELETE: 46;
DOWN: 40;
END: 35;
ENTER: 13;
ESCAPE: 27;
HOME: 36;
LEFT: 37;
PAGE_DOWN: 34;
PAGE_UP: 33;
PERIOD: 190;
RIGHT: 39;
SPACE: 32;
TAB: 9;
UP: 38;
}
// Utility function signatures
type FocusableTest = (element: Element, hasTabindex?: boolean) => boolean;
type TabbableTest = (element: Element) => boolean;
type SafeActiveElement = (document: Document) => Element;
type SafeBlur = (element: Element) => void;
type EscapeSelector = (selector: string) => string;