Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat: add tooltip to input clear button (#6354)

athzf09c260b7ebf
diff --git a/.changeset/bright-waves-clear.md b/.changeset/bright-waves-clear.md
new file mode 100644
index 0000000000..8878ff651f
--- /dev/null
+++ b/.changeset/bright-waves-clear.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Show each shared InputClearButton's contextual action label in a tooltip. Clearable inputs now give sighted users the same specific action name already available to assistive technology.
+
+@athz
diff --git a/packages/core/src/Field/InputClearButton.test.tsx b/packages/core/src/Field/InputClearButton.test.tsx
index a2974f4c27..d74ecfbf7c 100644
--- a/packages/core/src/Field/InputClearButton.test.tsx
+++ b/packages/core/src/Field/InputClearButton.test.tsx
@@ -8,8 +8,8 @@
* @output Unit tests for the shared clear-button primitive
* @position Testing; validates InputClearButton.tsx — the single home for the
* clearable input family's clear (✕) affordance and its theme target. Covers
- * the accessible name, the click callback, the decorative registry glyph,
- * both theme targets, the touch hit area, and xstyle forwarding.
+ * the accessible name, contextual hover tooltip, click callback, decorative
+ * registry glyph, both theme targets, touch hit area, and xstyle forwarding.
*
* SYNC: When InputClearButton.tsx changes, update tests to match new behavior.
*/
@@ -17,7 +17,7 @@
import {readFileSync} from 'node:fs';
import path from 'node:path';
import {describe, it, expect, vi, afterEach} from 'vitest';
-import {render, screen, fireEvent} from '@testing-library/react';
+import {render, screen, fireEvent, waitFor} from '@testing-library/react';
import * as stylex from '@stylexjs/stylex';
import {
InputClearButton,
@@ -95,6 +95,20 @@ describe('InputClearButton public props', () => {
});
describe('InputClearButton', () => {
+ it('uses the contextual label for the tooltip and accessible name', async () => {
+ const showPopover = vi.spyOn(HTMLElement.prototype, 'showPopover');
+ render(<InputClearButton label="Clear Search" onClick={() => {}} />);
+
+ const button = screen.getByRole('button', {name: 'Clear Search'});
+ const tooltip = screen.getByRole('tooltip', {hidden: true});
+ expect(tooltip).toHaveTextContent(/^Clear Search$/);
+ expect(button.getAttribute('aria-describedby')).toBe(tooltip.id);
+
+ fireEvent.mouseEnter(button);
+ await waitFor(() => expect(showPopover).toHaveBeenCalled());
+ showPopover.mockRestore();
+ });
+
it('renders a real button with the given accessible label', () => {
render(<InputClearButton label="Clear" onClick={() => {}} />);
const button = screen.getByRole('button', {name: 'Clear'});
diff --git a/packages/core/src/Field/InputClearButton.tsx b/packages/core/src/Field/InputClearButton.tsx
index 29dbc20571..f3e67bb326 100644
--- a/packages/core/src/Field/InputClearButton.tsx
+++ b/packages/core/src/Field/InputClearButton.tsx
@@ -4,8 +4,9 @@
/**
* @file InputClearButton.tsx
- * @input Uses React, Button, Icon
- * @output Exports the public InputClearButton and an internal popup-aware variant.
+ * @input Uses React, Button, and Icon
+ * @output Exports the public InputClearButton and an internal popup-aware variant,
+ * both with a contextual tooltip matching their required label.
* @position Shared primitive. Every input that renders a clear affordance —
* TextInput, NumberInput, TimeInput, DateInput, DateTimeInput,
* DateRangeInput, Selector, MultiSelector, Typeahead, Tokenizer, FileInput —
@@ -66,6 +67,7 @@ const styles = stylex.create({
});
export interface InputClearButtonProps {
+ /** Contextual accessible name for the button, such as "Clear Search". */
label: string;
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
xstyle?: stylex.StyleXStyles;
@@ -104,6 +106,7 @@ function renderInputClearButton({
variant="ghost"
size="sm"
label={label}
+ tooltip={label}
className={buttonTargetClassName}
icon={
<Icon