Skip to content

The open alternative to Salesforce, designed for AI.

Add visual RadioGroup orientation (#28392)

Raphaël Bosife7dddae9e2e
diff --git a/packages/twenty-docs/snippets/ui/generated/input/radio-group.mdx b/packages/twenty-docs/snippets/ui/generated/input/radio-group.mdx
index c02cdf1f51a..7ac312490bf 100644
--- a/packages/twenty-docs/snippets/ui/generated/input/radio-group.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/input/radio-group.mdx
@@ -43,6 +43,10 @@
Callback fired when the value changes.
</ParamField>
+<ParamField body="orientation" type="&quot;horizontal&quot; | &quot;vertical&quot;" default="vertical">
+ Visual layout direction, reflected in data-orientation. Does not change arrow-key navigation or set aria-orientation.
+</ParamField>
+
<ParamField body="readOnly" type="boolean" default="false">
Whether the user should be unable to select a different radio button in the group.
</ParamField>
diff --git a/packages/twenty-docs/ui/primitives/input/radio-group.mdx b/packages/twenty-docs/ui/primitives/input/radio-group.mdx
index 3f77d03a541..4b58b2a1e09 100644
--- a/packages/twenty-docs/ui/primitives/input/radio-group.mdx
+++ b/packages/twenty-docs/ui/primitives/input/radio-group.mdx
@@ -37,6 +37,34 @@ export const BillingFrequency = () => (
The group's `name` identifies the selected value in form submission. Give the group an accessible name as well as labeling each radio.
+### Horizontal layout
+
+Groups use a vertical column by default. Set `orientation="horizontal"` for a row. The prop controls visual layout through `data-orientation`; it does not set `aria-orientation` or change keyboard navigation. Both horizontal and vertical arrow keys retain the existing Base UI behavior, including right-to-left navigation through [DirectionProvider](/ui/primitives/layout/direction-provider).
+
+```tsx
+import { Radio, RadioGroup } from 'twenty-ui/primitives/input';
+
+export const HorizontalBillingFrequency = () => (
+ <RadioGroup
+ orientation="horizontal"
+ name="billingFrequency"
+ defaultValue="monthly"
+ aria-label="Billing frequency"
+ >
+ <Radio value="monthly">Monthly</Radio>
+ <Radio value="yearly">Yearly</Radio>
+ </RadioGroup>
+);
+```
+
+<StoryEmbed
+ storyId="ui-input-radiogroup--horizontal"
+ title="Horizontal RadioGroup"
+ height={80}
+/>
+
+The default gap stays the same in either direction.
+
## Anatomy
Put each `Radio` or `Radio.Root` inside the group and associate it with a label. Use `Radio.Indicator` to compose a custom indicator. `RadioGroup` and `Radio` are separate exports.
@@ -95,7 +123,7 @@ export const BillingFrequency = () => {
};
```
-`onValueChange` receives the next value and event details. The generic value type is inferred from the props. Use `disabled` on the group to disable every option, or on an individual radio to disable one choice. Arrow keys navigate and select enabled options; Tab moves out of the group. The installed Base UI version supports both horizontal and vertical arrow keys and does not expose an orientation prop. Use [DirectionProvider](/ui/primitives/layout/direction-provider) for right-to-left horizontal navigation. Visual row or column layout does not replace the upstream keyboard behavior.
+`onValueChange` receives the next value and event details. The generic value type is inferred from the props. Use `disabled` on the group to disable every option, or on an individual radio to disable one choice. Arrow keys navigate and select enabled options; Tab moves out of the group. The installed Base UI version supports both horizontal and vertical arrow keys. RadioGroup adds the visual-only `orientation` prop without changing that keyboard contract.
## Native integration and event details
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-radio-group.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-radio-group.front-component.tsx
index 33d9c82f329..1729b8c6de7 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-radio-group.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-radio-group.front-component.tsx
@@ -112,7 +112,7 @@ const RadioGroupExample = () => {
<RadioGroup
aria-label="Reading mode"
defaultValue="summary"
- style={{ flexDirection: 'row' }}
+ orientation="horizontal"
>
<Radio value="summary">Summary</Radio>
<Radio value="full">Full detail</Radio>
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts
index d1dd5ef6996..46cee3310b2 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/radioGroupTest.ts
@@ -14,6 +14,8 @@ export const radioGroupTest: TwentyUiGalleryPlayFunction = async ({
const monthly = within(group).getByRole('radio', { name: 'Monthly' });
const quarterly = within(group).getByRole('radio', { name: 'Quarterly' });
+ expect(group).toHaveAttribute('data-orientation', 'vertical');
+ expect(group).not.toHaveAttribute('aria-orientation');
expect(group.tagName).toBe('FIELDSET');
expect(group).toHaveAttribute('data-native-owner', 'digest');
expect(weekly).toBeChecked();
@@ -75,8 +77,14 @@ export const radioGroupTest: TwentyUiGalleryPlayFunction = async ({
expect(daily).toBeChecked();
});
- const summary = canvas.getByRole('radio', { name: 'Summary' });
- const fullDetail = canvas.getByRole('radio', { name: 'Full detail' });
+ const readingMode = canvas.getByRole('radiogroup', { name: 'Reading mode' });
+ const summary = within(readingMode).getByRole('radio', { name: 'Summary' });
+ const fullDetail = within(readingMode).getByRole('radio', {
+ name: 'Full detail',
+ });
+ expect(readingMode).toHaveAttribute('data-orientation', 'horizontal');
+ expect(readingMode).not.toHaveAttribute('aria-orientation');
+ expect(getComputedStyle(readingMode).flexDirection).toBe('row');
await userEvent.click(summary);
await userEvent.keyboard('{ArrowLeft}');
await waitFor(() => {
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsRadioCardContainer.tsx b/packages/twenty-front/src/modules/settings/components/SettingsRadioCardContainer.tsx
index 08d04ab2816..3e70d42e091 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsRadioCardContainer.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsRadioCardContainer.tsx
@@ -5,8 +5,6 @@ import { type IconComponent } from 'twenty-ui/icon';
import { themeCssVariables } from 'twenty-ui/theme';
const StyledRadioCardContainer = styled.div`
- display: flex;
- flex-direction: row;
flex-wrap: wrap;
gap: ${themeCssVariables.spacing[4]};
`;
@@ -29,6 +27,7 @@ export const SettingsRadioCardContainer = ({
}: SettingsRadioCardContainerProps) => {
return (
<RadioGroup
+ orientation="horizontal"
value={value}
onValueChange={onChange}
render={<StyledRadioCardContainer />}
diff --git a/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx b/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
index 2e10bc8b1cc..3d73e7e444a 100644
--- a/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
+++ b/packages/twenty-front/src/modules/settings/enterprise/components/EnterprisePlanModal.tsx
@@ -79,7 +79,6 @@ const StyledBenefitsContainer = styled.div`
`;
const StyledIntervalContainer = styled.div`
- flex-direction: row;
margin-bottom: ${themeCssVariables.spacing[8]};
width: 100%;
`;
@@ -184,6 +183,7 @@ export const EnterprisePlanModal = () => {
</StyledSubscriptionContainer>
<RadioGroup
+ orientation="horizontal"
render={<StyledIntervalContainer />}
aria-label={t`Billing interval`}
value={selectedInterval}
diff --git a/packages/twenty-front/src/pages/settings/profile/appearance/components/SettingsAppearance.tsx b/packages/twenty-front/src/pages/settings/profile/appearance/components/SettingsAppearance.tsx
index a366e29f21d..87e939a4972 100644
--- a/packages/twenty-front/src/pages/settings/profile/appearance/components/SettingsAppearance.tsx
+++ b/packages/twenty-front/src/pages/settings/profile/appearance/components/SettingsAppearance.tsx
@@ -13,7 +13,6 @@ import { SettingsAppearanceOption } from '~/pages/settings/profile/appearance/co
import { type ColorScheme } from '@/ui/theme/types/ColorScheme';
const StyledChoices = styled.div`
- flex-direction: row;
gap: ${themeCssVariables.spacing[4]};
width: 100%;
@@ -36,6 +35,7 @@ export const SettingsAppearance = () => {
<Section.Root>
<Section.Header title={t`Appearance`} />
<RadioGroup
+ orientation="horizontal"
render={<StyledChoices />}
aria-label={t`Appearance`}
value={colorScheme}
diff --git a/packages/twenty-front/src/pages/settings/profile/appearance/components/__stories__/SettingsAppearance.interactions.stories.tsx b/packages/twenty-front/src/pages/settings/profile/appearance/components/__stories__/SettingsAppearance.interactions.stories.tsx
index 9703688f41f..3a78a3d77b7 100644
--- a/packages/twenty-front/src/pages/settings/profile/appearance/components/__stories__/SettingsAppearance.interactions.stories.tsx
+++ b/packages/twenty-front/src/pages/settings/profile/appearance/components/__stories__/SettingsAppearance.interactions.stories.tsx
@@ -156,30 +156,21 @@ export const RightToLeftKeyboard: Story = {
export const HorizontalLayout: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- const lateRadioGroupStyles =
- canvasElement.ownerDocument.createElement('style');
+ const group = canvas.getByRole('radiogroup', { name: 'Appearance' });
+ const lightBounds = canvas
+ .getByRole('radio', { name: 'Light' })
+ .getBoundingClientRect();
+ const darkBounds = canvas
+ .getByRole('radio', { name: 'Dark' })
+ .getBoundingClientRect();
+ const systemBounds = canvas
+ .getByRole('radio', { name: 'System settings' })
+ .getBoundingClientRect();
- lateRadioGroupStyles.textContent =
- '@layer twenty-ui { [role="radiogroup"] { flex-direction: column; } }';
- canvasElement.ownerDocument.head.append(lateRadioGroupStyles);
-
- try {
- const lightBounds = canvas
- .getByRole('radio', { name: 'Light' })
- .getBoundingClientRect();
- const darkBounds = canvas
- .getByRole('radio', { name: 'Dark' })
- .getBoundingClientRect();
- const systemBounds = canvas
- .getByRole('radio', { name: 'System settings' })
- .getBoundingClientRect();
-
- expect(darkBounds.top).toBe(lightBounds.top);
- expect(systemBounds.top).toBe(lightBounds.top);
- expect(darkBounds.left).toBeGreaterThan(lightBounds.right);
- expect(systemBounds.left).toBeGreaterThan(darkBounds.right);
- } finally {
- lateRadioGroupStyles.remove();
- }
+ expect(group).toHaveAttribute('data-orientation', 'horizontal');
+ expect(darkBounds.top).toBe(lightBounds.top);
+ expect(systemBounds.top).toBe(lightBounds.top);
+ expect(darkBounds.left).toBeGreaterThan(lightBounds.right);
+ expect(systemBounds.left).toBeGreaterThan(darkBounds.right);
},
};
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index 56d368d89d9..f40bc1f0cf1 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -23,6 +23,7 @@ import { TOAST_PROP_DESCRIPTIONS } from './toastPropDescriptions';
import { TOAST_PROVIDER_PROP_DESCRIPTIONS } from './toastProviderPropDescriptions';
import { TOASTER_PROP_DESCRIPTIONS } from './toasterPropDescriptions';
import { RADIO_PROP_DESCRIPTIONS } from './radioPropDescriptions';
+import { RADIO_GROUP_PROP_DESCRIPTIONS } from './radioGroupPropDescriptions';
import { PHONE_COUNTRY_PICKER_PART_PROP_DESCRIPTIONS } from './phoneCountryPickerPartPropDescriptions';
import { PHONE_COUNTRY_PICKER_PROP_DESCRIPTIONS } from './phoneCountryPickerPropDescriptions';
import { SEARCH_INPUT_PROP_DESCRIPTIONS } from './searchInputPropDescriptions';
@@ -451,6 +452,8 @@ export const DOCUMENTED_COMPONENTS = [
source: 'primitives/input/RadioGroup/RadioGroup.tsx',
entryPoint: 'twenty-ui/primitives/input',
slug: 'input/radio-group',
+ propDescriptions: RADIO_GROUP_PROP_DESCRIPTIONS,
+ propDefaults: { orientation: 'vertical' },
},
{
name: 'Autocomplete',
diff --git a/packages/twenty-ui/docs/radioGroupPropDescriptions.ts b/packages/twenty-ui/docs/radioGroupPropDescriptions.ts
new file mode 100644
index 00000000000..e9349cc5eff
--- /dev/null
+++ b/packages/twenty-ui/docs/radioGroupPropDescriptions.ts
@@ -0,0 +1,6 @@
+import { type RadioGroupProps } from '../src/primitives/input/RadioGroup/types/RadioGroupProps';
+
+export const RADIO_GROUP_PROP_DESCRIPTIONS = {
+ orientation:
+ 'Visual layout direction, reflected in data-orientation. Does not change arrow-key navigation or set aria-orientation.',
+} satisfies Partial<Record<keyof RadioGroupProps, string>>;
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 42fcd8549c3..8b18ae77ccf 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -4999,6 +4999,13 @@
"defaultValue": null,
"description": "Callback fired when the value changes."
},
+ {
+ "name": "orientation",
+ "type": "\"horizontal\" | \"vertical\"",
+ "required": false,
+ "defaultValue": "vertical",
+ "description": "Visual layout direction, reflected in data-orientation. Does not change arrow-key navigation or set aria-orientation."
+ },
{
"name": "readOnly",
"type": "boolean",
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
index 7b36f6d684c..1a8503b649b 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
@@ -5,7 +5,7 @@ import { type SegmentedControlSize } from './SegmentedControlSize';
export type SegmentedControlProps<TValue extends string = string> = Omit<
RadioGroupProps<TValue>,
- 'aria-label' | 'aria-labelledby' | 'children' | 'role'
+ 'aria-label' | 'aria-labelledby' | 'children' | 'orientation' | 'role'
> & {
itemWidth?: 'content' | 'equal';
options: readonly SegmentedControlOption<TValue>[];
diff --git a/packages/twenty-ui/src/primitives/input/Radio/__tests__/Radio.test.tsx b/packages/twenty-ui/src/primitives/input/Radio/__tests__/Radio.test.tsx
index bb8085e8779..7961e417ae0 100644
--- a/packages/twenty-ui/src/primitives/input/Radio/__tests__/Radio.test.tsx
+++ b/packages/twenty-ui/src/primitives/input/Radio/__tests__/Radio.test.tsx
@@ -21,7 +21,7 @@ runComponentConformance({
runComponentConformance({
name: 'RadioGroup',
- element: <RadioGroup />,
+ element: <RadioGroup orientation="horizontal" />,
refInstanceOf: HTMLDivElement,
ownClassName: groupStyles.root,
});
diff --git a/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.module.scss b/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.module.scss
index 15113ab9af9..3d0a268bd50 100644
--- a/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.module.scss
+++ b/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.module.scss
@@ -2,4 +2,8 @@
display: flex;
flex-direction: column;
gap: var(--t-spacing-2);
+
+ &[data-orientation='horizontal'] {
+ flex-direction: row;
+ }
}
diff --git a/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.tsx b/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.tsx
index 69870bf3dab..b52de791846 100644
--- a/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.tsx
+++ b/packages/twenty-ui/src/primitives/input/RadioGroup/RadioGroup.tsx
@@ -7,10 +7,13 @@ import { type RadioGroupProps } from './types/RadioGroupProps';
export const RadioGroup = <TValue,>({
className,
+ orientation = 'vertical',
...props
}: RadioGroupProps<TValue>) => (
<RadioGroupPrimitive
+ // oxlint-disable-next-line react/jsx-props-no-spreading
{...props}
className={mergeClassNames(styles.root, className)}
+ data-orientation={orientation}
/>
);
diff --git a/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.interactions.stories.tsx b/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.interactions.stories.tsx
new file mode 100644
index 00000000000..8f886bfd898
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.interactions.stories.tsx
@@ -0,0 +1,93 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+
+import { Radio } from '@ui/primitives/input/Radio/Radio';
+import { DirectionProvider } from '@ui/primitives/layout/DirectionProvider/DirectionProvider';
+import { ComponentDecorator } from '@ui/testing';
+
+import { RadioGroup } from '../RadioGroup';
+
+const meta: Meta<typeof RadioGroup> = {
+ title: 'UI/Input/RadioGroup/Interactions',
+ component: RadioGroup,
+ args: {
+ 'aria-label': 'Billing frequency',
+ name: 'billingFrequency',
+ defaultValue: 'monthly',
+ children: (
+ <>
+ <Radio value="monthly">Monthly</Radio>
+ <Radio value="yearly">Yearly</Radio>
+ </>
+ ),
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof RadioGroup>;
+
+export const Default: Story = {
+ decorators: [ComponentDecorator],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const group = canvas.getByRole('radiogroup', { name: 'Billing frequency' });
+ const monthly = canvas.getByRole('radio', { name: 'Monthly' });
+ const yearly = canvas.getByRole('radio', { name: 'Yearly' });
+
+ await expect(group).toHaveAttribute('data-orientation', 'vertical');
+ await expect(group).not.toHaveAttribute('aria-orientation');
+ await expect(group).not.toHaveAttribute('orientation');
+ await expect(yearly.getBoundingClientRect().top).toBeGreaterThan(
+ monthly.getBoundingClientRect().bottom,
+ );
+ },
+};
+
+export const Horizontal: Story = {
+ ...Default,
+ args: { orientation: 'horizontal', onValueChange: fn() },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const group = canvas.getByRole('radiogroup', { name: 'Billing frequency' });
+ const monthly = canvas.getByRole('radio', { name: 'Monthly' });
+ const yearly = canvas.getByRole('radio', { name: 'Yearly' });
+ const expectedDirection = args.dir ?? 'ltr';
+ const isRightToLeft = expectedDirection === 'rtl';
+ const monthlyBounds = monthly.getBoundingClientRect();
+ const yearlyBounds = yearly.getBoundingClientRect();
+ const leftRadioBounds = isRightToLeft ? yearlyBounds : monthlyBounds;
+ const rightRadioBounds = isRightToLeft ? monthlyBounds : yearlyBounds;
+
+ await expect(getComputedStyle(group).direction).toBe(expectedDirection);
+ await expect(group).toHaveAttribute('data-orientation', 'horizontal');
+ await expect(group).not.toHaveAttribute('aria-orientation');
+ await expect(group).not.toHaveAttribute('orientation');
+ await expect(yearlyBounds.top).toBe(monthlyBounds.top);
+ await expect(rightRadioBounds.left).toBeGreaterThan(leftRadioBounds.right);
+ await userEvent.click(monthly);
+ await userEvent.keyboard(isRightToLeft ? '{ArrowLeft}' : '{ArrowRight}');
+ await waitFor(() => {
+ expect(yearly).toHaveFocus();
+ expect(yearly).toBeChecked();
+ });
+ await userEvent.keyboard('{ArrowUp}');
+ await waitFor(() => {
+ expect(monthly).toHaveFocus();
+ expect(monthly).toBeChecked();
+ });
+ await expect(args.onValueChange).toHaveBeenCalledTimes(2);
+ },
+};
+
+export const HorizontalRightToLeft: Story = {
+ ...Horizontal,
+ args: { ...Horizontal.args, dir: 'rtl' },
+ decorators: [
+ ComponentDecorator,
+ (Story) => (
+ <DirectionProvider direction="rtl">
+ <Story />
+ </DirectionProvider>
+ ),
+ ],
+};
diff --git a/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.stories.tsx b/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.stories.tsx
index a19e0300c2b..2e6a6eaf8ea 100644
--- a/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/RadioGroup/__stories__/RadioGroup.stories.tsx
@@ -27,3 +27,8 @@ type Story = StoryObj<typeof RadioGroup>;
export const Display: Story = {
decorators: [ComponentDecorator],
};
+
+export const Horizontal: Story = {
+ ...Display,
+ args: { orientation: 'horizontal' },
+};
diff --git a/packages/twenty-ui/src/primitives/input/RadioGroup/types/RadioGroupProps.ts b/packages/twenty-ui/src/primitives/input/RadioGroup/types/RadioGroupProps.ts
index 0edaf9e96b5..760bd085348 100644
--- a/packages/twenty-ui/src/primitives/input/RadioGroup/types/RadioGroupProps.ts
+++ b/packages/twenty-ui/src/primitives/input/RadioGroup/types/RadioGroupProps.ts
@@ -1,4 +1,6 @@
import { type RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';
export type RadioGroupProps<TValue = string> =
- RadioGroupPrimitive.Props<TValue>;
+ RadioGroupPrimitive.Props<TValue> & {
+ orientation?: 'horizontal' | 'vertical';
+ };