Skip to content

The open alternative to Salesforce, designed for AI.

Clarify ImageInput file selection (#27706)

Raphaël Bosi97214317187d
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/image-input.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/image-input.mdx
index 4e2aefd80f5..5743593c818 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/image-input.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/image-input.mdx
@@ -16,13 +16,33 @@
</ParamField>
<ParamField body="accept" type="string" default="image/*">
- Native file picker filter. Defaults to image/*. The application validates the selected file.
+ Native file picker filter. Defaults to image/*. The caller validates allowed formats.
+</ParamField>
+
+<ParamField body="aria-describedby" type="string">
+ Accessible description references for the hidden file input and selection buttons, combined with helperText and errorMessage.
+</ParamField>
+
+<ParamField body="aria-label" type="string">
+ Accessible name of the hidden file input. Defaults to uploadLabel.
+</ParamField>
+
+<ParamField body="aria-labelledby" type="string">
+ Accessible name reference for the hidden file input.
+</ParamField>
+
+<ParamField body="capture" type="boolean | &quot;user&quot; | &quot;environment&quot;">
+ Native device capture hint for the file picker.
</ParamField>
<ParamField body="className" type="string">
Class applied to the root element.
</ParamField>
+<ParamField body="dir" type="string">
+ Text direction applied to both the root and hidden file input.
+</ParamField>
+
<ParamField body="disabled" type="boolean" default="false">
Disables file selection, removal, and abort actions.
</ParamField>
@@ -31,28 +51,48 @@
Application error, displayed as an alert and associated with the selection controls.
</ParamField>
+<ParamField body="form" type="string">
+ Native form identifier associated with the hidden file input.
+</ParamField>
+
<ParamField body="helperText" type="string">
Application instructions, associated with the selection controls.
</ParamField>
+<ParamField body="id" type="string">
+ Native identifier of the hidden file input.
+</ParamField>
+
+<ParamField body="inputRef" type="Ref&lt;HTMLInputElement&gt;">
+ Ref to the hidden single-file HTMLInputElement.
+</ParamField>
+
<ParamField body="isUploading" type="boolean" default="false">
Marks the module busy. Selection and removal controls that would otherwise be enabled stay focusable but unavailable. Shows Abort when onAbort is supplied.
</ParamField>
+<ParamField body="name" type="string">
+ Native name of the hidden file input.
+</ParamField>
+
<ParamField body="onAbort" type="(() =&gt; void)">
Shows an abort action while uploading. It can cancel the first upload before a src exists.
</ParamField>
-<ParamField body="onRemove" type="(() =&gt; void)">
- Requests removal of the current image. Removal is disabled without this callback or a nonempty src.
+<ParamField body="onChange" type="ChangeEventHandler&lt;HTMLInputElement, HTMLInputElement&gt;">
+ Native file input change event, fired while the selected file is present and before the input resets. The input does not retain a file for form submission.
+</ParamField>
+
+<ParamField body="onFileSelect" type="((file: File) =&gt; void)">
+ Fires when a file is selected and receives its usable File after the input resets. Empty and canceled selections do not call it. Selection is disabled when omitted. The caller owns validation and uploading.
</ParamField>
-<ParamField body="onUpload" type="((file: File) =&gt; void)">
- Receives the selected File. Empty and canceled selections do not call it. Selection is disabled when omitted.
+<ParamField body="onRemove" type="(() =&gt; void)">
+ Requests removal of the current image. Removal is disabled without this callback or a nonempty src.
</ParamField>
<ParamField body="ref" type="Ref&lt;HTMLDivElement&gt;">
- Ref to the root element.
+ Ref to the root div element.
</ParamField>
<ParamField body="removeLabel" type="string" default="Remove">
@@ -60,7 +100,11 @@
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, {}&gt;">
- Custom root element or render function. Keep a non-interactive root.
+ Custom root element or render function. Supply root native attributes here and keep a non-interactive root.
+</ParamField>
+
+<ParamField body="required" type="boolean">
+ Native file input requirement. The input resets after selection, so the caller validates completed uploads.
</ParamField>
<ParamField body="src" type="string | null">
@@ -71,6 +115,10 @@
Inline style applied to the root element.
</ParamField>
+<ParamField body="title" type="string">
+ Native title of the hidden file input.
+</ParamField>
+
<ParamField body="uploadLabel" type="string" default="Upload">
- Label for the preview and Upload action.
+ Label for the preview, Upload action, and hidden file input.
</ParamField>
diff --git a/packages/twenty-docs/ui/components/input/image-input.mdx b/packages/twenty-docs/ui/components/input/image-input.mdx
index ea9e7361196..14f0eab1ca9 100644
--- a/packages/twenty-docs/ui/components/input/image-input.mdx
+++ b/packages/twenty-docs/ui/components/input/image-input.mdx
@@ -1,12 +1,12 @@
---
title: ImageInput
-description: Image selection, preview, and upload actions with application-owned storage.
+description: Image selection, preview, and caller-owned upload actions.
---
import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import ImageInputReference from '/snippets/ui/generated/components/input/image-input.mdx';
-`ImageInput` combines an image preview, a native file picker, and upload, remove, or abort actions. Pass a resolved image URL as `src`. Your application validates files, uploads them, saves the resulting URL, and supplies instructions and errors.
+`ImageInput` combines an image preview, a native file picker, and upload, remove, or abort actions. `onFileSelect` fires when a file is selected. Your application validates and uploads the file, owns upload progress and cancellation, and supplies the preview URL through `src`.
<StoryEmbed
storyId="ui-input-imageinput--with-helper-text"
@@ -19,13 +19,14 @@ import { ImageInput, type ImageInputProps } from 'twenty-ui/components/input';
export const WorkspaceImage = ({
src,
- onUpload,
+ onFileSelect,
onRemove,
-}: Pick<ImageInputProps, 'src' | 'onUpload' | 'onRemove'>) => (
+}: Pick<ImageInputProps, 'src' | 'onFileSelect' | 'onRemove'>) => (
<ImageInput
src={src}
- onUpload={onUpload}
+ onFileSelect={onFileSelect}
onRemove={onRemove}
+ accept="image/png, image/jpeg"
helperText="Choose a square image for your workspace."
/>
);
@@ -33,19 +34,29 @@ export const WorkspaceImage = ({
## Selection and preview
-The preview and Upload button open the same native file picker. `onUpload` receives the selected `File`. Canceling or returning an empty selection leaves the current image unchanged. The file input clears after selection so the same file can be selected again.
+The preview and Upload button open the same native file picker. `onFileSelect` receives the selected `File`; it does not start an upload itself. Canceling or returning an empty selection leaves the current image unchanged. The file input clears after selection so the same file can be selected again, and the callback's `File` remains usable.
-Native file selection and usable `File` contents are not supported in the current front-component sandbox. React and Preact renderer coverage includes previews, action callbacks, and state. Use an ordinary React host for the complete native selection flow.
+Native file selection and readable `File` contents require the pending [renderer file selection update](https://github.com/twentyhq/twenty/pull/27588) in the front-component sandbox. Current React and Preact renderer coverage includes previews, action callbacks, and state. Use an ordinary React host for the complete native selection flow until that update is available.
-The `accept` prop defaults to `image/*` and filters the file picker. Validate allowed formats, dimensions, and size in your application. This callback-driven selector does not retain a file for native form submission. Its action buttons use `type="button"`, so they do not submit a surrounding form.
+`accept` defaults to `image/*` and filters the file picker. Validate allowed formats, dimensions, and size in your application. This callback-driven selector does not retain a file for native form submission. Its action buttons use `type="button"`, so they do not submit a surrounding form.
-An empty or failed image shows a placeholder. Changing `src` retries the preview, including after an earlier image failed to load. Removal calls `onRemove`; update `src` after your application removes the image.
+An empty or failed image shows a placeholder. Changing `src` retries the preview, including after an earlier image failed to load. Removal calls `onRemove`; update `src` after your application removes the image. The application owns local preview URLs and revokes worker-created object URLs when they are no longer needed. The renderer owns cleanup of its host preview URLs.
+
+## Root and file input props
+
+`className`, `style`, and `ref` apply to the root div. The default root ref receives an `HTMLDivElement`; use `inputRef` for the hidden file input. Use `render={<div ... />}` to supply native root attributes or event handlers. Keep that root non-interactive, since the module already contains buttons. `dir` applies to both the root and file input; use `dir="rtl"` for right-to-left layout.
+
+Native file input attributes are top-level props, including `accept`, `capture`, `name`, `id`, `title`, `form`, `required`, accessible attributes, data attributes, and event handlers. They apply to the hidden input. `inputRef` receives its `HTMLInputElement`. The control always uses `type="file"`, accepts one file, and resets its value after every selection. `children`, `dangerouslySetInnerHTML`, `type`, `multiple`, `value`, `defaultValue`, and `hidden` cannot be customized.
+
+Native `required` validation still sees an empty input after selection because the input resets. Validate completed uploads in your application.
+
+`onChange` receives the native change event while the input still contains the selected file. The input then resets before `onFileSelect` fires. Native event props follow React's input contract. `onAbort` is the upload abort action.
## Uploading and disabled states
`isUploading` marks the root busy and makes selection and removal unavailable. Controls that were available stay focusable, so keyboard focus is not lost when an upload starts. Supply `onAbort` to replace Upload with Abort during an upload. Abort works before the first image URL exists. The application owns cancellation and sets `isUploading` back to `false` when the upload ends.
-`disabled` disables every action. Selection requires `onUpload`. Removal requires both `onRemove` and a nonempty `src`.
+`disabled` disables every action. Selection requires `onFileSelect`. Removal requires both `onRemove` and a nonempty `src`.
<StoryEmbed
storyId="ui-input-imageinput--uploading"
@@ -55,7 +66,7 @@ An empty or failed image shows a placeholder. Changing `src` retries the preview
## Labels, instructions, and errors
-Supply localized `uploadLabel`, `removeLabel`, and `abortLabel` strings. They default to `Upload`, `Remove`, and `Abort`. The upload label also names the preview button.
+Supply localized `uploadLabel`, `removeLabel`, and `abortLabel` strings. They default to `Upload`, `Remove`, and `Abort`. The upload label also names the preview button and the hidden file input. Native accessible attributes can provide a different file input name. `aria-describedby` also describes the selection buttons and combines with the application's helper and error text.
`helperText` and `errorMessage` belong to the application. Both describe the selection controls, and errors are announced as alerts. There are no built-in file limits or product instructions.
@@ -65,7 +76,24 @@ Supply localized `uploadLabel`, `removeLabel`, and `abortLabel` strings. They de
height={200}
/>
-Native div attributes, `className`, `style`, and `ref` apply to the root. Use `render` for root composition and keep that root non-interactive, since the module already contains buttons. Use `dir="rtl"` for right-to-left layout.
+## Migration
+
+Replace `onUpload` with `onFileSelect`. Keep `accept` as a top-level prop. The callback still receives a `File`; keep existing validation and upload code in your application.
+
+```tsx
+import { ImageInput } from 'twenty-ui/components/input';
+
+export const WorkspaceImageSelector = ({
+ uploadImage,
+}: {
+ uploadImage: (file: File) => void;
+}) => (
+ <ImageInput
+ onFileSelect={uploadImage}
+ accept="image/png, image/jpeg"
+ />
+);
+```
## Props
diff --git a/packages/twenty-docs/ui/components/overview.mdx b/packages/twenty-docs/ui/components/overview.mdx
index 26c4e7dc196..984dc713c23 100644
--- a/packages/twenty-docs/ui/components/overview.mdx
+++ b/packages/twenty-docs/ui/components/overview.mdx
@@ -22,7 +22,7 @@ Import from `twenty-ui/components/input`.
| [SearchInput](/ui/components/input/search-input) | Search text and optional filter controls. |
| [CountrySelect](/ui/components/input/country-select) | Searchable country choices, flags, and an explicit empty selection. |
| [CurrencyPicker](/ui/components/input/currency-picker) | Searchable currency choices with explicit formatting. |
-| [ImageInput](/ui/components/input/image-input) | Image selection, validation, and preview. |
+| [ImageInput](/ui/components/input/image-input) | Image selection and preview with caller-owned uploads. |
## Navigation
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
index 9ff06e7a5e5..bc5a93c0835 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/README.md
@@ -122,6 +122,13 @@ through a narrow worker TreeWalker that supports SHOW_TEXT, nextNode and
currentNode without callback filters; document Selection and DOM Range are
outside this scope.
+`ImageInput` calls `onFileSelect` when a file is selected. Applications own
+validation, uploads, progress, cancellation, and supplied preview URLs. Native
+chooser activation and readable `File` contents in React and Preact still depend
+on [C08 support](https://github.com/twentyhq/twenty/pull/27588).
+`userEvent.upload` checks selection handling and does not prove native chooser
+activation.
+
## Dialog policy
Direct app-owned `Dialog`/`AlertDialog` modality and native browser dialog/popover activation are prohibited in front components. Their standalone Twenty UI APIs have dedicated unit and browser stories. Front components use SDK `openCommandConfirmationModal`, whose structured title, subtitle and confirm-button options are rendered by the host. The Dialog fixture checks the confirmation request. Result handling and actual host modal focus, restoration, dismissal and teardown acceptance remain part of the renderer integration work. No direct Dialog or AlertDialog gallery fixture is retained as a compatibility target.
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-image-input.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-image-input.front-component.tsx
index 07d33c1fc45..b5c117b3701 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-image-input.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-image-input.front-component.tsx
@@ -22,8 +22,8 @@ const ImageInputExample = () => {
return (
<TwentyUiGalleryCard title="ImageInput">
<ImageInput
- role="group"
- aria-label="Profile image"
+ accept="image/png, image/jpeg"
+ render={<div role="group" aria-label="Profile image" />}
src={src}
isUploading={isUploading}
disabled={disabled}
@@ -32,7 +32,7 @@ const ImageInputExample = () => {
uploadLabel="Choose profile image"
removeLabel="Remove profile image"
abortLabel="Cancel profile upload"
- onUpload={(file) => {
+ onFileSelect={(file) => {
setUploads((count) => count + 1);
setSelectedFile(`${file.name}; ${file.type}; ${file.size} bytes`);
}}
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/imageInputTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/imageInputTest.ts
index 25ba56bc4af..9c058f409fd 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/imageInputTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/imageInputTest.ts
@@ -121,7 +121,7 @@ export const imageInputTest: TwentyUiGalleryPlayFunction = async ({
throw new Error('ImageInput must render a native file input');
}
- await expect(fileInput).toHaveAttribute('accept', 'image/*');
+ await expect(fileInput).toHaveAttribute('accept', 'image/png, image/jpeg');
await expect(fileInput).not.toBeVisible();
await userEvent.upload(
fileInput,
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsImageInput.tsx b/packages/twenty-front/src/modules/settings/components/SettingsImageInput.tsx
index 818e288f724..bf4baed181b 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsImageInput.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsImageInput.tsx
@@ -5,7 +5,7 @@ import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
type SettingsImageInputProps = Pick<
ImageInputProps,
- | 'onUpload'
+ | 'onFileSelect'
| 'onRemove'
| 'onAbort'
| 'isUploading'
@@ -17,7 +17,7 @@ type SettingsImageInputProps = Pick<
export const SettingsImageInput = ({
picture,
- onUpload,
+ onFileSelect,
onRemove,
onAbort,
isUploading,
@@ -28,7 +28,7 @@ export const SettingsImageInput = ({
return (
<ImageInput
- onUpload={onUpload}
+ onFileSelect={onFileSelect}
onRemove={onRemove}
onAbort={onAbort}
isUploading={isUploading}
diff --git a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsImageInput.stories.tsx b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsImageInput.stories.tsx
index 6a52e75676f..070e6517a3e 100644
--- a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsImageInput.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsImageInput.stories.tsx
@@ -9,7 +9,7 @@ const meta: Meta<typeof SettingsImageInput> = {
title: 'Modules/Settings/SettingsImageInput',
component: SettingsImageInput,
decorators: [ComponentDecorator],
- args: { onUpload: fn(), onRemove: fn() },
+ args: { onFileSelect: fn(), onRemove: fn() },
};
export default meta;
diff --git a/packages/twenty-front/src/modules/settings/workspace-member/components/WorkspaceMemberPictureUploader.tsx b/packages/twenty-front/src/modules/settings/workspace-member/components/WorkspaceMemberPictureUploader.tsx
index cf3d9023d3c..911455911e5 100644
--- a/packages/twenty-front/src/modules/settings/workspace-member/components/WorkspaceMemberPictureUploader.tsx
+++ b/packages/twenty-front/src/modules/settings/workspace-member/components/WorkspaceMemberPictureUploader.tsx
@@ -146,7 +146,7 @@ export const WorkspaceMemberPictureUploader = ({
return (
<SettingsImageInput
picture={displayAvatarUrl}
- onUpload={handleUpload}
+ onFileSelect={handleUpload}
onRemove={handleRemove}
onAbort={isUploading ? handleAbort : undefined}
isUploading={isUploading || isRemoving}
diff --git a/packages/twenty-front/src/modules/settings/workspace/components/WorkspaceLogoUploader.tsx b/packages/twenty-front/src/modules/settings/workspace/components/WorkspaceLogoUploader.tsx
index 041e65b9112..baf72182294 100644
--- a/packages/twenty-front/src/modules/settings/workspace/components/WorkspaceLogoUploader.tsx
+++ b/packages/twenty-front/src/modules/settings/workspace/components/WorkspaceLogoUploader.tsx
@@ -85,7 +85,7 @@ export const WorkspaceLogoUploader = () => {
return (
<SettingsImageInput
picture={currentWorkspace?.logo}
- onUpload={onUpload}
+ onFileSelect={onUpload}
onRemove={onRemove}
isUploading={isUploading || isRemoving}
errorMessage={errorMessage}
diff --git a/packages/twenty-ui/docs/imageInputPropDescriptions.ts b/packages/twenty-ui/docs/imageInputPropDescriptions.ts
index 1cb9ab377b1..ce6cb878a0f 100644
--- a/packages/twenty-ui/docs/imageInputPropDescriptions.ts
+++ b/packages/twenty-ui/docs/imageInputPropDescriptions.ts
@@ -2,8 +2,8 @@ import { type ImageInputProps } from '../src/components/input/ImageInput/types/I
export const IMAGE_INPUT_PROP_DESCRIPTIONS = {
src: 'Resolved image URL. Empty or failed images show the image placeholder.',
- onUpload:
- 'Receives the selected File. Empty and canceled selections do not call it. Selection is disabled when omitted.',
+ onFileSelect:
+ 'Fires when a file is selected and receives its usable File after the input resets. Empty and canceled selections do not call it. Selection is disabled when omitted. The caller owns validation and uploading.',
onRemove:
'Requests removal of the current image. Removal is disabled without this callback or a nonempty src.',
onAbort:
@@ -15,14 +15,30 @@ export const IMAGE_INPUT_PROP_DESCRIPTIONS = {
'Application instructions, associated with the selection controls.',
errorMessage:
'Application error, displayed as an alert and associated with the selection controls.',
- uploadLabel: 'Label for the preview and Upload action.',
+ uploadLabel: 'Label for the preview, Upload action, and hidden file input.',
removeLabel: 'Label for the Remove action.',
abortLabel: 'Label for the Abort action.',
accept:
- 'Native file picker filter. Defaults to image/*. The application validates the selected file.',
+ 'Native file picker filter. Defaults to image/*. The caller validates allowed formats.',
+ capture: 'Native device capture hint for the file picker.',
+ name: 'Native name of the hidden file input.',
+ id: 'Native identifier of the hidden file input.',
+ title: 'Native title of the hidden file input.',
+ form: 'Native form identifier associated with the hidden file input.',
+ required:
+ 'Native file input requirement. The input resets after selection, so the caller validates completed uploads.',
+ 'aria-label':
+ 'Accessible name of the hidden file input. Defaults to uploadLabel.',
+ 'aria-labelledby': 'Accessible name reference for the hidden file input.',
+ 'aria-describedby':
+ 'Accessible description references for the hidden file input and selection buttons, combined with helperText and errorMessage.',
+ inputRef: 'Ref to the hidden single-file HTMLInputElement.',
+ onChange:
+ 'Native file input change event, fired while the selected file is present and before the input resets. The input does not retain a file for form submission.',
+ dir: 'Text direction applied to both the root and hidden file input.',
render:
- 'Custom root element or render function. Keep a non-interactive root.',
- ref: 'Ref to the root element.',
+ 'Custom root element or render function. Supply root native attributes here and keep a non-interactive root.',
+ ref: 'Ref to the root div element.',
className: 'Class applied to the root element.',
style: 'Inline style applied to the root element.',
} satisfies Partial<Record<keyof ImageInputProps, string>>;
diff --git a/packages/twenty-ui/docs/label-ownership.md b/packages/twenty-ui/docs/label-ownership.md
index 49fea8a1aa4..c2188d4b796 100644
--- a/packages/twenty-ui/docs/label-ownership.md
+++ b/packages/twenty-ui/docs/label-ownership.md
@@ -14,7 +14,7 @@ This covers production exports under components, primitives, and icons, includin
| SearchInput | Caller-owned placeholder and native accessible name; `filterButtonAriaLabel` defaults to `Filter`. Referenced labels take precedence over explicit labels and placeholder fallback. |
| CountrySelect | `searchLabel`, `noCountryLabel`, and `noResultsLabel` default to `Search`, `No country`, and `No results`. The search label names the search input and is its placeholder. Applications supply `label` or native accessible names and the country labels, including translated strings. |
| PhoneCountryPicker | Callers supply country labels and the trigger accessible name. The popup takes the trigger name unless a `Dropdown.Title` or an explicit `Dropdown.Content` label names it, and the selected country label describes the trigger. `searchLabel` defaults to `Search`; `emptyLabel` defaults to `No results`. Calling codes are supplied as data without a leading plus sign. |
-| ImageInput | `uploadLabel`, `removeLabel`, and `abortLabel` default to `Upload`, `Remove`, and `Abort`. The upload label names the visible upload button and the preview button. Applications supply `helperText` and `errorMessage`, including validation instructions and translated strings. |
+| ImageInput | `uploadLabel`, `removeLabel`, and `abortLabel` default to `Upload`, `Remove`, and `Abort`. The upload label names the visible upload button, preview button, and hidden file input. Native accessible attributes can supply names and descriptions for the file input. Applications supply `helperText` and `errorMessage`, including validation instructions and translated strings. |
| Toast and Toaster | Children, description and action slots, `iconLabel`, `cancelLabel` (default `Cancel`), and `closeLabel` (default `Close`). Toaster accepts native accessible attributes over its `Notifications` region default. |
| Chip and Avatar | Chip content, translated fallbacks and interactive accessible names belong to the caller. Missing children add no label. Avatar's image and default fallback are decorative. `name` supplies the visual initial and colors. Explicit `imageProps.alt` labels the image and default fallback; caller fallback semantics take precedence. Composed buttons and links own their labels and interaction handlers. |
| JsonTree | Callers supply empty string, array, and object labels and expanded/collapsed arrow names. JSON booleans, null, property names, and values are data. |
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index c29347c44db..3e632df3cd4 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -12165,7 +12165,35 @@
"type": "string",
"required": false,
"defaultValue": "image/*",
- "description": "Native file picker filter. Defaults to image/*. The application validates the selected file."
+ "description": "Native file picker filter. Defaults to image/*. The caller validates allowed formats."
+ },
+ {
+ "name": "aria-describedby",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Accessible description references for the hidden file input and selection buttons, combined with helperText and errorMessage."
+ },
+ {
+ "name": "aria-label",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Accessible name of the hidden file input. Defaults to uploadLabel."
+ },
+ {
+ "name": "aria-labelledby",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Accessible name reference for the hidden file input."
+ },
+ {
+ "name": "capture",
+ "type": "boolean | \"user\" | \"environment\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native device capture hint for the file picker."
},
{
"name": "className",
@@ -12174,6 +12202,13 @@
"defaultValue": null,
"description": "Class applied to the root element."
},
+ {
+ "name": "dir",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Text direction applied to both the root and hidden file input."
+ },
{
"name": "disabled",
"type": "boolean",
@@ -12188,6 +12223,13 @@
"defaultValue": null,
"description": "Application error, displayed as an alert and associated with the selection controls."
},
+ {
+ "name": "form",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native form identifier associated with the hidden file input."
+ },
{
"name": "helperText",
"type": "string",
@@ -12195,6 +12237,20 @@
"defaultValue": null,
"description": "Application instructions, associated with the selection controls."
},
+ {
+ "name": "id",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native identifier of the hidden file input."
+ },
+ {
+ "name": "inputRef",
+ "type": "Ref<HTMLInputElement>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Ref to the hidden single-file HTMLInputElement."
+ },
{
"name": "isUploading",
"type": "boolean",
@@ -12202,6 +12258,13 @@
"defaultValue": "false",
"description": "Marks the module busy. Selection and removal controls that would otherwise be enabled stay focusable but unavailable. Shows Abort when onAbort is supplied."
},
+ {
+ "name": "name",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native name of the hidden file input."
+ },
{
"name": "onAbort",
"type": "(() => void)",
@@ -12210,25 +12273,32 @@
"description": "Shows an abort action while uploading. It can cancel the first upload before a src exists."
},
{
- "name": "onRemove",
- "type": "(() => void)",
+ "name": "onChange",
+ "type": "ChangeEventHandler<HTMLInputElement, HTMLInputElement>",
"required": false,
"defaultValue": null,
- "description": "Requests removal of the current image. Removal is disabled without this callback or a nonempty src."
+ "description": "Native file input change event, fired while the selected file is present and before the input resets. The input does not retain a file for form submission."
},
{
- "name": "onUpload",
+ "name": "onFileSelect",
"type": "((file: File) => void)",
"required": false,
"defaultValue": null,
- "description": "Receives the selected File. Empty and canceled selections do not call it. Selection is disabled when omitted."
+ "description": "Fires when a file is selected and receives its usable File after the input resets. Empty and canceled selections do not call it. Selection is disabled when omitted. The caller owns validation and uploading."
+ },
+ {
+ "name": "onRemove",
+ "type": "(() => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Requests removal of the current image. Removal is disabled without this callback or a nonempty src."
},
{
"name": "ref",
"type": "Ref<HTMLDivElement>",
"required": false,
"defaultValue": null,
- "description": "Ref to the root element."
+ "description": "Ref to the root div element."
},
{
"name": "removeLabel",
@@ -12242,7 +12312,14 @@
"type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",
"required": false,
"defaultValue": null,
- "description": "Custom root element or render function. Keep a non-interactive root."
+ "description": "Custom root element or render function. Supply root native attributes here and keep a non-interactive root."
+ },
+ {
+ "name": "required",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native file input requirement. The input resets after selection, so the caller validates completed uploads."
},
{
"name": "src",
@@ -12258,12 +12335,19 @@
"defaultValue": null,
"description": "Inline style applied to the root element."
},
+ {
+ "name": "title",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native title of the hidden file input."
+ },
{
"name": "uploadLabel",
"type": "string",
"required": false,
"defaultValue": "Upload",
- "description": "Label for the preview and Upload action."
+ "description": "Label for the preview, Upload action, and hidden file input."
}
]
},
diff --git a/packages/twenty-ui/src/components/input/ImageInput/ImageInput.tsx b/packages/twenty-ui/src/components/input/ImageInput/ImageInput.tsx
index eebc9a30a52..85ae970344f 100644
--- a/packages/twenty-ui/src/components/input/ImageInput/ImageInput.tsx
+++ b/packages/twenty-ui/src/components/input/ImageInput/ImageInput.tsx
@@ -1,4 +1,5 @@
import { useRender } from '@base-ui/react/use-render';
+import { useMergedRefs } from '@base-ui/utils/useMergedRefs';
import { isNonEmptyString } from '@sniptt/guards';
import { clsx } from 'clsx';
import { type ChangeEvent, useId, useRef } from 'react';
@@ -11,9 +12,11 @@ import styles from './ImageInput.module.scss';
import { ImageInputPreview } from './internal/ImageInputPreview';
import { type ImageInputProps } from './types/ImageInputProps';
+const DEFAULT_IMAGE_ACCEPT = 'image/*';
+
export const ImageInput = ({
src,
- onUpload,
+ onFileSelect,
onRemove,
onAbort,
disabled = false,
@@ -23,26 +26,36 @@ export const ImageInput = ({
uploadLabel = 'Upload',
removeLabel = 'Remove',
abortLabel = 'Abort',
- accept = 'image/*',
+ accept = DEFAULT_IMAGE_ACCEPT,
+ inputRef,
+ onChange,
+ 'aria-describedby': ariaDescribedBy,
className,
+ style,
+ dir,
render,
ref,
- ...props
+ ...inputProps
}: ImageInputProps) => {
const fileInputRef = useRef<HTMLInputElement>(null);
+ const mergedFileInputRef = useMergedRefs(fileInputRef, inputRef);
const descriptionId = useId();
const helperTextId = `${descriptionId}-helper`;
const errorMessageId = `${descriptionId}-error`;
const hasPicture = isNonEmptyString(src);
const hasHelperText = isNonEmptyString(helperText);
const hasErrorMessage = isNonEmptyString(errorMessage);
- const isSelectionUnavailable = disabled || !isDefined(onUpload);
+ const isSelectionUnavailable = disabled || !isDefined(onFileSelect);
const isRemovalUnavailable = disabled || !hasPicture || !isDefined(onRemove);
const isUploadDisabled = isSelectionUnavailable || isUploading;
const isRemoveDisabled = isRemovalUnavailable || isUploading;
const showAbort = isUploading && isDefined(onAbort);
const describedBy =
- [hasHelperText && helperTextId, hasErrorMessage && errorMessageId]
+ [
+ ariaDescribedBy,
+ hasHelperText && helperTextId,
+ hasErrorMessage && errorMessageId,
+ ]
.filter(isNonEmptyString)
.join(' ') || undefined;
@@ -57,22 +70,27 @@ export const ImageInput = ({
const handleFileChange = (event: ChangeEvent<HTMLInputElement>) => {
const file = event.currentTarget.files?.[0];
- event.currentTarget.value = '';
+ try {
+ onChange?.(event);
+ } finally {
+ event.currentTarget.value = '';
+ }
if (isUploadDisabled || !isDefined(file)) {
return;
}
- onUpload?.(file);
+ onFileSelect?.(file);
};
return useRender({
render,
ref,
props: {
- ...props,
className: clsx(styles.root, className),
- 'aria-busy': isUploading || props['aria-busy'],
+ style,
+ dir,
+ 'aria-busy': isUploading || inputProps['aria-busy'],
children: (
<>
<button
@@ -89,11 +107,20 @@ export const ImageInput = ({
<div className={styles.content}>
<div className={styles.actions}>
<input
- ref={fileInputRef}
+ aria-label={uploadLabel}
+ {...inputProps}
+ ref={mergedFileInputRef}
className={styles.fileInput}
+ dir={dir}
+ children={undefined}
+ dangerouslySetInnerHTML={undefined}
type="file"
+ multiple={false}
+ value={undefined}
+ defaultValue={undefined}
accept={accept}
disabled={isUploadDisabled}
+ aria-describedby={describedBy}
hidden
onChange={handleFileChange}
/>
diff --git a/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.interactions.stories.tsx b/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.interactions.stories.tsx
index 54c4b677b33..6127b6a4cef 100644
--- a/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.interactions.stories.tsx
+++ b/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.interactions.stories.tsx
@@ -27,7 +27,7 @@ const meta: Meta<typeof ImageInput> = {
tags: ['!autodocs'],
decorators: [ComponentDecorator],
parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },
- args: { onUpload: fn(), onRemove: fn(), onAbort: fn() },
+ args: { onFileSelect: fn(), onRemove: fn(), onAbort: fn() },
};
export default meta;
@@ -74,7 +74,7 @@ export const NativeButtonsInForm: Story = {
await userEvent.keyboard('{Enter}');
await expect(args.onRemove).toHaveBeenCalledTimes(2);
await expect(onSubmit).not.toHaveBeenCalled();
- await expect(args.onUpload).not.toHaveBeenCalled();
+ await expect(args.onFileSelect).not.toHaveBeenCalled();
await userEvent.click(
canvas.getByRole('button', { name: 'Save workspace' }),
);
@@ -96,15 +96,15 @@ export const FileSelectionAndRetry: Story = {
await expect(fileInput).toHaveAttribute('accept', 'image/png');
await expect(fileInput).not.toHaveAttribute('multiple');
await userEvent.upload(fileInput, file);
- await expect(args.onUpload).toHaveBeenCalledOnce();
- await expect(args.onUpload).toHaveBeenCalledWith(file);
+ await expect(args.onFileSelect).toHaveBeenCalledOnce();
+ await expect(args.onFileSelect).toHaveBeenCalledWith(file);
await expect(fileInput).toHaveValue('');
await userEvent.upload(fileInput, file);
- await expect(args.onUpload).toHaveBeenCalledTimes(2);
- await expect(args.onUpload).toHaveBeenLastCalledWith(file);
+ await expect(args.onFileSelect).toHaveBeenCalledTimes(2);
+ await expect(args.onFileSelect).toHaveBeenLastCalledWith(file);
fileInput.dispatchEvent(new Event('cancel', { bubbles: true }));
fileInput.dispatchEvent(new Event('change', { bubbles: true }));
- await expect(args.onUpload).toHaveBeenCalledTimes(2);
+ await expect(args.onFileSelect).toHaveBeenCalledTimes(2);
},
};
@@ -123,7 +123,7 @@ export const Disabled: Story = {
}
await expect(fileInput).toBeDisabled();
await expect(onFilePicker).not.toHaveBeenCalled();
- await expect(args.onUpload).not.toHaveBeenCalled();
+ await expect(args.onFileSelect).not.toHaveBeenCalled();
await expect(args.onRemove).not.toHaveBeenCalled();
} finally {
fileInput.removeEventListener('click', onFilePicker);
@@ -146,7 +146,7 @@ export const UploadingWithoutAbort: Story = {
await expect(
canvas.queryByRole('button', { name: 'Abort' }),
).not.toBeInTheDocument();
- await expect(args.onUpload).not.toHaveBeenCalled();
+ await expect(args.onFileSelect).not.toHaveBeenCalled();
await expect(args.onRemove).not.toHaveBeenCalled();
},
};
@@ -165,7 +165,7 @@ export const AbortFirstUpload: Story = {
abortButton.focus();
await userEvent.keyboard('{Enter}');
await expect(args.onAbort).toHaveBeenCalledOnce();
- await expect(args.onUpload).not.toHaveBeenCalled();
+ await expect(args.onFileSelect).not.toHaveBeenCalled();
await expect(args.onRemove).not.toHaveBeenCalled();
},
};
diff --git a/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.stories.tsx b/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.stories.tsx
index b3b2122edd3..5cc4ec8096e 100644
--- a/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.stories.tsx
+++ b/packages/twenty-ui/src/components/input/ImageInput/__stories__/ImageInput.stories.tsx
@@ -10,7 +10,7 @@ const meta: Meta<typeof ImageInput> = {
id: 'ui-input-imageinput',
title: 'UI/Components/Input/ImageInput',
component: ImageInput,
- args: { onUpload: fn(), onRemove: fn() },
+ args: { onFileSelect: fn(), onRemove: fn() },
decorators: [ComponentDecorator],
parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },
};
diff --git a/packages/twenty-ui/src/components/input/ImageInput/__tests__/ImageInput.test.tsx b/packages/twenty-ui/src/components/input/ImageInput/__tests__/ImageInput.test.tsx
index 9117d045c4f..175a650b0ad 100644
--- a/packages/twenty-ui/src/components/input/ImageInput/__tests__/ImageInput.test.tsx
+++ b/packages/twenty-ui/src/components/input/ImageInput/__tests__/ImageInput.test.tsx
@@ -1,9 +1,366 @@
-import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
+import { fireEvent, render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { type ChangeEvent, createRef } from 'react';
+import { describe, expect, expectTypeOf, it, vi } from 'vitest';
+
+import { type ImageInputProps } from '@ui/components/input';
import { ImageInput } from '../ImageInput';
-runComponentConformance({
- name: 'ImageInput',
- element: <ImageInput />,
- refInstanceOf: HTMLDivElement,
+const readFileText = (file: File) =>
+ new Promise<string | ArrayBuffer | null>((resolve, reject) => {
+ const reader = new FileReader();
+
+ reader.addEventListener('load', () => resolve(reader.result));
+ reader.addEventListener('error', () => reject(reader.error));
+ reader.readAsText(file);
+ });
+
+describe('ImageInput', () => {
+ it('excludes obsolete callbacks and component-owned native input options from its public types', () => {
+ expectTypeOf<
+ Extract<
+ keyof ImageInputProps,
+ | 'onUpload'
+ | 'fileInputProps'
+ | 'children'
+ | 'dangerouslySetInnerHTML'
+ | 'type'
+ | 'multiple'
+ | 'value'
+ | 'defaultValue'
+ | 'hidden'
+ >
+ >().toEqualTypeOf<never>();
+ expectTypeOf<ImageInputProps['accept']>().toEqualTypeOf<
+ string | undefined
+ >();
+ });
+
+ it('forwards separate native props and refs to the root and file control', async () => {
+ const user = userEvent.setup();
+ const rootRef = createRef<HTMLDivElement>();
+ const cleanupFileInputRef = vi.fn();
+ const fileInputRef = vi.fn(
+ (_fileInput: HTMLInputElement | null) => cleanupFileInputRef,
+ );
+ const onRootChange = vi.fn(
+ (event: ChangeEvent<HTMLDivElement>) => event.currentTarget,
+ );
+ const onFileChange = vi.fn(
+ (event: ChangeEvent<HTMLInputElement>) => event.currentTarget,
+ );
+ const { unmount } = render(
+ <>
+ <form aria-label="Workspace" id="workspace-form" />
+ <label htmlFor="image-file">Workspace image file</label>
+ <ImageInput
+ ref={rootRef}
+ render={
+ <div
+ id="image-root"
+ title="Workspace image"
+ onChange={onRootChange}
+ />
+ }
+ className="custom-root"
+ style={{ padding: '4px' }}
+ dir="rtl"
+ inputRef={fileInputRef}
+ id="image-file"
+ name="workspaceImage"
+ form="workspace-form"
+ accept="image/png"
+ capture="environment"
+ required
+ onChange={onFileChange}
+ onFileSelect={vi.fn()}
+ />
+ </>,
+ );
+ const fileInput = screen.getByLabelText<HTMLInputElement>('Upload', {
+ selector: 'input',
+ });
+ const file = new File(['image'], 'workspace.png', { type: 'image/png' });
+
+ expect(rootRef.current).toBeInstanceOf(HTMLDivElement);
+ expect(rootRef.current).toHaveAttribute('id', 'image-root');
+ expect(rootRef.current).toHaveAttribute('title', 'Workspace image');
+ expect(rootRef.current).toHaveClass('custom-root');
+ expect(rootRef.current).toHaveStyle({ padding: '4px' });
+ expect(rootRef.current).toHaveAttribute('dir', 'rtl');
+ expect(fileInputRef).toHaveBeenCalledWith(fileInput);
+ expect(fileInput).toHaveAttribute('id', 'image-file');
+ expect(fileInput).toHaveAttribute('name', 'workspaceImage');
+ expect(fileInput.form).toBe(
+ screen.getByRole('form', { name: 'Workspace' }),
+ );
+ expect(fileInput).toHaveAttribute('type', 'file');
+ expect(fileInput).toHaveAttribute('accept', 'image/png');
+ expect(fileInput).toHaveAttribute('capture', 'environment');
+ expect(fileInput).toBeRequired();
+ expect(fileInput).toHaveAttribute('dir', 'rtl');
+ expect(fileInput).not.toHaveClass('custom-root');
+ expect(fileInput).not.toHaveStyle({ padding: '4px' });
+ expect(
+ screen.getByLabelText('Workspace image file', { selector: 'input' }),
+ ).toBe(fileInput);
+ expect(fileInput).not.toHaveAttribute('multiple');
+ expect(fileInput).not.toBeVisible();
+
+ await user.upload(fileInput, file);
+
+ expect(onRootChange).toHaveReturnedWith(rootRef.current);
+ expect(onFileChange).toHaveReturnedWith(fileInput);
+
+ unmount();
+
+ expect(rootRef.current).toBeNull();
+ expect(cleanupFileInputRef).toHaveBeenCalledOnce();
+ });
+
+ it('composes root props and refs through a render function', () => {
+ const rootRef = createRef<HTMLDivElement>();
+
+ render(
+ <ImageInput
+ ref={rootRef}
+ id="workspace-file"
+ className="custom-root"
+ style={{ padding: '4px' }}
+ render={(rootProps) => <div {...rootProps} data-testid="image-root" />}
+ />,
+ );
+
+ const root = screen.getByTestId('image-root');
+
+ expect(rootRef.current).toBe(root);
+ expect(root).toHaveClass('custom-root');
+ expect(root).toHaveStyle({ padding: '4px' });
+ expect(root).not.toHaveAttribute('id');
+ expect(
+ screen.getByLabelText('Upload', { selector: 'input' }),
+ ).toHaveAttribute('id', 'workspace-file');
+ });
+
+ it('exposes the selected file to the native event before reset and supports repeated selection', async () => {
+ const user = userEvent.setup();
+ const onFileChange = vi.fn((event: ChangeEvent<HTMLInputElement>) => ({
+ file: event.currentTarget.files?.[0],
+ value: event.currentTarget.value,
+ }));
+ const onFileSelect = vi.fn(readFileText);
+
+ render(<ImageInput onFileSelect={onFileSelect} onChange={onFileChange} />);
+
+ const fileInput = screen.getByLabelText<HTMLInputElement>('Upload', {
+ selector: 'input',
+ });
+ const file = new File(['workspace image'], 'workspace.png', {
+ type: 'image/png',
+ lastModified: 123,
+ });
+
+ await user.upload(fileInput, file);
+
+ expect(onFileChange).toHaveReturnedWith({
+ file,
+ value: 'C:\\fakepath\\workspace.png',
+ });
+ expect(onFileChange).toHaveBeenCalledBefore(onFileSelect);
+ expect(onFileSelect).toHaveBeenCalledWith(file);
+ expect(fileInput).toHaveValue('');
+ await expect(onFileSelect.mock.results[0]?.value).resolves.toBe(
+ 'workspace image',
+ );
+
+ await user.upload(fileInput, file);
+
+ expect(onFileSelect).toHaveBeenCalledTimes(2);
+ expect(onFileSelect).toHaveBeenLastCalledWith(file);
+ expect(fileInput).toHaveValue('');
+ await expect(onFileSelect.mock.results[1]?.value).resolves.toBe(
+ 'workspace image',
+ );
+ });
+
+ it('keeps single-file selection when a broader props object enables multiple files', async () => {
+ const user = userEvent.setup();
+ const onFileSelect = vi.fn();
+ const onFileChange = vi.fn(
+ (event: ChangeEvent<HTMLInputElement>) =>
+ event.currentTarget.files?.length,
+ );
+ const broaderInputProps = {
+ accept: 'image/png',
+ multiple: true,
+ onChange: onFileChange,
+ };
+
+ render(<ImageInput {...broaderInputProps} onFileSelect={onFileSelect} />);
+
+ const fileInput = screen.getByLabelText<HTMLInputElement>('Upload', {
+ selector: 'input',
+ });
+ const firstFile = new File(['first'], 'first.png', { type: 'image/png' });
+ const secondFile = new File(['second'], 'second.png', {
+ type: 'image/png',
+ });
+
+ expect(fileInput).not.toHaveAttribute('multiple');
+
+ await user.upload(fileInput, [firstFile, secondFile]);
+
+ expect(onFileChange).toHaveReturnedWith(1);
+ expect(onFileSelect).toHaveBeenCalledOnce();
+ expect(onFileSelect).toHaveBeenCalledWith(firstFile);
+ expect(fileInput).toHaveValue('');
+ });
+
+ it('keeps a hidden empty file control when broader props include component-owned options', async () => {
+ const user = userEvent.setup();
+ const onFileSelect = vi.fn();
+ const broaderInputProps = {
+ accept: 'image/png',
+ children: <span>Unexpected input content</span>,
+ dangerouslySetInnerHTML: { __html: 'Unexpected input markup' },
+ type: 'text',
+ hidden: false,
+ value: 'controlled-file.png',
+ defaultValue: 'initial-file.png',
+ };
+
+ render(<ImageInput {...broaderInputProps} onFileSelect={onFileSelect} />);
+
+ const fileInput = screen.getByLabelText<HTMLInputElement>('Upload', {
+ selector: 'input',
+ });
+ const file = new File(['image'], 'workspace.png', { type: 'image/png' });
+
+ expect(fileInput).toHaveAttribute('type', 'file');
+ expect(fileInput).toHaveAttribute('hidden');
+ expect(fileInput).toHaveValue('');
+ expect(
+ screen.queryByText('Unexpected input content'),
+ ).not.toBeInTheDocument();
+
+ await user.upload(fileInput, file);
+
+ expect(onFileSelect).toHaveBeenCalledWith(file);
+ expect(fileInput).toHaveValue('');
+ });
+
+ it('does not select a file after cancellation or an empty change event', () => {
+ const onFileSelect = vi.fn();
+ const onFileChange = vi.fn();
+
+ render(<ImageInput onFileSelect={onFileSelect} onChange={onFileChange} />);
+
+ const fileInput = screen.getByLabelText('Upload', { selector: 'input' });
+
+ fireEvent(fileInput, new Event('cancel', { bubbles: true }));
+ fireEvent.change(fileInput);
+
+ expect(onFileChange).toHaveBeenCalledOnce();
+ expect(onFileSelect).not.toHaveBeenCalled();
+ expect(fileInput).toHaveValue('');
+ });
+
+ it.each([
+ { state: 'disabled', props: { disabled: true } },
+ { state: 'uploading', props: { isUploading: true } },
+ ])('ignores file selection while $state', async ({ props }) => {
+ const user = userEvent.setup();
+ const onFileSelect = vi.fn();
+
+ render(<ImageInput {...props} onFileSelect={onFileSelect} />);
+
+ const fileInput = screen.getByLabelText('Upload', { selector: 'input' });
+ const file = new File(['image'], 'workspace.png', { type: 'image/png' });
+
+ expect(fileInput).toBeDisabled();
+
+ await user.upload(fileInput, file);
+ fireEvent.change(fileInput, { target: { files: [file] } });
+
+ expect(onFileSelect).not.toHaveBeenCalled();
+ expect(fileInput).toHaveValue('');
+ });
+
+ it('keeps keyboard removal usable when no file selection handler is provided', async () => {
+ const user = userEvent.setup();
+ const onRemove = vi.fn();
+
+ render(<ImageInput src="workspace.png" onRemove={onRemove} />);
+
+ for (const button of screen.getAllByRole('button', { name: 'Upload' })) {
+ expect(button).toBeDisabled();
+ }
+
+ expect(
+ screen.getByLabelText('Upload', { selector: 'input' }),
+ ).toBeDisabled();
+
+ await user.tab();
+
+ expect(screen.getByRole('button', { name: 'Remove' })).toHaveFocus();
+
+ await user.keyboard('{Enter}');
+
+ expect(onRemove).toHaveBeenCalledOnce();
+ });
+
+ it('provides a default file label and merges native descriptions with helper text and errors', () => {
+ const { rerender } = render(
+ <>
+ <span id="image-format">PNG images only.</span>
+ <ImageInput
+ uploadLabel="Choose workspace image"
+ helperText="Choose a square image."
+ errorMessage="The image could not be saved."
+ onFileSelect={vi.fn()}
+ aria-describedby="image-format"
+ />
+ </>,
+ );
+ const defaultFileInput = screen.getByLabelText('Choose workspace image', {
+ selector: 'input',
+ });
+
+ expect(defaultFileInput).toHaveAttribute(
+ 'aria-label',
+ 'Choose workspace image',
+ );
+ expect(defaultFileInput).toHaveAccessibleDescription(
+ 'PNG images only. Choose a square image. The image could not be saved.',
+ );
+
+ rerender(
+ <>
+ <span id="image-format">PNG images only.</span>
+ <ImageInput
+ uploadLabel="Choose workspace image"
+ helperText="Choose a square image."
+ errorMessage="The image could not be saved."
+ onFileSelect={vi.fn()}
+ aria-label="Workspace image file"
+ aria-describedby="image-format"
+ />
+ </>,
+ );
+
+ expect(
+ screen.getByLabelText('Workspace image file', { selector: 'input' }),
+ ).toHaveAccessibleDescription(
+ 'PNG images only. Choose a square image. The image could not be saved.',
+ );
+
+ for (const button of screen.getAllByRole('button', {
+ name: 'Choose workspace image',
+ })) {
+ expect(button).toHaveAccessibleDescription(
+ 'PNG images only. Choose a square image. The image could not be saved.',
+ );
+ }
+ });
});
diff --git a/packages/twenty-ui/src/components/input/ImageInput/types/ImageInputProps.ts b/packages/twenty-ui/src/components/input/ImageInput/types/ImageInputProps.ts
index 4ccdb967af7..f01087d7843 100644
--- a/packages/twenty-ui/src/components/input/ImageInput/types/ImageInputProps.ts
+++ b/packages/twenty-ui/src/components/input/ImageInput/types/ImageInputProps.ts
@@ -1,19 +1,34 @@
import { type useRender } from '@base-ui/react/use-render';
+import { type ComponentPropsWithRef } from 'react';
export type ImageInputProps = Omit<
- useRender.ComponentProps<'div'>,
- 'children' | 'onAbort'
-> & {
- src?: string | null;
- onUpload?: (file: File) => void;
- onRemove?: () => void;
- onAbort?: () => void;
- disabled?: boolean;
- isUploading?: boolean;
- helperText?: string;
- errorMessage?: string | null;
- uploadLabel?: string;
- removeLabel?: string;
- abortLabel?: string;
- accept?: string;
-};
+ ComponentPropsWithRef<'input'>,
+ | 'children'
+ | 'dangerouslySetInnerHTML'
+ | 'type'
+ | 'multiple'
+ | 'value'
+ | 'defaultValue'
+ | 'hidden'
+ | 'onAbort'
+ | 'src'
+ | 'ref'
+ | 'className'
+ | 'style'
+> &
+ Pick<
+ useRender.ComponentProps<'div'>,
+ 'ref' | 'render' | 'className' | 'style'
+ > & {
+ src?: string | null;
+ onFileSelect?: (file: File) => void;
+ onRemove?: () => void;
+ onAbort?: () => void;
+ isUploading?: boolean;
+ helperText?: string;
+ errorMessage?: string | null;
+ uploadLabel?: string;
+ removeLabel?: string;
+ abortLabel?: string;
+ inputRef?: ComponentPropsWithRef<'input'>['ref'];
+ };