Skip to content

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

TypeScript

fix(ComplexSelector): tooltip status placement keeps its message (#9026)

Cindy Zhang7544940f497a
diff --git a/.changeset/complexselector-tooltip-status.md b/.changeset/complexselector-tooltip-status.md
new file mode 100644
index 0000000000..3535547356
--- /dev/null
+++ b/.changeset/complexselector-tooltip-status.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] ComplexSelector: with `statusVariant="tooltip"` the status message is no longer lost. The trigger row now shows the status icon as a focusable info-tip button that reveals the message on hover, keyboard focus, or tap, and the trigger is described by that message instead of pointing at an element that did not exist. Pressing the info-tip does not open the popup.
+
+@cixzhang
diff --git a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx b/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
index 62b4cc6cf1..ec83a825f9 100644
--- a/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
+++ b/packages/core/src/ComplexSelector/ComplexSelector.test.tsx
@@ -14,6 +14,8 @@ import {beforeEach, describe, expect, it, vi} from 'vitest';
import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {Button} from '../Button/Button';
+import * as stylex from '@stylexjs/stylex';
+import {focusVars} from '../theme/tokens.stylex';
import {ComplexSelector, type ComplexSelectorHandle} from './ComplexSelector';
const originalMatches = HTMLElement.prototype.matches;
@@ -1056,5 +1058,114 @@ describe('ComplexSelector onOpenChange', () => {
container.querySelector('.astryx-field-status'),
).not.toBeInTheDocument();
});
+
+ // family:input-fields FR8: tooltip placement keeps the message reachable.
+ it('puts the tooltip-placement message in a focusable info-tip that describes the trigger', async () => {
+ const user = userEvent.setup();
+ render(
+ <ComplexSelector
+ label="Filter"
+ value={[]}
+ status={{type: 'error', message: 'Required'}}
+ statusVariant="tooltip">
+ {() => <button type="button">Apply</button>}
+ </ComplexSelector>,
+ );
+ const trigger = screen.getByRole('combobox', {name: 'Filter'});
+ const tip = screen.getByRole('button', {name: 'Error details'});
+ // Every id the trigger points at exists, and the status message is
+ // among them.
+ const ids = trigger.getAttribute('aria-describedby')?.split(' ') ?? [];
+ expect(ids.length).toBeGreaterThan(0);
+ for (const id of ids) {
+ expect(document.getElementById(id)).not.toBeNull();
+ }
+ expect(trigger).toHaveAccessibleDescription('Required');
+
+ // Focusing the info-tip reveals the message without opening the popup.
+ await user.tab();
+ await user.tab();
+ expect(tip).toHaveFocus();
+ expect(tip).toHaveAccessibleDescription('Required');
+ await user.click(tip);
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ });
+
+ // architecture:interaction-modality INV3: the info-tip rings itself, so
+ // the control box rings only for the trigger, not for any focused child.
+ it('rings the control box for the trigger only, not for the info-tip', () => {
+ render(
+ <ComplexSelector
+ label="Filter"
+ value={[]}
+ status={{type: 'error', message: 'Required'}}
+ statusVariant="tooltip">
+ {() => <button type="button">Apply</button>}
+ </ComplexSelector>,
+ );
+ const box = screen.getByRole('combobox', {name: 'Filter'}).parentElement!;
+ // The same declarations as the shared any-descendant ring, with null
+ // defaults so only its `:has(:focus-visible)` atoms are compared (the
+ // default atoms are shared with the combobox-only ring).
+ /* eslint-disable @astryx/focus-outline-shared -- a test oracle that
+ mirrors the shared ring's conditional atoms; it paints nothing. */
+ const anyDescendantRing = stylex.create({
+ ring: {
+ outlineWidth: {
+ default: null,
+ ':has(:focus-visible)': focusVars['--focus-outline-width'],
+ },
+ outlineStyle: {
+ default: null,
+ ':has(:focus-visible)': focusVars['--focus-outline-style'],
+ },
+ },
+ });
+ /* eslint-enable @astryx/focus-outline-shared */
+ const anyFocusAtoms = stylex
+ .props(anyDescendantRing.ring)
+ .className!.split(' ')
+ .filter(name => name.includes('x') && !name.includes('__'));
+ expect(anyFocusAtoms.length).toBeGreaterThan(0);
+ for (const name of anyFocusAtoms) {
+ expect(box).not.toHaveClass(name);
+ }
+ });
+
+ it('opens no popup when the info-tip message bubble is pressed', async () => {
+ const user = userEvent.setup();
+ render(
+ <ComplexSelector
+ label="Filter"
+ value={[]}
+ status={{type: 'error', message: 'Required'}}
+ statusVariant="tooltip">
+ {() => <button type="button">Apply</button>}
+ </ComplexSelector>,
+ );
+ const trigger = screen.getByRole('combobox', {name: 'Filter'});
+ const tip = screen.getByRole('button', {name: 'Error details'});
+ act(() => {
+ tip.focus();
+ });
+ const bubble = await screen.findByRole('tooltip', {hidden: true});
+ await user.click(bubble);
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ });
+
+ it('keeps the attached message box and adds no info-tip', () => {
+ render(
+ <ComplexSelector
+ label="Filter"
+ value={[]}
+ status={{type: 'error', message: 'Required'}}>
+ {() => <button type="button">Apply</button>}
+ </ComplexSelector>,
+ );
+ expect(screen.queryByRole('button', {name: 'Error details'})).toBeNull();
+ expect(
+ screen.getByRole('combobox', {name: 'Filter'}),
+ ).toHaveAccessibleDescription('Required');
+ });
});
});
diff --git a/packages/core/src/ComplexSelector/ComplexSelector.tsx b/packages/core/src/ComplexSelector/ComplexSelector.tsx
index 47a7b92df0..89ddb3ec0f 100644
--- a/packages/core/src/ComplexSelector/ComplexSelector.tsx
+++ b/packages/core/src/ComplexSelector/ComplexSelector.tsx
@@ -45,6 +45,7 @@ import {layerAnimations} from '../Layer/layerAnimations.stylex';
import type {LayerAlignment, LayerPlacement} from '../Layer/useLayer';
import {usePopover} from '../Popover/usePopover';
import {useResolvedRequired} from '../hooks/useResolvedRequired';
+import {useInputStatusIcon} from '../hooks/useInputStatusIcon';
import {
colorVars,
durationVars,
@@ -56,15 +57,22 @@ import {
typographyVars,
typeScaleVars,
} from '../theme/tokens.stylex';
+import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {isRenderable, mergeProps} from '../utils';
import {composeEventHandlers} from '../utils/composeEventHandlers';
-import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {usePressFeedback} from '../hooks/usePressFeedback';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
const styles = stylex.create({
+ // The tooltip-placement status info-tip sits beside the chevron and keeps
+ // its size when the trigger text is long.
+ statusTip: {
+ display: 'inline-flex',
+ alignItems: 'center',
+ flexShrink: 0,
+ },
triggerContainer: {
position: 'relative',
display: 'flex',
@@ -458,6 +466,11 @@ export interface ComplexSelectorProps<Value> extends Omit<
'data-testid'?: string;
}
+/** Keeps a click from reaching the control box's open-the-popup handler. */
+function stopPropagation(event: React.MouseEvent) {
+ event.stopPropagation();
+}
+
/**
* A selector shell for rich, custom selection surfaces.
*
@@ -557,10 +570,24 @@ export function ComplexSelector<Value>({
const contentId = useId();
const descriptionId = useId();
const statusMessageId = useId();
+ // With `tooltip` placement Field renders no message box, so the status
+ // lives in an info-tip button on the trigger row (family:input-fields FR8).
+ // Only that placement renders an on-field status affordance here.
+ const isTooltipStatus = effectiveStatusVariant === 'tooltip';
+ const {statusIcon: statusTip, describedBy: statusTipDescribedBy} =
+ useInputStatusIcon({
+ status: isTooltipStatus ? status : undefined,
+ statusVariant: effectiveStatusVariant,
+ size: 'sm',
+ });
const ariaDescribedBy =
[
description ? descriptionId : null,
- status?.message ? statusMessageId : null,
+ isTooltipStatus
+ ? statusTipDescribedBy
+ : status?.message
+ ? statusMessageId
+ : null,
]
.filter((id): id is string => id != null)
.join(' ') || undefined;
@@ -809,8 +836,10 @@ export function ComplexSelector<Value>({
// The ring belongs to the wrapper (the focusable `<button>` sits
// inside it), but it must still be a KEYBOARD ring: `:focus-within`
// matched a mouse click on the trigger and drew the outline for
- // pointer users too. `focusWithin` here is `:has(:focus-visible)`.
- focusOutlineStyles.focusWithin,
+ // pointer users too. It keys off the trigger alone, so the status
+ // info-tip beside it rings itself and the box does not ring too
+ // (architecture:interaction-modality INV3).
+ focusOutlineStyles.focusWithinCombobox,
variant === 'secondary' && styles.triggerSecondary,
variant === 'ghost' && styles.triggerGhost,
variant !== 'input' && interactionOverlayStyles.backgroundImage,
@@ -859,6 +888,14 @@ export function ComplexSelector<Value>({
{...stylex.props(styles.trigger)}>
<span {...stylex.props(styles.triggerText)}>{triggerContent}</span>
</button>
+ {isRenderable(statusTip) && (
+ // The info-tip is its own control: a press on it, or on its message
+ // bubble (portaled, so outside this span in the DOM but inside it in
+ // React), shows the message without opening the popup.
+ <span onClick={stopPropagation} {...stylex.props(styles.statusTip)}>
+ {statusTip}
+ </span>
+ )}
{isBusy && <Spinner size="sm" aria-hidden="true" />}
<Icon
icon="chevronDown"
diff --git a/packages/core/src/utils/focusOutline.stylex.ts b/packages/core/src/utils/focusOutline.stylex.ts
index 62fb233e36..56c2341eee 100644
--- a/packages/core/src/utils/focusOutline.stylex.ts
+++ b/packages/core/src/utils/focusOutline.stylex.ts
@@ -160,6 +160,34 @@ export const focusOutlineStyles = stylex.create({
':has(> :first-child:focus-visible)': FOCUS_OUTLINE_OFFSET,
},
},
+ /**
+ * Like {@link focusOutlineStyles.focusWithin}, but only for a direct child
+ * with `role="combobox"` — for a control box that paints the ring for its
+ * combobox trigger while sibling controls inside it (a status info-tip, a
+ * clear button) ring themselves. One focus move, one ring
+ * (architecture:interaction-modality INV3).
+ */
+ focusWithinCombobox: {
+ outlineWidth: {
+ default: '0',
+ ':has(> [role="combobox"]:focus-visible)':
+ focusOutlineLonghands.outlineWidth,
+ },
+ outlineStyle: {
+ default: 'none',
+ ':has(> [role="combobox"]:focus-visible)':
+ focusOutlineLonghands.outlineStyle,
+ },
+ outlineColor: {
+ default: null,
+ ':has(> [role="combobox"]:focus-visible)':
+ focusOutlineLonghands.outlineColor,
+ },
+ outlineOffset: {
+ default: '0',
+ ':has(> [role="combobox"]:focus-visible)': FOCUS_OUTLINE_OFFSET,
+ },
+ },
/**
* Draws no ring, and keeps the UA's own off — for an element whose ring an
* ancestor paints.