Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/),
and this project adheres to [Semantic Versioning](https://semver.org/).

## [1.0.0] - 2026-03-16

### Added

- Add Tooltip component with CSS Anchor Positioning and JS fallback (Firefox/older browsers use JS fallback via `useTooltipPosition`) ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Dogfood Tooltip on all icon-only buttons across the library (close, dismiss, remove, toggle, clear) ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Fix dialog drag transform to unblock `position:fixed` descendants from escaping dialog bounds ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Fix tooltip clipping — use `position:fixed` in CSS Anchor path so tooltips paint above dialog edges ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Widen dialog `max-width` from 32em to 40em for more comfortable content ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Add WCAG 2.5.8 touch target minimums to PasswordInput toggle and Toast dismiss buttons ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))
- Extract shared CSS patterns to composable classes in `shared.css` ([#118](https://github.com/coloneljade/auldrant-ui/pull/118))

## [0.26.1] - 2026-03-16

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function App() {
| `Dialog` | Dismissible dialog (Escape, backdrop, X button) | `open`, `title`, `onClose`, `message?`, `defaultAction?` |
| `Dropdown` + `DropdownItem` | Trigger button with a Popover API menu, full keyboard support, and type-ahead navigation | `trigger` on Dropdown; `onSelect?`, `disabled?` on DropdownItem |
| `Modal` | Action-required modal (`role="alertdialog"`) | `open`, `title`, `onCancel`, `defaultAction`, `focusCancel?` |
| `Tooltip` | Hover/focus tooltip with CSS Anchor Positioning and accessible `aria-describedby` wiring | `content`, `delay?` |

### Layout

Expand Down
3 changes: 3 additions & 0 deletions dev/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { TableSection } from './sections/TableSection';
import { TextareaSection } from './sections/TextareaSection';
import { ToastSection } from './sections/ToastSection';
import { ToggleSection } from './sections/ToggleSection';
import { TooltipSection } from './sections/TooltipSection';

/** All dev sections — used for both tab layout and global search filtering. */
const ALL_SECTIONS: { key: string; Section: FunctionComponent }[] = [
Expand Down Expand Up @@ -75,6 +76,7 @@ const ALL_SECTIONS: { key: string; Section: FunctionComponent }[] = [
{ key: 'dropdown', Section: DropdownSection },
{ key: 'modal', Section: ModalSection },
{ key: 'toast', Section: ToastSection },
{ key: 'tooltip', Section: TooltipSection },
];

/** Extract tab ID from /tests/tab/:id (ignoring any suffix), falling back to 'inputs'. */
Expand Down Expand Up @@ -221,6 +223,7 @@ export const TestPage: FunctionComponent = () => {
<DialogSection />
<ModalSection />
<DropdownSection />
<TooltipSection />
</Tab>
</TabGroup>
)}
Expand Down
40 changes: 40 additions & 0 deletions dev/sections/TooltipSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Button from '@components/Button';
import Icon, { IconName } from '@components/Icon';
import Tooltip from '@components/Tooltip';
import type { FunctionComponent } from 'preact';

export const TooltipSection: FunctionComponent = () => (
<div class="dev-section">
<h2>Tooltip</h2>

<h3>Default — button trigger (200ms delay)</h3>
<div class="dev-row">
<Tooltip content="Save your work">
<Button label="Save" onClick={() => {}} />
</Tooltip>
</div>

<h3>Long content — wrapping text</h3>
<div class="dev-row">
<Tooltip content="This action will permanently delete the selected items and cannot be undone. Make sure you have a backup.">
<Button label="Delete all" onClick={() => {}} />
</Tooltip>
</div>

<h3>Icon trigger — aria-describedby use case</h3>
<div class="dev-row">
<Tooltip content="Upload a file">
<button type="button" aria-label="Upload">
<Icon name={IconName.upload} />
</button>
</Tooltip>
</div>

<h3>Instant — delay=0</h3>
<div class="dev-row">
<Tooltip content="Appears immediately" delay={0}>
<Button label="Hover me" onClick={() => {}} />
</Tooltip>
</div>
</div>
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auldrant/ui",
"version": "0.26.1",
"version": "1.0.0",
"type": "module",
"description": "Accessible Preact component library with design tokens and CSS modules",
"author": "Colonel Jade",
Expand Down
33 changes: 18 additions & 15 deletions src/components/Chip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Icon, { IconName } from '@components/Icon';
import Tooltip from '@components/Tooltip';
import type { IBaseProps } from '@scripts/types';
import { cx } from '@scripts/utils';
import styles from '@styles/Chip.module.css';
Expand Down Expand Up @@ -53,21 +54,23 @@ const Chip: FunctionComponent<IChipProps> = (props) => {
>
{label}
{onRemove && (
<button
type="button"
class={styles.chipRemove}
aria-label={removeLabel}
disabled={disabled}
onClick={onRemove}
onKeyDown={(e) => {
if (e.key === 'Backspace' || e.key === 'Delete') {
e.preventDefault();
onRemove();
}
}}
>
<Icon name={IconName.dismiss} />
</button>
<Tooltip content={removeLabel}>
<button
type="button"
class={styles.chipRemove}
aria-label={removeLabel}
disabled={disabled}
onClick={onRemove}
onKeyDown={(e) => {
if (e.key === 'Backspace' || e.key === 'Delete') {
e.preventDefault();
onRemove();
}
}}
>
<Icon name={IconName.dismiss} />
</button>
</Tooltip>
)}
</span>
);
Expand Down
25 changes: 14 additions & 11 deletions src/components/PasswordInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FormField from '@components/FormField';
import Icon, { IconName } from '@components/Icon';
import Tooltip from '@components/Tooltip';
import { useSignal } from '@preact/signals';
import type { IFieldProps } from '@scripts/types';
import styles from '@styles/PasswordInput.module.css';
Expand Down Expand Up @@ -59,17 +60,19 @@ const PasswordInput: FunctionComponent<IPasswordInputProps> = (props) => {
disabled={disabled}
onInput={onInput && ((e) => onInput((e.target as HTMLInputElement).value))}
/>
<button
type="button"
class={styles.toggle}
disabled={disabled}
aria-label={visible.value ? 'Hide password' : 'Show password'}
onClick={() => {
visible.value = !visible.value;
}}
>
<Icon name={visible.value ? IconName.hidePassword : IconName.showPassword} />
</button>
<Tooltip content={visible.value ? 'Hide password' : 'Show password'}>
<button
type="button"
class={styles.toggle}
disabled={disabled}
aria-label={visible.value ? 'Hide password' : 'Show password'}
onClick={() => {
visible.value = !visible.value;
}}
>
<Icon name={visible.value ? IconName.hidePassword : IconName.showPassword} />
</button>
</Tooltip>
</div>
</FormField>
);
Expand Down
27 changes: 15 additions & 12 deletions src/components/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FormField from '@components/FormField';
import Icon, { IconName } from '@components/Icon';
import Tooltip from '@components/Tooltip';
import type { IFieldProps } from '@scripts/types';
import styles from '@styles/SearchInput.module.css';
import type { FunctionComponent } from 'preact';
Expand Down Expand Up @@ -55,18 +56,20 @@ const SearchInput: FunctionComponent<ISearchInputProps> = (props) => {
}}
/>
{value && (
<button
type="button"
class={styles.clearButton}
disabled={disabled}
aria-label="Clear search"
onClick={() => {
onInput?.('');
onClear?.();
}}
>
<Icon name={IconName.dismiss} />
</button>
<Tooltip content="Clear search">
<button
type="button"
class={styles.clearButton}
disabled={disabled}
aria-label="Clear search"
onClick={() => {
onInput?.('');
onClear?.();
}}
>
<Icon name={IconName.dismiss} />
</button>
</Tooltip>
)}
</div>
</FormField>
Expand Down
14 changes: 11 additions & 3 deletions src/components/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Icon, { IconName } from '@components/Icon';
import Tooltip from '@components/Tooltip';
import { useSignal } from '@preact/signals';
import useTimer from '@scripts/hooks';
import type { IBaseProps } from '@scripts/types';
Expand Down Expand Up @@ -95,9 +96,16 @@ const Toast: FunctionComponent<IToastProps> = (props) => {
{title && <p class={styles.toastTitle}>{title}</p>}
<p class={styles.toastMessage}>{message}</p>
</div>
<button type="button" class={styles.toastDismiss} aria-label={dismissLabel} onClick={dismiss}>
<Icon name={IconName.dismiss} />
</button>
<Tooltip content={dismissLabel}>
<button
type="button"
class={styles.toastDismiss}
aria-label={dismissLabel}
onClick={dismiss}
>
<Icon name={IconName.dismiss} />
</button>
</Tooltip>
</output>
);
};
Expand Down
149 changes: 149 additions & 0 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { useSignal } from '@preact/signals';
import type { IBaseProps } from '@scripts/types';
import useTooltipPosition from '@scripts/useTooltipPosition';
import { cx } from '@scripts/utils';
import styles from '@styles/Tooltip.module.css';
import type { ComponentChildren, FunctionComponent, VNode } from 'preact';
import { cloneElement, isValidElement } from 'preact';
import { useEffect, useId, useRef } from 'preact/hooks';

/** Props for {@link Tooltip}. */
interface ITooltipProps extends IBaseProps {
/** Element that triggers the tooltip — receives aria-describedby automatically. */
children: ComponentChildren;
/** Tooltip text or inline content. Must not contain interactive elements. */
content: ComponentChildren;
/** Delay in ms before showing on hover. Default: 200. Set to 0 to disable. */
delay?: number;
}

/**
* Hover/focus tooltip with CSS Anchor Positioning and accessible aria-describedby wiring.
* Wrap any interactive element to provide a visible label hint for sighted users.
*
* The child element automatically receives `aria-describedby` pointing to the tooltip.
* Uses CSS Anchor Positioning on Chrome 131+/Safari 26+; a JS fallback handles Firefox
* and earlier browsers.
*
* @example
* ```tsx
* <Tooltip content="Save your work">
* <Button label="Save" />
* </Tooltip>
* ```
*/
const Tooltip: FunctionComponent<ITooltipProps> = (props) => {
const { children, content, delay = 200, class: className } = props;

const isVisible = useSignal(false);
const tooltipId = useId();
const wrapperRef = useRef<HTMLSpanElement>(null);
const triggerRef = useRef<HTMLSpanElement>(null);
const tooltipRef = useRef<HTMLDivElement>(null);
const timerRef = useRef<number | null>(null);

useTooltipPosition(isVisible.value, triggerRef, tooltipRef, wrapperRef);

// All hover and focus events wired as imperative DOM listeners so the static
// <span> wrapper carries zero JSX event handler attributes. Any JSX handler
// on a non-interactive element triggers biome's noStaticElementInteractions
// rule — this structure avoids that entirely without adding a spurious role.
// delay is a dep so re-hovering after a prop change uses the current value.
useEffect(() => {
const wrapper = wrapperRef.current;
if (!wrapper) {
return;
}

const clearTimer = () => {
if (timerRef.current !== null) {
clearTimeout(timerRef.current);
timerRef.current = null;
}
};

const onMouseEnter = () => {
clearTimer();
if (delay > 0) {
timerRef.current = window.setTimeout(() => {
isVisible.value = true;
timerRef.current = null;
}, delay);
} else {
isVisible.value = true;
}
};

const onMouseLeave = () => {
clearTimer();
isVisible.value = false;
};

// focusin/focusout bubble from focused descendants — no delay on focus
// (WAI-ARIA requirement: tooltip must appear immediately on keyboard focus).
const onFocusIn = () => {
clearTimer();
isVisible.value = true;
};

const onFocusOut = () => {
clearTimer();
isVisible.value = false;
};

wrapper.addEventListener('mouseenter', onMouseEnter);
wrapper.addEventListener('mouseleave', onMouseLeave);
wrapper.addEventListener('focusin', onFocusIn);
wrapper.addEventListener('focusout', onFocusOut);
return () => {
wrapper.removeEventListener('mouseenter', onMouseEnter);
wrapper.removeEventListener('mouseleave', onMouseLeave);
wrapper.removeEventListener('focusin', onFocusIn);
wrapper.removeEventListener('focusout', onFocusOut);
};
}, [delay]);

// Escape to dismiss — document-level so it fires even when the tooltip is
// shown via hover with nothing focused (injecting onKeyDown into the child
// would not cover that case). Not stopPropagation — a parent dialog's Escape
// is handled via the native cancel event, a separate event type, unaffected.
useEffect(() => {
if (!isVisible.value) {
return;
}
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
isVisible.value = false;
}
};
document.addEventListener('keydown', onKeyDown);
return () => document.removeEventListener('keydown', onKeyDown);
}, [isVisible.value]);

// Inject aria-describedby into the child element if it is a single VNode;
// otherwise wrap in a span so the attribute is still applied.
const trigger = isValidElement(children)
? cloneElement(children as VNode<{ 'aria-describedby'?: string }>, {
'aria-describedby': tooltipId,
})
: ((<span aria-describedby={tooltipId}>{children}</span>) as ComponentChildren);

return (
<span ref={wrapperRef} class={cx(styles.tooltip, className)} data-placement="above">
<span ref={triggerRef} class={styles.tooltipTriggerAnchor}>
{trigger}
</span>
<div
id={tooltipId}
ref={tooltipRef}
role="tooltip"
aria-hidden={isVisible.value ? undefined : 'true'}
class={cx(styles.tooltipContent, isVisible.value && styles.visible)}
>
{content}
</div>
</span>
);
};

export default Tooltip;
Loading
Loading