Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
associate FormField hints with controls via aria-describedby (#7525)
[._.]/ Adam Eivyef18712b6086
diff --git a/client/src/components/ui/FormField.jsx b/client/src/components/ui/FormField.jsxindex 4ccf6c70e3..0fcc82e6a8 100644--- a/client/src/components/ui/FormField.jsx+++ b/client/src/components/ui/FormField.jsx@@ -29,21 +29,39 @@ export function FormField({compact = false,}) {const generatedId = useId();+ // Only generate hintId if hint is present and non-empty to avoid orphan IDREFs.+ const hintId = hint != null && hint !== '' && hint !== false ? `${generatedId}-hint` : null;+// The label must point at whatever id the first control actually has: reuse// the child's own id when present, otherwise inject the generated one.let controlId = generatedId;const augmented = Children.map(children, (child, i) => {if (i !== 0 || !isValidElement(child)) return child;++ // Build props for the child, starting with ID assignment.+ const childProps = {};if (child.props.id) {controlId = child.props.id;- return child;+ } else {+ controlId = generatedId;+ childProps.id = controlId;+ }++ // Handle aria-describedby: preserve existing tokens and append hint id.+ if (hintId) {+ const existingDescribedBy = child.props['aria-describedby'];+ const tokens = existingDescribedBy ? [existingDescribedBy.trim(), hintId] : [hintId];+ childProps['aria-describedby'] = tokens.join(' ');}- return cloneElement(child, { id: controlId });++ // Only clone if we have props to assign; otherwise return the original child.+ return Object.keys(childProps).length > 0 ? cloneElement(child, childProps) : child;});+return (<div className={className}>{label != null && <label htmlFor={controlId} className={compact ? 'block text-xs uppercase tracking-wider text-gray-500 mb-1' : labelClassName}>{label}</label>}- {hint != null && <p className={compact ? 'block text-[11px] text-gray-500 mt-1' : 'text-xs text-gray-500 mb-1'}>{hint}</p>}+ {hint != null && hint !== '' && hint !== false && <p id={hintId} className={compact ? 'block text-[11px] text-gray-500 mt-1' : 'text-xs text-gray-500 mb-1'}>{hint}</p>}{augmented}</div>);diff --git a/client/src/components/ui/FormField.test.jsx b/client/src/components/ui/FormField.test.jsxindex 99259cc138..233aa24fca 100644--- a/client/src/components/ui/FormField.test.jsx+++ b/client/src/components/ui/FormField.test.jsx@@ -83,4 +83,114 @@ describe('FormField', () => {);expect(screen.getByLabelText('●Light')).toBeTruthy();});++ it('associates a hint with the control via aria-describedby', () => {+ const { container } = render(+ <FormField label="Speech Rate" hint="0.5 = slow, 1.0 = normal, 2.0 = fast">+ <input type="number" min="0.5" max="2.0" step="0.1" defaultValue="1.0" />+ </FormField>+ );+ const input = screen.getByLabelText('Speech Rate');+ const hint = screen.getByText('0.5 = slow, 1.0 = normal, 2.0 = fast');++ // Hint must have an id.+ expect(hint.id).toBeTruthy();++ // Control must reference the hint via aria-describedby.+ expect(input).toHaveAttribute('aria-describedby', hint.id);+ });++ it('preserves existing aria-describedby tokens and appends the hint', () => {+ const { container } = render(+ <FormField label="Provider" hint="This service may be unavailable during maintenance">+ <select aria-describedby="provider-note" defaultValue="auto">+ <option value="auto">Auto</option>+ <option value="manual">Manual</option>+ </select>+ </FormField>+ );+ const select = screen.getByLabelText('Provider');+ const hint = screen.getByText('This service may be unavailable during maintenance');++ // Control must have both the original aria-describedby and the hint id.+ expect(select).toHaveAttribute('aria-describedby');+ const describedBy = select.getAttribute('aria-describedby');+ expect(describedBy).toContain('provider-note');+ expect(describedBy).toContain(hint.id);+ });++ it('associates hint with an explicit control id', () => {+ render(+ <FormField label="STT Engine" hint="Browser-based engines have limited language support">+ <select id="stt-selector" defaultValue="browser">+ <option value="browser">Browser</option>+ <option value="api">API</option>+ </select>+ </FormField>+ );+ const select = screen.getByLabelText('STT Engine');+ const hint = screen.getByText('Browser-based engines have limited language support');++ // Label should point at the explicit id.+ expect(select.id).toBe('stt-selector');++ // Control must reference the hint via aria-describedby.+ expect(select).toHaveAttribute('aria-describedby', hint.id);+ });++ it('does not create a dangling hint id when hint is absent', () => {+ const { container } = render(+ <FormField label="Name">+ <input defaultValue="" />+ </FormField>+ );+ const input = screen.getByLabelText('Name');++ // Without a hint, aria-describedby should not be set.+ expect(input).not.toHaveAttribute('aria-describedby');+ });++ it('renders hint content without an id when hint prop is falsy', () => {+ const { container } = render(+ <FormField label="Notes">+ <textarea defaultValue="" />+ </FormField>+ );+ const textarea = screen.getByLabelText('Notes');++ // No aria-describedby when hint is omitted.+ expect(textarea).not.toHaveAttribute('aria-describedby');+ });++ it('treats empty string hint as no hint to avoid orphan IDREFs', () => {+ const { container } = render(+ <FormField label="Field" hint="">+ <input defaultValue="" />+ </FormField>+ );+ const input = screen.getByLabelText('Field');+ const paragraphs = container.querySelectorAll('p');++ // No paragraph should be rendered for an empty hint.+ expect(paragraphs).toHaveLength(0);++ // No aria-describedby should be set.+ expect(input).not.toHaveAttribute('aria-describedby');+ });++ it('treats false hint as no hint', () => {+ const { container } = render(+ <FormField label="Field" hint={false}>+ <input defaultValue="" />+ </FormField>+ );+ const input = screen.getByLabelText('Field');+ const paragraphs = container.querySelectorAll('p');++ // No paragraph should be rendered for a false hint.+ expect(paragraphs).toHaveLength(0);++ // No aria-describedby should be set.+ expect(input).not.toHaveAttribute('aria-describedby');+ });});