Skip to content

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

TypeScript

Fix Button edges inside InputGroup (#7233)

rubyycheung96154f56d7f7
diff --git a/.changeset/input-group-button-edges.md b/.changeset/input-group-button-edges.md
new file mode 100644
index 0000000000..208b65e5b7
--- /dev/null
+++ b/.changeset/input-group-button-edges.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Buttons used as InputGroup addons now share the group's outer shape, with square inner corners where they meet the adjacent input.
+
+Standalone buttons and buttons rendered inside an input keep their existing shape and behavior.
+
+@rubyycheung
diff --git a/apps/storybook/stories/InputGroup.stories.tsx b/apps/storybook/stories/InputGroup.stories.tsx
index f85e8b71e0..2ee724a15b 100644
--- a/apps/storybook/stories/InputGroup.stories.tsx
+++ b/apps/storybook/stories/InputGroup.stories.tsx
@@ -2,6 +2,7 @@
import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
+import {Button} from '@astryxdesign/core/Button';
import {InputGroup} from '@astryxdesign/core/InputGroup';
import {InputGroupText} from '@astryxdesign/core/InputGroup';
import {TextInput} from '@astryxdesign/core/TextInput';
@@ -53,6 +54,7 @@ export default meta;
type Story = StoryObj<typeof InputGroup>;
const TEAM_OPTIONS = ['Design Systems', 'Infrastructure', 'Product'];
+const VISIBILITY_OPTIONS = ['Only me', 'Members', 'Anyone'];
export const WithPrefix: Story = {
render: args => {
@@ -256,6 +258,76 @@ export const WithSelector: Story = {
},
};
+export const WithActionButton: Story = {
+ render: args => {
+ const [value, setValue] = useState<string | undefined>('Members');
+ return (
+ <InputGroup {...args}>
+ <Selector
+ label="Audience"
+ isLabelHidden
+ options={VISIBILITY_OPTIONS}
+ value={value}
+ onChange={setValue}
+ />
+ <Button label="Save" />
+ </InputGroup>
+ );
+ },
+ args: {
+ label: 'Visibility',
+ },
+};
+
+export const ActionButtonCombinations: Story = {
+ render: () => {
+ const [prefixValue, setPrefixValue] = useState('');
+ const [suffixValue, setSuffixValue] = useState('');
+ const [visibility, setVisibility] = useState<string | undefined>('Members');
+
+ return (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 16,
+ maxWidth: 520,
+ }}>
+ <InputGroup label="Prefix action" size="sm">
+ <Button label="Paste" />
+ <TextInput
+ label="Code"
+ isLabelHidden
+ value={prefixValue}
+ onChange={setPrefixValue}
+ placeholder="Enter code"
+ />
+ </InputGroup>
+ <InputGroup label="Text action" size="md">
+ <TextInput
+ label="Query"
+ isLabelHidden
+ value={suffixValue}
+ onChange={setSuffixValue}
+ placeholder="Search"
+ />
+ <Button label="Search" variant="primary" />
+ </InputGroup>
+ <InputGroup label="Selector action" size="lg">
+ <Selector
+ label="Audience"
+ isLabelHidden
+ options={VISIBILITY_OPTIONS}
+ value={visibility}
+ onChange={setVisibility}
+ />
+ <Button label="Save" tooltip="Save visibility" />
+ </InputGroup>
+ </div>
+ );
+ },
+};
+
export const WithMultiSelector: Story = {
render: args => {
const [value, setValue] = useState<string[]>([]);
diff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsx
index da3a8f500d..1890b83bbc 100644
--- a/packages/core/src/Button/Button.test.tsx
+++ b/packages/core/src/Button/Button.test.tsx
@@ -9,6 +9,7 @@
* SYNC: When Button.tsx changes, update tests to match new behavior
*/
+import {readFileSync} from 'node:fs';
import {describe, it, expect, vi} from 'vitest';
import {render, screen, fireEvent, act} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
@@ -21,6 +22,8 @@ import {
} from '../__tests__/pressState';
import {Badge} from '../Badge/Badge';
import {ButtonGroup} from '../ButtonGroup';
+import {InputGroup} from '../InputGroup';
+import {TextInput} from '../TextInput';
import {IconButton} from '../IconButton';
import {InternationalizationProvider} from '../i18n';
@@ -39,6 +42,40 @@ describe('Button', () => {
expect(screen.getByRole('button')).toHaveTextContent('Click me');
});
+ it('uses InputGroup end-cap geometry and keeps its keyboard ring above adjacent members', () => {
+ const {rerender} = render(
+ <InputGroup label="Visibility">
+ <TextInput
+ label="Audience"
+ isLabelHidden
+ value="Members"
+ onChange={() => {}}
+ />
+ <Button label="Save" />
+ </InputGroup>,
+ );
+
+ const addon = screen.getByRole('button', {name: 'Save'});
+ expect(addon.className).toContain('groupStyles.buttonAddon');
+
+ // jsdom cannot resolve this compound StyleX focus selector. Keep the
+ // direct-child keyboard stacking rule explicit at its definition instead.
+ const groupStylesSource = readFileSync(
+ 'packages/core/src/InputGroup/groupStyles.ts',
+ 'utf8',
+ );
+ expect(groupStylesSource).toContain(
+ "':where(.astryx-input-group > *):focus-visible'",
+ );
+ expect(groupStylesSource).toMatch(
+ /zIndex:\s*\{\s*default: null,\s*\[DIRECT_INPUT_GROUP_ADDON_FOCUS_VISIBLE\]: 2,/,
+ );
+
+ rerender(<Button label="Save" />);
+ const standalone = screen.getByRole('button', {name: 'Save'});
+ expect(standalone.className).not.toContain('groupStyles.buttonAddon');
+ });
+
it('renders children instead of label when provided', () => {
render(<Button label="Accessible name">Custom content</Button>);
const button = screen.getByRole('button');
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index fb52d7c152..67fb79b93d 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -4,7 +4,7 @@
/**
* @file Button.tsx
- * @input Uses React, ButtonHTMLAttributes, ReactNode, i18n (useTranslator)
+ * @input Uses React, ButtonHTMLAttributes, ReactNode, i18n (useTranslator), group contexts
* @output Exports Button component, ButtonProps, ButtonVariant types
* @position Core implementation; consumed by index.ts, tested by Button.test.tsx
*
@@ -44,6 +44,8 @@ import {iconBoxSizeStyles, type IconSize} from '../Icon/IconSize.stylex';
import {EDGE_COMP_ATTR} from '../Layout/edgeCompensation.stylex';
import {useSize} from '../SizeContext/SizeContext';
import {useButtonGroup} from '../ButtonGroup/ButtonGroupContext';
+import {useInputGroup} from '../InputGroup/InputGroupContext';
+import {groupStyles as inputGroupStyles} from '../InputGroup/groupStyles';
import {mergeProps} from '../utils';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {useLinkComponent} from '../Link/useLinkComponent';
@@ -576,6 +578,7 @@ export function Button({
const t = useTranslator();
const size = useSize(sizeProp, 'md');
const buttonGroup = useButtonGroup();
+ const inputGroup = useInputGroup();
const [isPending, startTransition] = useTransition();
// clickAction is normally fire-once (submit/save/pay), so a same-tick
@@ -674,6 +677,7 @@ export function Button({
(buttonGroup.orientation === 'horizontal'
? groupStyles.horizontal
: groupStyles.vertical),
+ inputGroup != null && buttonGroup == null && inputGroupStyles.buttonAddon,
buttonGroup &&
(variant === 'primary' || variant === 'destructive') &&
(buttonGroup.orientation === 'horizontal'
diff --git a/packages/core/src/InputGroup/InputGroup.doc.mjs b/packages/core/src/InputGroup/InputGroup.doc.mjs
index 124fd4326c..cadadf2d8b 100644
--- a/packages/core/src/InputGroup/InputGroup.doc.mjs
+++ b/packages/core/src/InputGroup/InputGroup.doc.mjs
@@ -30,7 +30,7 @@ export const docs = {
name: 'children',
type: 'ReactNode',
description:
- 'InputGroupText and compatible input children: TextInput, NumberInput, TimeInput, DateInput, Typeahead, Selector, or MultiSelector.',
+ 'InputGroupText, Button addons, and compatible input children: TextInput, NumberInput, TimeInput, DateInput, Typeahead, Selector, or MultiSelector.',
required: true,
},
{
@@ -110,6 +110,11 @@ export const docs = {
description:
'Use InputGroupText for static prefixes/suffixes like "$", "kg", or "https://".',
},
+ {
+ guidance: true,
+ description:
+ 'Use Button for an action attached to the input; InputGroup connects its corners automatically.',
+ },
{
guidance: true,
description:
@@ -181,6 +186,11 @@ export const docsDense = {
description:
'Use InputGroupText for static prefixes/suffixes like "$", "kg", or "https://".',
},
+ {
+ guidance: true,
+ description:
+ 'Use Button for an action attached to the input; InputGroup connects its corners automatically.',
+ },
{
guidance: true,
description:
diff --git a/packages/core/src/InputGroup/InputGroup.tsx b/packages/core/src/InputGroup/InputGroup.tsx
index 740c1aa5f0..6a3b877c74 100644
--- a/packages/core/src/InputGroup/InputGroup.tsx
+++ b/packages/core/src/InputGroup/InputGroup.tsx
@@ -8,10 +8,8 @@
* @output Exports InputGroup component with group label/description ARIA wiring
* @position Groups input with prefix/suffix addons; consumed by index.ts
*
- * Children (TextInput, NumberInput, TimeInput, DateInput, Typeahead,
- * Selector, MultiSelector) consume the InputGroup context
- * to remove their own border/radius so the group container provides
- * the unified border treatment.
+ * Compatible input children consume InputGroup context to remove competing
+ * border/radius geometry. Button addons consume it to join the same outer shape.
*
* SYNC: When modified, update these files to stay in sync:
* - /packages/core/src/InputGroup/InputGroup.doc.mjs
diff --git a/packages/core/src/InputGroup/groupStyles.ts b/packages/core/src/InputGroup/groupStyles.ts
index c1f41b639e..2181be4a73 100644
--- a/packages/core/src/InputGroup/groupStyles.ts
+++ b/packages/core/src/InputGroup/groupStyles.ts
@@ -3,8 +3,8 @@
/**
* @file groupStyles.ts
* @input Uses StyleX, theme tokens, and layer-aware group end-cap selectors
- * @output Exports shared group-aware styles for input components
- * @position Shared styles consumed by InputGroup-compatible controls
+ * @output Exports shared group-aware styles for InputGroup children
+ * @position Shared styles consumed by InputGroup-compatible controls and addons
*/
import * as stylex from '@stylexjs/stylex';
@@ -15,7 +15,45 @@ import {radiusVars, borderVars} from '../theme/tokens.stylex';
// are not visual group members; skip them when finding the trailing edge.
const IS_LAST_ITEM = ':not(:has(~ *:not([popover]):not(template):not(dialog)))';
+// Button consumes InputGroup context anywhere below the group, including buttons
+// inside an input's own implementation. Keep the visual adaptation on direct
+// children so internal clear, calendar, and disclosure actions stay unchanged.
+const DIRECT_INPUT_GROUP_ADDON = ':where(.astryx-input-group > *)';
+const DIRECT_INPUT_GROUP_ADDON_FOCUS_VISIBLE =
+ ':where(.astryx-input-group > *):focus-visible';
+const DIRECT_INPUT_GROUP_ADDON_NOT_FIRST =
+ ':where(.astryx-input-group > *):not(:first-child)';
+const DIRECT_INPUT_GROUP_ADDON_WITH_MEMBER_AFTER =
+ ':where(.astryx-input-group > *):has(~ *:not([popover]):not(template):not(dialog))';
+
export const groupStyles = stylex.create({
+ buttonAddon: {
+ borderStartStartRadius: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON_NOT_FIRST]: 0,
+ },
+ borderEndStartRadius: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON_NOT_FIRST]: 0,
+ },
+ borderStartEndRadius: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON_WITH_MEMBER_AFTER]: 0,
+ },
+ borderEndEndRadius: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON_WITH_MEMBER_AFTER]: 0,
+ },
+ height: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON]: '100%',
+ },
+ // Keep the keyboard ring above the adjacent group member at the shared edge.
+ zIndex: {
+ default: null,
+ [DIRECT_INPUT_GROUP_ADDON_FOCUS_VISIBLE]: 2,
+ },
+ },
inGroup: {
flex: 1,
minWidth: 0,