Skip to content

The open alternative to Salesforce, designed for AI.

Complete Field and Slider anatomy (#27583)

Raphaël Bosi900291ef6712
diff --git a/packages/twenty-docs/snippets/ui/generated/input/field.mdx b/packages/twenty-docs/snippets/ui/generated/input/field.mdx
index c033b7b1358..d40913b9396 100644
--- a/packages/twenty-docs/snippets/ui/generated/input/field.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/input/field.mdx
@@ -82,6 +82,30 @@
- `onChange`: triggers validation on every change to the control value.
</ParamField>
+### Field.Item
+
+<ParamField body="Item.className" type="string | ((state: FieldItemState) =&gt; string | undefined)">
+ CSS class applied to the element, or a function that
+ returns a class based on the component's state.
+</ParamField>
+
+<ParamField body="Item.disabled" type="boolean" default="false">
+ Whether the wrapped control should ignore user interaction.
+ The `disabled` prop on `<Field.Root>` takes precedence over this.
+</ParamField>
+
+<ParamField body="Item.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, FieldItemState&gt;">
+ Allows you to replace the component's HTML element
+ with a different tag, or compose it with another component.
+
+ Accepts a `ReactElement` or a function that returns the element to render.
+</ParamField>
+
+<ParamField body="Item.style" type="CSSProperties | ((state: FieldItemState) =&gt; CSSProperties | undefined)">
+ Style applied to the element, or a function that
+ returns a style object based on the component's state.
+</ParamField>
+
### Field.Label
<ParamField body="Label.className" type="string | ((state: FieldLabelState) =&gt; string | undefined)">
diff --git a/packages/twenty-docs/ui/primitives/input/field.mdx b/packages/twenty-docs/ui/primitives/input/field.mdx
index b3fe499708d..82d81e8fd1c 100644
--- a/packages/twenty-docs/ui/primitives/input/field.mdx
+++ b/packages/twenty-docs/ui/primitives/input/field.mdx
@@ -30,6 +30,7 @@ Field.Root
| Part | Requirement | Purpose |
| ------------------------------------- | ------------------- | ---------------------------------------------------------------------------- |
| `Root` | Required | Shares the name, disabled state, and validation with the control. |
+| `Item` | Optional for groups | Associates each radio or checkbox with its own label and description. |
| `Label` | Recommended | Supplies a visible, associated label. An accessible name is always required. |
| `Input` or another integrated control | Required | Receives user input and connects to the field. |
| `Control` | Alternative control | Provides an unstyled input when you do not use an integrated control. |
@@ -79,6 +80,48 @@ export const UsernameField = ({ error }: UsernameFieldProps) => (
Keep error messages actionable and provide a visible label even when the control has a placeholder.
+## Grouped controls
+
+Use `Field.Item` inside a radio or checkbox group to associate each choice with its own label and description. Keep the group's label outside the items. An item can be disabled independently; a disabled `Field.Root` disables every item.
+
+<StoryEmbed
+ storyId="ui-input-field--grouped-items"
+ title="Field items"
+ height={360}
+/>
+
+```tsx
+import { Field, Radio, RadioGroup } from 'twenty-ui/primitives/input';
+
+export const NotificationsField = () => (
+ <Field.Root name="notifications">
+ <Field.Label>Notifications</Field.Label>
+ <RadioGroup defaultValue="important">
+ <Field.Item>
+ <Field.Label>Important updates</Field.Label>
+ <Radio value="important" />
+ <Field.Description>
+ Only messages that need your attention
+ </Field.Description>
+ </Field.Item>
+ <Field.Item disabled>
+ <Field.Label>Daily digest</Field.Label>
+ <Radio value="digest" />
+ <Field.Description>Coming soon</Field.Description>
+ </Field.Item>
+ </RadioGroup>
+ </Field.Root>
+);
+```
+
+## Native integration and types
+
+Field preserves Base UI validation timing, custom validation, controlled and uncontrolled control values, and value-change event details. `Validity` exposes the validation result through its children function. Integrated controls retain their native form behavior.
+
+`Root`, `Item`, `Label`, `Control`, `Description`, and `Error` forward native props, refs, and `render` composition. Their default elements are a div, div, label, input, paragraph, and div respectively. `Validity` does not render its own element.
+
+Import `FieldRootProps`, `FieldItemProps`, `FieldLabelProps`, `FieldControlProps`, `FieldDescriptionProps`, `FieldErrorProps`, and `FieldValidityProps` from `twenty-ui/primitives/input` for the corresponding upstream part contracts.
+
## Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.
diff --git a/packages/twenty-docs/ui/primitives/input/slider.mdx b/packages/twenty-docs/ui/primitives/input/slider.mdx
index a4189467a4e..1c2f1070a86 100644
--- a/packages/twenty-docs/ui/primitives/input/slider.mdx
+++ b/packages/twenty-docs/ui/primitives/input/slider.mdx
@@ -97,6 +97,8 @@ export const VolumeSlider = () => {
Use `onValueChange` to keep the controlled value current during an interaction. `onValueCommitted` handles the final value when the interaction finishes, for example to save it. Both callbacks are also available in uncontrolled mode without taking ownership of the value.
+Change details include the originating `event`, the interaction `reason`, the `activeThumbIndex`, and `cancel()`. Commit details use Base UI's generic event contract and do not include change cancellation. A canceled change does not commit.
+
## Range
```tsx
@@ -132,6 +134,16 @@ Arrow keys adjust a focused thumb by a step. Home and End move it toward the bou
Set `color="success"` for the alternative palette; the default is `accent`.
+The default `thumbAlignment` is `edge`. Pass `center` or `edge-client-only` to override it. Native `className`, `style`, and `render` composition remain available on each part, including state functions.
+
+## Native integration and types
+
+`Slider.Root` infers a number or a readonly numeric array from `value` or `defaultValue`, retaining that type in both callbacks. `SliderRootProps` accepts both by default; use `SliderRootProps<number>` for single-value helpers or `SliderRootProps<readonly number[]>` for range helpers.
+
+Every part has an exported props type in `twenty-ui/primitives/input`: `SliderRootProps`, `SliderControlProps`, `SliderTrackProps`, `SliderIndicatorProps`, `SliderThumbProps`, `SliderLabelProps`, and `SliderValueProps`.
+
+Refs target div elements for Root, Control, Track, Indicator, Thumb, and Label, and an output element for Value. A Thumb's ref targets its visible handle; its accessible name and native form value belong to the nested range input. Use `name` and `form` on Root for native submission, with one input per range value.
+
## Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-field-controls.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-field-controls.front-component.tsx
index 4bbfa007da8..7e560099177 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-field-controls.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-field-controls.front-component.tsx
@@ -1,6 +1,13 @@
import { useState } from 'react';
import { defineFrontComponent } from 'twenty-sdk/define';
-import { Field, Input, InputGroup, Textarea } from 'twenty-ui/primitives/input';
+import {
+ Field,
+ Input,
+ InputGroup,
+ Radio,
+ RadioGroup,
+ Textarea,
+} from 'twenty-ui/primitives/input';
import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';
@@ -11,6 +18,25 @@ const FieldControls = () => {
return (
<TwentyUiGalleryCard title="Field and text controls">
+ <Field.Root name="notifications">
+ <Field.Label>Notifications</Field.Label>
+ <RadioGroup defaultValue="important">
+ <Field.Item>
+ <Field.Label>Important updates</Field.Label>
+ <Radio value="important" />
+ <Field.Description>Only urgent messages</Field.Description>
+ </Field.Item>
+ <Field.Item>
+ <Field.Label>All updates</Field.Label>
+ <Radio value="all" />
+ <Field.Description>Every record change</Field.Description>
+ </Field.Item>
+ <Field.Item disabled>
+ <Field.Label>Daily digest</Field.Label>
+ <Radio value="digest" />
+ </Field.Item>
+ </RadioGroup>
+ </Field.Root>
<Field.Root>
<Field.Label>Email</Field.Label>
<InputGroup startElement="@" endElement=".com">
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/fieldControlsTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/fieldControlsTest.ts
index 500bc891ec8..163a42fc00e 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/fieldControlsTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/fieldControlsTest.ts
@@ -12,6 +12,22 @@ export const fieldControlsTest: TwentyUiGalleryPlayFunction = async ({
const email = canvas.getByRole('textbox', { name: 'Email' });
const notes = canvas.getByRole('textbox', { name: 'Notes' });
+ const important = canvas.getByRole('radio', { name: 'Important updates' });
+ const all = canvas.getByRole('radio', { name: 'All updates' });
+
+ expect(
+ canvas.getByRole('radiogroup', { name: 'Notifications' }),
+ ).toBeVisible();
+ expect(important).toHaveAccessibleDescription('Only urgent messages');
+ expect(all).toHaveAccessibleDescription('Every record change');
+ expect(canvas.getByRole('radio', { name: 'Daily digest' })).toHaveAttribute(
+ 'aria-disabled',
+ 'true',
+ );
+ expect(important).toBeChecked();
+ await userEvent.click(canvas.getByText('All updates', { exact: true }));
+ await waitFor(() => expect(all).toBeChecked());
+ expect(important).not.toBeChecked();
expect(email).toHaveAccessibleDescription('Use your work email');
expect(
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 0fe03e938cc..8d61851ad83 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -795,6 +795,13 @@
"CheckboxShape": "primitives/input/Checkbox/types/CheckboxShape",
"CheckboxSize": "primitives/input/Checkbox/types/CheckboxSize",
"CheckboxVariant": "primitives/input/Checkbox/types/CheckboxVariant",
+ "FieldControlProps": "primitives/input/Field/types/FieldControlProps",
+ "FieldDescriptionProps": "primitives/input/Field/types/FieldDescriptionProps",
+ "FieldErrorProps": "primitives/input/Field/types/FieldErrorProps",
+ "FieldItemProps": "primitives/input/Field/types/FieldItemProps",
+ "FieldLabelProps": "primitives/input/Field/types/FieldLabelProps",
+ "FieldRootProps": "primitives/input/Field/types/FieldRootProps",
+ "FieldValidityProps": "primitives/input/Field/types/FieldValidityProps",
"InputGroupProps": "primitives/input/InputGroup/types/InputGroupProps",
"InputProps": "primitives/input/Input/types/InputProps",
"InputSize": "primitives/input/types/InputSize",
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 174af89d11d..c2e0146c022 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -2305,6 +2305,39 @@
}
]
},
+ {
+ "name": "Item",
+ "props": [
+ {
+ "name": "className",
+ "type": "string | ((state: FieldItemState) => string | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class applied to the element, or a function that\nreturns a class based on the component's state."
+ },
+ {
+ "name": "disabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Whether the wrapped control should ignore user interaction.\nThe `disabled` prop on `<Field.Root>` takes precedence over this."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, FieldItemState>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Allows you to replace the component's HTML element\nwith a different tag, or compose it with another component.\n\nAccepts a `ReactElement` or a function that returns the element to render."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties | ((state: FieldItemState) => CSSProperties | undefined)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."
+ }
+ ]
+ },
{
"name": "Label",
"props": [
diff --git a/packages/twenty-ui/src/primitives/input/Field/Field.tsx b/packages/twenty-ui/src/primitives/input/Field/Field.tsx
index f2ff78f3e01..fe0b58ea3ae 100644
--- a/packages/twenty-ui/src/primitives/input/Field/Field.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/Field.tsx
@@ -6,6 +6,7 @@ import { FieldLabel } from './internal/FieldLabel';
export const Field = {
Root: FieldPrimitive.Root,
+ Item: FieldPrimitive.Item,
Label: FieldLabel,
Control: FieldPrimitive.Control,
Description: FieldDescription,
diff --git a/packages/twenty-ui/src/primitives/input/Field/__stories__/Field.stories.tsx b/packages/twenty-ui/src/primitives/input/Field/__stories__/Field.stories.tsx
index b5dd3d1cea4..6c99cfafc1f 100644
--- a/packages/twenty-ui/src/primitives/input/Field/__stories__/Field.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/__stories__/Field.stories.tsx
@@ -8,6 +8,8 @@ import {
} from '@ui/testing';
import { Field } from '@ui/primitives/input/Field/Field';
+import { Radio } from '@ui/primitives/input/Radio/Radio';
+import { RadioGroup } from '@ui/primitives/input/RadioGroup/RadioGroup';
const meta: Meta<typeof Field.Root> = {
title: 'UI/Input/Field',
@@ -40,6 +42,35 @@ export const WithError: Story = {
),
};
+export const GroupedItems: Story = {
+ decorators: [ComponentDecorator],
+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },
+ render: () => (
+ <Field.Root name="notifications">
+ <Field.Label>Notifications</Field.Label>
+ <RadioGroup defaultValue="important">
+ <Field.Item>
+ <Field.Label>Important updates</Field.Label>
+ <Radio value="important" />
+ <Field.Description>
+ Only messages that need your attention
+ </Field.Description>
+ </Field.Item>
+ <Field.Item>
+ <Field.Label>All updates</Field.Label>
+ <Radio value="all" />
+ <Field.Description>Every change to your records</Field.Description>
+ </Field.Item>
+ <Field.Item disabled>
+ <Field.Label>Daily digest</Field.Label>
+ <Radio value="digest" />
+ <Field.Description>Coming soon</Field.Description>
+ </Field.Item>
+ </RadioGroup>
+ </Field.Root>
+ ),
+};
+
type FieldCatalogState = 'default' | 'invalid' | 'disabled';
type FieldCatalogHelper = 'description' | 'error';
diff --git a/packages/twenty-ui/src/primitives/input/Field/__stories__/FieldInteractions.stories.tsx b/packages/twenty-ui/src/primitives/input/Field/__stories__/FieldInteractions.stories.tsx
new file mode 100644
index 00000000000..70af308931a
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/__stories__/FieldInteractions.stories.tsx
@@ -0,0 +1,153 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { useState } from 'react';
+import { expect, fn, userEvent, within } from 'storybook/test';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { Field } from '@ui/primitives/input/Field/Field';
+import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';
+
+import { GroupedItems } from './Field.stories';
+
+const ValidatedFieldExample = () => {
+ const [savedValue, setSavedValue] = useState('');
+
+ return (
+ <form
+ onSubmit={(event) => {
+ event.preventDefault();
+ setSavedValue(
+ String(new FormData(event.currentTarget).get('username')),
+ );
+ }}
+ >
+ <Field.Root
+ name="username"
+ validationMode="onBlur"
+ validate={(value) =>
+ value === 'taken' ? 'This username is taken' : null
+ }
+ >
+ <Field.Label>Username</Field.Label>
+ <Field.Control defaultValue="taken" />
+ <Field.Description>Choose a unique username</Field.Description>
+ <Field.Error />
+ <Field.Validity>
+ {({ validity }) => <output>Valid: {String(validity.valid)}</output>}
+ </Field.Validity>
+ </Field.Root>
+ <Button type="submit">Save username</Button>
+ <output>Saved username: {savedValue}</output>
+ </form>
+ );
+};
+
+const meta = {
+ title: 'UI/Input/Field/Interactions',
+ component: Field.Root,
+ decorators: [ComponentDecorator],
+ parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },
+} satisfies Meta<typeof Field.Root>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+export const ItemAssociation: Story = {
+ ...GroupedItems,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const important = canvas.getByRole('radio', { name: 'Important updates' });
+ const all = canvas.getByRole('radio', { name: 'All updates' });
+ const digest = canvas.getByRole('radio', { name: 'Daily digest' });
+
+ await expect(
+ canvas.getByRole('radiogroup', { name: 'Notifications' }),
+ ).toBeVisible();
+ await expect(important).toHaveAccessibleDescription(
+ 'Only messages that need your attention',
+ );
+ await expect(all).toHaveAccessibleDescription(
+ 'Every change to your records',
+ );
+ await expect(digest).toHaveAttribute('aria-disabled', 'true');
+ await expect(important).toBeChecked();
+ await userEvent.click(canvas.getByText('All updates'));
+ await expect(all).toBeChecked();
+ await expect(important).not.toBeChecked();
+ await userEvent.click(canvas.getByText('Daily digest'));
+ await expect(all).toBeChecked();
+ },
+};
+
+export const RootDisabled: Story = {
+ render: () => (
+ <Field.Root disabled>
+ <Field.Item disabled={false}>
+ <Field.Label>Disabled username</Field.Label>
+ <Field.Control defaultValue="Locked" />
+ </Field.Item>
+ </Field.Root>
+ ),
+ play: async ({ canvasElement }) => {
+ await expect(
+ within(canvasElement).getByRole('textbox', { name: 'Disabled username' }),
+ ).toBeDisabled();
+ },
+};
+
+export const Validation: Story = {
+ render: () => <ValidatedFieldExample />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const username = canvas.getByRole('textbox', { name: 'Username' });
+
+ await expect(username).toHaveAccessibleDescription(
+ 'Choose a unique username',
+ );
+ await userEvent.click(canvas.getByText('Username', { exact: true }));
+ await expect(username).toHaveFocus();
+ await userEvent.tab();
+ await expect(canvas.getByText('This username is taken')).toBeVisible();
+ await expect(username).toHaveAttribute('aria-invalid', 'true');
+ await expect(canvas.getByText('Valid: false')).toBeVisible();
+ await userEvent.clear(username);
+ await userEvent.type(username, 'raphael');
+ await userEvent.tab();
+ await expect(username).not.toHaveAttribute('aria-invalid', 'true');
+ await expect(canvas.getByText('Valid: true')).toBeVisible();
+ await expect(
+ canvas.queryByText('This username is taken'),
+ ).not.toBeInTheDocument();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Save username' }),
+ );
+ await expect(canvas.getByText('Saved username: raphael')).toBeVisible();
+ },
+};
+
+export const Controlled: Story = {
+ render: () => (
+ <Field.Root>
+ <Field.Label>Account name</Field.Label>
+ <Field.Control value="Locked" onValueChange={onValueChange} />
+ </Field.Root>
+ ),
+ play: async ({ canvasElement }) => {
+ const account = within(canvasElement).getByRole('textbox', {
+ name: 'Account name',
+ });
+
+ onValueChange.mockClear();
+ await userEvent.type(account, 'a');
+ await expect(account).toHaveValue('Locked');
+ await expect(onValueChange).toHaveBeenCalledTimes(1);
+ await expect(onValueChange).toHaveBeenCalledWith(
+ 'Lockeda',
+ expect.objectContaining({
+ reason: 'none',
+ event: expect.objectContaining({ type: 'input' }),
+ }),
+ );
+ },
+};
+
+const onValueChange = fn();
diff --git a/packages/twenty-ui/src/primitives/input/Field/__tests__/Field.test.tsx b/packages/twenty-ui/src/primitives/input/Field/__tests__/Field.test.tsx
index 5f25c1855c3..982aec0b2f0 100644
--- a/packages/twenty-ui/src/primitives/input/Field/__tests__/Field.test.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/__tests__/Field.test.tsx
@@ -17,6 +17,21 @@ runComponentConformance({
refInstanceOf: HTMLDivElement,
});
+runComponentConformance({
+ name: 'Field.Item',
+ element: <Field.Item />,
+ refInstanceOf: HTMLDivElement,
+ wrapper: FieldRootWrapper,
+});
+
+runComponentConformance({
+ name: 'Field.Control',
+ element: <Field.Control />,
+ refInstanceOf: HTMLInputElement,
+ wrapper: FieldRootWrapper,
+ renderPropTagName: 'input',
+});
+
runComponentConformance({
name: 'Field.Label',
element: <Field.Label>Label</Field.Label>,
diff --git a/packages/twenty-ui/src/primitives/input/Field/internal/FieldDescription.tsx b/packages/twenty-ui/src/primitives/input/Field/internal/FieldDescription.tsx
index fab271ac7b7..f3dfe5d9e83 100644
--- a/packages/twenty-ui/src/primitives/input/Field/internal/FieldDescription.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/internal/FieldDescription.tsx
@@ -3,12 +3,9 @@ import { forwardRef } from 'react';
import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+import { type FieldDescriptionProps } from '../types/FieldDescriptionProps';
import styles from './FieldDescription.module.scss';
-type FieldDescriptionProps = React.ComponentPropsWithoutRef<
- typeof FieldPrimitive.Description
->;
-
export const FieldDescription = forwardRef<
React.ElementRef<typeof FieldPrimitive.Description>,
FieldDescriptionProps
diff --git a/packages/twenty-ui/src/primitives/input/Field/internal/FieldError.tsx b/packages/twenty-ui/src/primitives/input/Field/internal/FieldError.tsx
index 376c0f13eba..68346bc526b 100644
--- a/packages/twenty-ui/src/primitives/input/Field/internal/FieldError.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/internal/FieldError.tsx
@@ -3,12 +3,9 @@ import { forwardRef } from 'react';
import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+import { type FieldErrorProps } from '../types/FieldErrorProps';
import styles from './FieldError.module.scss';
-type FieldErrorProps = React.ComponentPropsWithoutRef<
- typeof FieldPrimitive.Error
->;
-
export const FieldError = forwardRef<
React.ElementRef<typeof FieldPrimitive.Error>,
FieldErrorProps
diff --git a/packages/twenty-ui/src/primitives/input/Field/internal/FieldLabel.tsx b/packages/twenty-ui/src/primitives/input/Field/internal/FieldLabel.tsx
index 9a6b2ebbf26..d12719cfd0f 100644
--- a/packages/twenty-ui/src/primitives/input/Field/internal/FieldLabel.tsx
+++ b/packages/twenty-ui/src/primitives/input/Field/internal/FieldLabel.tsx
@@ -3,12 +3,9 @@ import { forwardRef } from 'react';
import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';
+import { type FieldLabelProps } from '../types/FieldLabelProps';
import styles from './FieldLabel.module.scss';
-type FieldLabelProps = React.ComponentPropsWithoutRef<
- typeof FieldPrimitive.Label
->;
-
export const FieldLabel = forwardRef<
React.ElementRef<typeof FieldPrimitive.Label>,
FieldLabelProps
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldControlProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldControlProps.ts
new file mode 100644
index 00000000000..e8e18618c76
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldControlProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldControlProps = FieldPrimitive.Control.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldDescriptionProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldDescriptionProps.ts
new file mode 100644
index 00000000000..69a028c41c2
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldDescriptionProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldDescriptionProps = FieldPrimitive.Description.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldErrorProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldErrorProps.ts
new file mode 100644
index 00000000000..19c930e64e9
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldErrorProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldErrorProps = FieldPrimitive.Error.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldItemProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldItemProps.ts
new file mode 100644
index 00000000000..bc47e86685b
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldItemProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldItemProps = FieldPrimitive.Item.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldLabelProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldLabelProps.ts
new file mode 100644
index 00000000000..cccb6a887ea
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldLabelProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldLabelProps = FieldPrimitive.Label.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldRootProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldRootProps.ts
new file mode 100644
index 00000000000..8a6d19c5b14
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldRootProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldRootProps = FieldPrimitive.Root.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Field/types/FieldValidityProps.ts b/packages/twenty-ui/src/primitives/input/Field/types/FieldValidityProps.ts
new file mode 100644
index 00000000000..38ec864141f
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Field/types/FieldValidityProps.ts
@@ -0,0 +1,3 @@
+import { type Field as FieldPrimitive } from '@base-ui/react/field';
+
+export type FieldValidityProps = FieldPrimitive.Validity.Props;
diff --git a/packages/twenty-ui/src/primitives/input/Slider/__stories__/SliderInteractions.stories.tsx b/packages/twenty-ui/src/primitives/input/Slider/__stories__/SliderInteractions.stories.tsx
index f8da08ea647..17ca749698a 100644
--- a/packages/twenty-ui/src/primitives/input/Slider/__stories__/SliderInteractions.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Slider/__stories__/SliderInteractions.stories.tsx
@@ -1,14 +1,15 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
-import { expect, fn, userEvent, within } from 'storybook/test';
+import { clearAllMocks, expect, fn, userEvent, within } from 'storybook/test';
import { Field } from '@ui/primitives/input/Field/Field';
+import { Button } from '@ui/primitives/input/Button/Button';
import { ComponentDecorator } from '@ui/testing';
import { Slider } from '../Slider';
import { type SliderRootProps } from '../types/SliderRootProps';
-const SliderExample = (props: SliderRootProps) => (
+const SliderExample = (props: SliderRootProps<number>) => (
<Slider.Root {...props}>
<Slider.Control data-testid="slider-control">
<Slider.Track>
@@ -19,7 +20,7 @@ const SliderExample = (props: SliderRootProps) => (
</Slider.Root>
);
-const ControlledSliderExample = (props: SliderRootProps) => {
+const ControlledSliderExample = (props: SliderRootProps<number>) => {
const [value, setValue] = useState(40);
return (
@@ -52,6 +53,47 @@ const FormSliderExample = () => {
);
};
+const ControlledRangeExample = (props: SliderRootProps<readonly number[]>) => {
+ const [value, setValue] = useState<readonly number[]>([25, 75]);
+ const [savedRange, setSavedRange] = useState('');
+
+ return (
+ <form
+ onSubmit={(event) => {
+ event.preventDefault();
+ setSavedRange(
+ new FormData(event.currentTarget).getAll('price').join(', '),
+ );
+ }}
+ >
+ <Slider.Root
+ {...props}
+ name="price"
+ value={value}
+ onValueChange={(nextValue, details) => {
+ setValue(nextValue);
+ props.onValueChange?.(nextValue, details);
+ }}
+ >
+ <Slider.Label>Price range</Slider.Label>
+ <Slider.Value />
+ <Slider.Control>
+ <Slider.Track>
+ <Slider.Indicator />
+ <Slider.Thumb index={0} aria-label="Minimum price" />
+ <Slider.Thumb index={1} aria-label="Maximum price" />
+ </Slider.Track>
+ </Slider.Control>
+ </Slider.Root>
+ <Button type="button" onClick={() => setValue([10, 90])}>
+ Reset prices
+ </Button>
+ <Button type="submit">Save prices</Button>
+ <output>Saved prices: {savedRange}</output>
+ </form>
+ );
+};
+
const meta = {
title: 'UI/Input/Slider/Interactions',
component: Slider.Root<number>,
@@ -251,3 +293,52 @@ export const FunctionProps: Story = {
await expect(root).toHaveAttribute('data-volume', '41');
},
};
+
+export const ControlledRange: StoryObj<typeof Slider.Root<readonly number[]>> =
+ {
+ decorators: [ComponentDecorator],
+ args: {
+ onValueChange: fn(),
+ onValueCommitted: fn(),
+ thumbAlignment: 'center',
+ color: 'success',
+ },
+ render: (args) => <ControlledRangeExample {...args} />,
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const minimum = canvas.getByRole('slider', { name: 'Minimum price' });
+ const maximum = canvas.getByRole('slider', { name: 'Maximum price' });
+
+ clearAllMocks();
+ minimum.focus();
+ await userEvent.keyboard('{ArrowRight}');
+ await expect(minimum).toHaveValue('26');
+ await expect(maximum).toHaveValue('75');
+ await expect(args.onValueChange).toHaveBeenCalledTimes(1);
+ await expect(args.onValueChange).toHaveBeenCalledWith(
+ [26, 75],
+ expect.objectContaining({
+ activeThumbIndex: 0,
+ reason: 'keyboard',
+ event: expect.objectContaining({ type: 'keydown' }),
+ }),
+ );
+ await expect(args.onValueCommitted).toHaveBeenCalledTimes(1);
+ await expect(args.onValueCommitted).toHaveBeenCalledWith(
+ [26, 75],
+ expect.objectContaining({
+ reason: 'keyboard',
+ event: expect.objectContaining({ type: 'keydown' }),
+ }),
+ );
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Save prices' }),
+ );
+ await expect(canvas.getByText('Saved prices: 26, 75')).toBeVisible();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Reset prices' }),
+ );
+ await expect(minimum).toHaveValue('10');
+ await expect(maximum).toHaveValue('90');
+ },
+ };
diff --git a/packages/twenty-ui/src/primitives/input/Slider/__tests__/SliderTypes.test.tsx b/packages/twenty-ui/src/primitives/input/Slider/__tests__/SliderTypes.test.tsx
new file mode 100644
index 00000000000..f32f73d6f0b
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Slider/__tests__/SliderTypes.test.tsx
@@ -0,0 +1,56 @@
+import { type Slider as SliderPrimitive } from '@base-ui/react/slider';
+import { expectTypeOf, it } from 'vitest';
+
+import { Slider, type SliderRootProps } from '@ui/primitives/input';
+
+it('accepts the upstream default single or range props', () => {
+ expectTypeOf<
+ Omit<SliderRootProps, 'color'>
+ >().toEqualTypeOf<SliderPrimitive.Root.Props>();
+ expectTypeOf<SliderRootProps<number>['onValueChange']>().toEqualTypeOf<
+ SliderPrimitive.Root.Props<number>['onValueChange']
+ >();
+ expectTypeOf<
+ SliderRootProps<readonly [number, number]>['onValueCommitted']
+ >().toEqualTypeOf<
+ SliderPrimitive.Root.Props<readonly [number, number]>['onValueCommitted']
+ >();
+});
+
+it('infers number values and distinct change and commit details', () => {
+ <Slider.Root
+ defaultValue={40}
+ onValueChange={(value, details) => {
+ expectTypeOf(value).toEqualTypeOf<number>();
+ expectTypeOf(
+ details,
+ ).toEqualTypeOf<SliderPrimitive.Root.ChangeEventDetails>();
+ }}
+ onValueCommitted={(value, details) => {
+ expectTypeOf(value).toEqualTypeOf<number>();
+ expectTypeOf(
+ details,
+ ).toEqualTypeOf<SliderPrimitive.Root.CommitEventDetails>();
+ }}
+ />;
+});
+
+it('retains readonly tuple inference in change and commit callbacks', () => {
+ const range: readonly [number, number] = [25, 75];
+
+ <Slider.Root
+ value={range}
+ onValueChange={(value, details) => {
+ expectTypeOf(value).toEqualTypeOf<typeof range>();
+ expectTypeOf(
+ details,
+ ).toEqualTypeOf<SliderPrimitive.Root.ChangeEventDetails>();
+ }}
+ onValueCommitted={(value, details) => {
+ expectTypeOf(value).toEqualTypeOf<typeof range>();
+ expectTypeOf(
+ details,
+ ).toEqualTypeOf<SliderPrimitive.Root.CommitEventDetails>();
+ }}
+ />;
+});
diff --git a/packages/twenty-ui/src/primitives/input/Slider/types/SliderRootProps.ts b/packages/twenty-ui/src/primitives/input/Slider/types/SliderRootProps.ts
index db580ad1ce2..1575217e7dc 100644
--- a/packages/twenty-ui/src/primitives/input/Slider/types/SliderRootProps.ts
+++ b/packages/twenty-ui/src/primitives/input/Slider/types/SliderRootProps.ts
@@ -1,7 +1,7 @@
import { type Slider as SliderPrimitive } from '@base-ui/react/slider';
export type SliderRootProps<
- TValue extends number | readonly number[] = number,
+ TValue extends number | readonly number[] = number | readonly number[],
> = SliderPrimitive.Root.Props<TValue> & {
/** Color of the indicator and thumbs. */
color?: 'accent' | 'success';
diff --git a/packages/twenty-ui/src/primitives/input/index.ts b/packages/twenty-ui/src/primitives/input/index.ts
index a0d4aa922c4..d4d614f1ae0 100644
--- a/packages/twenty-ui/src/primitives/input/index.ts
+++ b/packages/twenty-ui/src/primitives/input/index.ts
@@ -30,6 +30,13 @@ export type { CheckboxShape } from './Checkbox/types/CheckboxShape';
export type { CheckboxSize } from './Checkbox/types/CheckboxSize';
export type { CheckboxVariant } from './Checkbox/types/CheckboxVariant';
export { Field } from './Field/Field';
+export type { FieldControlProps } from './Field/types/FieldControlProps';
+export type { FieldDescriptionProps } from './Field/types/FieldDescriptionProps';
+export type { FieldErrorProps } from './Field/types/FieldErrorProps';
+export type { FieldItemProps } from './Field/types/FieldItemProps';
+export type { FieldLabelProps } from './Field/types/FieldLabelProps';
+export type { FieldRootProps } from './Field/types/FieldRootProps';
+export type { FieldValidityProps } from './Field/types/FieldValidityProps';
export { Input } from './Input/Input';
export type { InputProps } from './Input/types/InputProps';
export { InputGroup } from './InputGroup/InputGroup';