Skip to content

The open alternative to Salesforce, designed for AI.

Let render-composed Autocomplete inputs own their look (#28261)

Raphaël Bosidb3e04033505
diff --git a/packages/twenty-docs/snippets/ui/generated/input/autocomplete.mdx b/packages/twenty-docs/snippets/ui/generated/input/autocomplete.mdx
index 10f0856d1a2..81a5411397e 100644
--- a/packages/twenty-docs/snippets/ui/generated/input/autocomplete.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/input/autocomplete.mdx
@@ -259,7 +259,7 @@
</ParamField>
<ParamField body="Input.size" type="&quot;md&quot; | &quot;sm&quot;">
- Visual size of the input. Inside an InputGroup, the group size applies.
+ Visual size of the input. Inside an InputGroup, the group size applies. Not accepted with render.
</ParamField>
<ParamField body="Input.style" type="CSSProperties | ((state: ComboboxInputState) =&gt; CSSProperties | undefined)">
diff --git a/packages/twenty-docs/ui/primitives/input/autocomplete.mdx b/packages/twenty-docs/ui/primitives/input/autocomplete.mdx
index 690a32c8a08..360735fdfac 100644
--- a/packages/twenty-docs/ui/primitives/input/autocomplete.mdx
+++ b/packages/twenty-docs/ui/primitives/input/autocomplete.mdx
@@ -233,9 +233,9 @@ Keep Root mounted when results arrive asynchronously. Control `open` independent
## Input composition and native forms
-`Input` accepts `size="sm"` or `size="md"` and uses the same styles as [Input](/ui/primitives/input/input). Compose it with an existing input using `render`. Forward the supplied ref, native attributes, and handlers to the actual input element.
+`Input` accepts `size="sm"` or `size="md"` and uses the same styles as [Input](/ui/primitives/input/input). Compose it with an existing input using `render`. The composed control then owns its look: `Input` adds no Input styles and ignores `size`, but still passes your `className`, native attributes, handlers, ref, and state attributes. Forward them to the actual input element. Render Twenty UI `Input` to keep the standard look.
-`InputGroup` provides layout and an anchor without adding input borders. It can contain chips or render an existing wrapper. Use [InputGroup](/ui/primitives/input/input-group) through its `render` prop when the whole group needs input styling. Give the input an accessible label or compose it with [Field](/ui/primitives/input/field).
+`InputGroup` provides layout and an anchor without adding input borders. It can contain chips or render an existing wrapper. Use [InputGroup](/ui/primitives/input/input-group) through its `render` prop when the whole group needs input styling, as the grouped object suggestions story does. An `Input` without `render` inside it drops its own border. Give the input an accessible label or compose it with [Field](/ui/primitives/input/field).
Root preserves the upstream `name`, `form`, `disabled`, `readOnly`, and native form behavior. Input's native attributes and ref target its input. `submitOnItemClick` opts into form submission when selecting a suggestion; the default does not submit.
diff --git a/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventLocationInput.tsx b/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventLocationInput.tsx
index a5d384f1e72..1755ad63f43 100644
--- a/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventLocationInput.tsx
+++ b/packages/twenty-front/src/modules/activities/calendar/components/CalendarEventLocationInput.tsx
@@ -61,10 +61,7 @@ export const CalendarEventLocationInput = ({
autoComplete="off"
aria-label={ariaLabel}
placeholder={placeholder}
- render={(inputProps) => (
- // oxlint-disable-next-line react/jsx-props-no-spreading
- <StyledComposerTextInput {...inputProps} className={undefined} />
- )}
+ render={<StyledComposerTextInput />}
/>
<PlaceAutocompleteSelect
list={placeAutocompleteData}
diff --git a/packages/twenty-front/src/modules/activities/emails/recipients/components/EmailRecipientsFieldInput.tsx b/packages/twenty-front/src/modules/activities/emails/recipients/components/EmailRecipientsFieldInput.tsx
index 021f020e4e9..6d649d6607f 100644
--- a/packages/twenty-front/src/modules/activities/emails/recipients/components/EmailRecipientsFieldInput.tsx
+++ b/packages/twenty-front/src/modules/activities/emails/recipients/components/EmailRecipientsFieldInput.tsx
@@ -581,10 +581,7 @@ export const EmailRecipientsFieldInput = ({
const recipientsInput = (
<Autocomplete.Input
key="email-recipients-input"
- render={(inputProps) => (
- // oxlint-disable-next-line react/jsx-props-no-spreading
- <StyledInput {...inputProps} className={undefined} />
- )}
+ render={<StyledInput />}
ref={inputRef}
type="text"
autoComplete="off"
diff --git a/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx b/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx
index a75029caa93..2d0cc512dec 100644
--- a/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx
+++ b/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx
@@ -262,7 +262,7 @@ export const AddressInput = ({
aria-label={label}
render={(inputProps) => (
<TextInput
- inputProps={{ ...inputProps, className: undefined }}
+ inputProps={inputProps}
autoFocus={autoFocus}
ref={inputRefs[fieldType]}
label={label}
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index 2cfaac22d9e..d3efb1822b2 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -478,6 +478,11 @@ export const DOCUMENTED_COMPONENTS = [
type: '(highlightedValue: TItem | undefined, eventDetails: AutocompleteRootHighlightEventDetails) => void',
},
},
+ Input: {
+ render: {
+ type: 'ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxInputState>',
+ },
+ },
},
partPropDescriptions: {
Root: {
@@ -492,7 +497,7 @@ export const DOCUMENTED_COMPONENTS = [
children: 'Render function receiving each filtered item and its index.',
},
Input: {
- size: 'Visual size of the input. Inside an InputGroup, the group size applies.',
+ size: 'Visual size of the input. Inside an InputGroup, the group size applies. Not accepted with render.',
},
Popup: {
width:
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 2444095d106..dcb82bd2b58 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -5385,7 +5385,7 @@
"type": "\"md\" | \"sm\"",
"required": false,
"defaultValue": null,
- "description": "Visual size of the input. Inside an InputGroup, the group size applies."
+ "description": "Visual size of the input. Inside an InputGroup, the group size applies. Not accepted with render."
},
{
"name": "style",
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.composition.stories.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.composition.stories.tsx
index 7aa7915d04e..aa7c96983ae 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.composition.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/Autocomplete.composition.stories.tsx
@@ -8,8 +8,10 @@ import {
within,
} from 'storybook/test';
+import inputStyles from '@ui/primitives/input/Input/Input.module.scss';
import { ComponentDecorator } from '@ui/testing';
+import { Autocomplete } from '../Autocomplete';
import { type AutocompleteRootProps } from '../types/AutocompleteRootProps';
import { AutocompleteExample } from './AutocompleteExample';
@@ -156,3 +158,55 @@ export const CancelledDismissal: Story = {
await expect(body.getByRole('listbox')).toBeVisible();
},
};
+
+export const ComposedInputAppearance: Story = {
+ render: () => (
+ <>
+ <AutocompleteExample />
+ <Autocomplete.Root
+ items={['Apple', 'Banana', 'Cherry']}
+ autoHighlight="always"
+ >
+ <Autocomplete.Input aria-label="Composed fruit" render={<input />} />
+ <Autocomplete.Portal>
+ <Autocomplete.Positioner>
+ <Autocomplete.Popup>
+ <Autocomplete.List>
+ {(fruit: string) => (
+ <Autocomplete.Item key={fruit} value={fruit}>
+ {fruit}
+ </Autocomplete.Item>
+ )}
+ </Autocomplete.List>
+ </Autocomplete.Popup>
+ </Autocomplete.Positioner>
+ </Autocomplete.Portal>
+ </Autocomplete.Root>
+ </>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const defaultInput = canvas.getByRole('combobox', { name: 'Fruit' });
+ const composedInput = canvas.getByRole('combobox', {
+ name: 'Composed fruit',
+ });
+
+ await expect(defaultInput).toHaveClass(inputStyles.input, inputStyles.md);
+ await expect(composedInput).not.toHaveClass(inputStyles.input);
+ await expect(composedInput).not.toHaveClass(inputStyles.md);
+
+ await userEvent.type(composedInput, 'Ch');
+ const cherry = await body.findByRole('option', { name: 'Cherry' });
+ await waitFor(() =>
+ expect(composedInput).toHaveAttribute('aria-activedescendant', cherry.id),
+ );
+ await expect(composedInput).toHaveFocus();
+ await userEvent.keyboard('{Enter}');
+ await expect(composedInput).toHaveValue('Cherry');
+ await expect(composedInput).toHaveFocus();
+ await waitFor(() =>
+ expect(body.queryByRole('listbox')).not.toBeInTheDocument(),
+ );
+ },
+};
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteGroupedExample.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteGroupedExample.tsx
index 15f2e626c25..cbbdcf13ce6 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteGroupedExample.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/__stories__/AutocompleteGroupedExample.tsx
@@ -1,5 +1,6 @@
import { IconChevronDown, IconX } from '@ui/icon';
import { Button } from '@ui/primitives/input/Button/Button';
+import { InputGroup } from '@ui/primitives/input/InputGroup/InputGroup';
import { Text } from '@ui/primitives/typography/Text/Text';
import { Autocomplete } from '../Autocomplete';
@@ -33,7 +34,7 @@ export const AutocompleteGroupedExample = () => (
itemToStringValue={(city) => city.name}
autoHighlight="always"
>
- <Autocomplete.InputGroup style={{ gap: 4 }}>
+ <Autocomplete.InputGroup render={<InputGroup />}>
<Autocomplete.Input id="grouped-city" placeholder="Search cities" />
<Autocomplete.Clear
aria-label="Clear city"
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/__tests__/Autocomplete.test.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/__tests__/Autocomplete.test.tsx
index 105cddf1e71..c661c482185 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/__tests__/Autocomplete.test.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/__tests__/Autocomplete.test.tsx
@@ -1,4 +1,5 @@
-import { type ReactNode } from 'react';
+import { type ReactElement, type ReactNode } from 'react';
+import { expectTypeOf, it } from 'vitest';
import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
import inputStyles from '@ui/primitives/input/Input/Input.module.scss';
@@ -6,6 +7,7 @@ import listItemStyles from '@ui/primitives/navigation/ListItem/ListItem.module.s
import { Autocomplete } from '@ui/primitives/input';
import styles from '../Autocomplete.module.scss';
+import { type AutocompleteInputProps } from '../types/AutocompleteInputProps';
const RootWrapper = ({ children }: { children: ReactNode }) => (
<Autocomplete.Root>{children}</Autocomplete.Root>
@@ -44,6 +46,7 @@ runComponentConformance({
refInstanceOf: HTMLInputElement,
wrapper: RootWrapper,
ownClassName: inputStyles.input,
+ renderPropKeepsOwnClassName: false,
renderPropTagName: 'input',
});
runComponentConformance({
@@ -131,3 +134,12 @@ runComponentConformance({
wrapper: RootWrapper,
renderPropTagName: 'button',
});
+
+it('accepts size only on an Autocomplete.Input without render', () => {
+ expectTypeOf<{ size: 'sm' }>().toExtend<AutocompleteInputProps>();
+ expectTypeOf<{ render: ReactElement }>().toExtend<AutocompleteInputProps>();
+ expectTypeOf<{
+ render: ReactElement;
+ size: 'sm';
+ }>().not.toExtend<AutocompleteInputProps>();
+});
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/internal/AutocompleteInput.tsx b/packages/twenty-ui/src/primitives/input/Autocomplete/internal/AutocompleteInput.tsx
index e9c6ad777b4..ab76263c7fe 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/internal/AutocompleteInput.tsx
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/internal/AutocompleteInput.tsx
@@ -12,9 +12,21 @@ import { type AutocompleteInputProps } from '../types/AutocompleteInputProps';
export const AutocompleteInput = ({
size,
className,
+ render,
...props
}: AutocompleteInputProps) => {
const inputGroup = useContext(InputGroupContext);
+
+ if (isDefined(render)) {
+ return (
+ <AutocompletePrimitive.Input
+ {...props}
+ className={className}
+ render={render}
+ />
+ );
+ }
+
const resolvedSize = size ?? inputGroup?.size ?? 'md';
return (
diff --git a/packages/twenty-ui/src/primitives/input/Autocomplete/types/AutocompleteInputProps.ts b/packages/twenty-ui/src/primitives/input/Autocomplete/types/AutocompleteInputProps.ts
index 42653ffa82d..5a9b2fc422f 100644
--- a/packages/twenty-ui/src/primitives/input/Autocomplete/types/AutocompleteInputProps.ts
+++ b/packages/twenty-ui/src/primitives/input/Autocomplete/types/AutocompleteInputProps.ts
@@ -2,9 +2,20 @@ import { type Autocomplete as AutocompletePrimitive } from '@base-ui/react/autoc
import { type InputSize } from '@ui/primitives/input/types/InputSize';
-export type AutocompleteInputProps = Omit<
+type AutocompletePrimitiveInputProps = Omit<
AutocompletePrimitive.Input.Props,
'size'
-> & {
- size?: InputSize;
-};
+>;
+
+type AutocompleteInputAppearanceProps =
+ | {
+ render?: undefined;
+ size?: InputSize;
+ }
+ | {
+ render: NonNullable<AutocompletePrimitive.Input.Props['render']>;
+ size?: never;
+ };
+
+export type AutocompleteInputProps = AutocompletePrimitiveInputProps &
+ AutocompleteInputAppearanceProps;
diff --git a/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx
index 4fed54931c3..e0e1688199d 100644
--- a/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx
+++ b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx
@@ -46,6 +46,7 @@ export const runComponentConformance = ({
refInstanceOf,
wrapper: Wrapper,
ownClassName,
+ renderPropKeepsOwnClassName = true,
renderPropTagName = 'span',
skip = [],
}: ComponentConformanceOptions) => {
@@ -194,7 +195,9 @@ export const runComponentConformance = ({
expect(ref.current).toBe(rootNode);
if (isDefined(ownClassName)) {
- expect(rootNode).toHaveClass(ownClassName);
+ expect(rootNode.classList.contains(ownClassName)).toBe(
+ renderPropKeepsOwnClassName,
+ );
}
});
diff --git a/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts
index edffe6a76e5..277ea15a04e 100644
--- a/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts
+++ b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts
@@ -13,6 +13,7 @@ export type ComponentConformanceOptions = {
refInstanceOf: new () => Element;
wrapper?: ComponentType<{ children: ReactNode }>;
ownClassName?: string;
+ renderPropKeepsOwnClassName?: boolean;
renderPropTagName?: keyof JSX.IntrinsicElements;
skip?: ComponentConformanceCase[];
};