Skip to content

The open alternative to Salesforce, designed for AI.

Make the True/False control full width in record forms (#28787)

Charles Bochetf19ebfee4c5d
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
index a40a6305f3e..e39cd910cc8 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
@@ -39,6 +39,10 @@
Useful when the radio group is rendered outside the form.
</ParamField>
+<ParamField body="fullWidth" type="boolean" default="false">
+ Stretch the control to the width of its container.
+</ParamField>
+
<ParamField body="inputRef" type="Ref&lt;HTMLInputElement&gt;">
A ref to access the hidden input element.
</ParamField>
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx
index 5cf162c60ac..10014f4551f 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx
@@ -40,6 +40,7 @@ export const RecordFormBooleanFieldInput = ({
variant="transparent"
>
<SegmentedControl
+ fullWidth
variant="rectangle"
aria-label={isNonEmptyString(label) ? label : t`True or false`}
options={[
diff --git a/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts b/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
index 4551e2ceec7..11ce8deadff 100644
--- a/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
+++ b/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
@@ -4,6 +4,7 @@ import { type KeysOfUnion } from 'type-fest';
import { type SegmentedControl } from '../src/components/input/SegmentedControl/SegmentedControl';
export const SEGMENTED_CONTROL_PROP_DESCRIPTIONS = {
+ fullWidth: 'Stretch the control to the width of its container.',
itemWidth: 'Use equal-width options or size each option to its content.',
options:
'Options with a unique string `value`, a `label` or `startIcon`, and optional `disabled`. Icon-only options require an `aria-label`.',
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 3d0156d18d2..bee974fc357 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -2108,6 +2108,13 @@
"defaultValue": null,
"description": "Identifies the form that owns the radio inputs.\nUseful when the radio group is rendered outside the form."
},
+ {
+ "name": "fullWidth",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Stretch the control to the width of its container."
+ },
{
"name": "inputRef",
"type": "Ref<HTMLInputElement>",
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
index 452be7c2a12..44adcf4b169 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
@@ -43,6 +43,10 @@
}
}
+.fullWidth {
+ inline-size: 100%;
+}
+
.sm {
--tw-segmented-control-block-size: var(--t-spacing-6);
--tw-segmented-control-item-size: var(--t-spacing-5);
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss.d.ts b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss.d.ts
index 33b840db5f0..cef3013c4a9 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss.d.ts
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss.d.ts
@@ -1,5 +1,6 @@
declare const classNames: {
readonly container: 'container';
+ readonly fullWidth: 'fullWidth';
readonly icon: 'icon';
readonly iconOnly: 'iconOnly';
readonly item: 'item';
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
index 7bbd83bcf9c..6e8eb8037dc 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
@@ -13,6 +13,7 @@ import { type SegmentedControlProps } from './types/SegmentedControlProps';
export const SegmentedControl = <TValue extends string>({
className,
+ fullWidth = false,
itemWidth = 'equal',
options,
size = 'md',
@@ -25,7 +26,7 @@ export const SegmentedControl = <TValue extends string>({
<RadioGroupPrimitive
{...props}
className={mergeClassNames(
- clsx(styles.container, styles[size]),
+ clsx(styles.container, styles[size], fullWidth && styles.fullWidth),
className,
)}
data-item-width={itemWidth}
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx b/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
index 3d548fdcb1c..516ed51e816 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
@@ -106,6 +106,24 @@ export const Rectangle: Story = {
play: Default.play,
};
+export const FullWidth: Story = {
+ args: { fullWidth: true, variant: 'rectangle' },
+ decorators: [
+ (Story) => (
+ <div style={{ width: 360 }}>
+ <Story />
+ </div>
+ ),
+ ],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await expect(
+ canvas.getByRole('radiogroup').getBoundingClientRect().width,
+ ).toBe(360);
+ },
+};
+
export const ContentWidth: Story = {
args: { itemWidth: 'content' },
play: async ({ canvasElement }) => {
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 81d10b9711d..08902152218 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
@@ -8,6 +8,7 @@ export type SegmentedControlProps<TValue extends string = string> = Omit<
RadioGroupProps<TValue>,
'aria-label' | 'aria-labelledby' | 'children' | 'orientation' | 'role'
> & {
+ fullWidth?: boolean;
itemWidth?: 'content' | 'equal';
options: readonly SegmentedControlOption<TValue>[];
size?: SegmentedControlSize;