Tooltip Enhancement
Oat UI automatically converts standard HTMLtitle attributes into styled tooltips with better accessibility support.
How It Works
The tooltip utility:- Finds all elements with a
titleattribute - Converts the
titleto adata-tooltipattribute for custom styling - Adds an
aria-labelif one doesn’t exist - Removes the original
titleto prevent browser default tooltips - Watches for new elements added to the DOM via MutationObserver
Usage
Examples
Basic Tooltip
Icon Buttons
With Existing ARIA Label
Styling Tooltips
Style tooltips using the[data-tooltip] attribute selector:
Progressive Enhancement
The tooltip system works as progressive enhancement:With JavaScript: Custom styled tooltips with better accessibility
Without JavaScript: Browser default
title tooltips still workAccessibility Benefits
- Screen readers: Automatically adds
aria-labelfor better screen reader support - Keyboard users: Tooltips work with keyboard focus (using CSS
:focus) - Touch devices: Removes problematic browser tooltips on touch screens
Sidebar Toggle
A lightweight utility for handling sidebar show/hide functionality in layouts.How It Works
The sidebar utility toggles thedata-sidebar-open attribute on the layout container when a toggle button is clicked, and automatically dismisses the sidebar on mobile when clicking outside.
Usage
Attributes
Applied to the container element that wraps both sidebar and main content. The
data-sidebar-open attribute is toggled on this element.Applied to the sidebar element itself. Used to identify the sidebar for click-outside detection.
Applied to button(s) that toggle the sidebar visibility.
Examples
Basic Sidebar Layout
Multiple Toggle Buttons
Styling
Use thedata-sidebar-open attribute to style the open/closed states:
Mobile Behavior
On screens narrower than 768px, clicking outside the sidebar automatically closes it:The 768px breakpoint matches common mobile/tablet breakpoints. If you need a different breakpoint, you’ll need to modify the source code.
Command Polyfill
Oat UI includes a polyfill for thecommandfor attribute, which provides an alternative to JavaScript for opening and closing dialogs (mainly for Safari compatibility).
Usage
Commands
Opens the dialog as a modal (with backdrop)
Closes the dialog
Toggles the dialog open/closed state (default if
command attribute is omitted)Examples
Modal Dialog
Toggle Dialog
Browser Support
The polyfill automatically activates only in browsers that don’t support the nativecommandfor attribute:
Native support: Uses browser implementation (Chrome, Edge)
Polyfill: Automatically activated (Safari, Firefox)
The polyfill only works with
<dialog> elements. Other use cases of commandfor are not supported.Best Practices
Progressive Enhancement - All utilities work as enhancements; core functionality works without JavaScript
Accessibility First - Utilities automatically add ARIA attributes and screen reader support
Performance - MutationObserver used efficiently to watch for dynamic content
No Dependencies - All utilities use native browser APIs