Skip to content

The open alternative to Salesforce, designed for AI.

Add loading positions to Button (#27496)

Raphaël Bosi871e79f0435b
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/icon-button.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/icon-button.mdx
index f4b5feba6b7..47270195797 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/icon-button.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/icon-button.mdx
@@ -41,7 +41,7 @@
</ParamField>
<ParamField body="loading" type="boolean">
- Shows a loading indicator and disables activation while preserving the button width.
+ Shows a loading indicator and disables activation.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, ButtonState&gt;">
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/light-button.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/light-button.mdx
index 55602291016..efa29aee81f 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/light-button.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/light-button.mdx
@@ -45,7 +45,11 @@
</ParamField>
<ParamField body="loading" type="boolean">
- Shows a loading indicator and disables activation while preserving the button width.
+ Shows a loading indicator and disables activation.
+</ParamField>
+
+<ParamField body="loadingPosition" type="&quot;center&quot; | &quot;end&quot; | &quot;start&quot;">
+ Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, ButtonState&gt;">
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/light-icon-button.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/light-icon-button.mdx
index a4ebbce1474..4c3f1b14a14 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/light-icon-button.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/light-icon-button.mdx
@@ -45,7 +45,7 @@
</ParamField>
<ParamField body="loading" type="boolean">
- Shows a loading indicator and disables activation while preserving the button width.
+ Shows a loading indicator and disables activation.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, ButtonState&gt;">
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/main-button.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/main-button.mdx
index 1c052241a2a..efe6f692110 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/main-button.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/main-button.mdx
@@ -41,7 +41,11 @@
</ParamField>
<ParamField body="loading" type="boolean">
- Shows a loading indicator and disables activation while preserving the button width.
+ Shows a loading indicator and disables activation.
+</ParamField>
+
+<ParamField body="loadingPosition" type="&quot;center&quot; | &quot;end&quot; | &quot;start&quot;">
+ Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, ButtonState&gt;">
diff --git a/packages/twenty-docs/snippets/ui/generated/input/button.mdx b/packages/twenty-docs/snippets/ui/generated/input/button.mdx
index fe0e8c3059b..0360a2670c9 100644
--- a/packages/twenty-docs/snippets/ui/generated/input/button.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/input/button.mdx
@@ -41,7 +41,11 @@
</ParamField>
<ParamField body="loading" type="boolean" default="false">
- Shows a loading indicator and disables activation while preserving the button width.
+ Shows a loading indicator and disables activation.
+</ParamField>
+
+<ParamField body="loadingPosition" type="&quot;center&quot; | &quot;end&quot; | &quot;start&quot;" default="center">
+ Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, ButtonState&gt;">
diff --git a/packages/twenty-docs/ui/primitives/input/button.mdx b/packages/twenty-docs/ui/primitives/input/button.mdx
index a7c257b7004..ddd28e15eae 100644
--- a/packages/twenty-docs/ui/primitives/input/button.mdx
+++ b/packages/twenty-docs/ui/primitives/input/button.mdx
@@ -73,7 +73,11 @@ Choose `solid`, `outline`, `soft`, `ghost`, or `link` independently of the `neut
`link` uses compact text with no border or filled background. It follows its content height at either size, with a smaller font and narrower padding. Its neutral color uses stronger text on hover. The appearance does not determine semantics: use `onClick` for actions and `href` for navigation.
-`disabled` and `loading` prevent activation. Loading keeps the label accessible and preserves the button's width while showing a spinner.
+`disabled` and `loading` prevent activation. Loading keeps the label accessible and communicates a busy state. By default, `loadingPosition="center"` hides the content while preserving its layout space and centers the spinner. Set `loadingPosition` to `start` or `end` to keep children and the opposite icon visible while replacing the corresponding icon with the spinner.
+
+Your application owns progress formatting and the translated label. Pass the complete status phrase as children, for example `Installing (42%)`.
+
+<StoryEmbed storyId="ui-input-button-button--loading-at-end" height={220} />
## Upcoming features
diff --git a/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationActionButton.tsx b/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationActionButton.tsx
index e9667e9175a..cb17f4e4253 100644
--- a/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationActionButton.tsx
+++ b/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationActionButton.tsx
@@ -4,7 +4,6 @@ import { Link } from 'react-router-dom';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath, isDefined } from 'twenty-shared/utils';
import { IconDownload, IconSettings } from 'twenty-ui/icon';
-import { Loader } from 'twenty-ui/primitives/feedback';
import { Button } from 'twenty-ui/primitives/input';
type SettingsApplicationActionButtonProps = {
@@ -51,12 +50,12 @@ export const SettingsApplicationActionButton = ({
return (
<Button
startIcon={<IconDownload />}
- endIcon={isInstalling ? <Loader /> : undefined}
variant="solid"
color="accent"
size="sm"
onClick={onInstall}
- disabled={isInstalling}
+ loading={isInstalling}
+ loadingPosition="end"
>
{isInstalling ? t`Installing ${displayedInstallProgress}` : t`Install`}
</Button>
diff --git a/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationUninstallButton.tsx b/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationUninstallButton.tsx
index 220810f9396..c113da4257d 100644
--- a/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationUninstallButton.tsx
+++ b/packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationUninstallButton.tsx
@@ -5,7 +5,6 @@ import { t } from '@lingui/core/macro';
import { Trans } from '@lingui/react/macro';
import { useId } from 'react';
import { IconTrash } from 'twenty-ui/icon';
-import { Loader } from 'twenty-ui/primitives/feedback';
import { Button } from 'twenty-ui/primitives/input';
type SettingsApplicationUninstallButtonProps = {
@@ -31,12 +30,12 @@ export const SettingsApplicationUninstallButton = ({
<>
<Button
startIcon={<IconTrash />}
- endIcon={isUninstalling ? <Loader /> : undefined}
variant="outline"
color="danger"
size="sm"
onClick={() => openDialog(uninstallDialogId)}
- disabled={isUninstalling}
+ loading={isUninstalling}
+ loadingPosition="end"
>
{isUninstalling
? t`Uninstalling ${displayedUninstallProgress}`
diff --git a/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx b/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
index f514ad688fe..16832749007 100644
--- a/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
+++ b/packages/twenty-front/src/modules/settings/applications/components/__tests__/SettingsApplicationActionButton.test.tsx
@@ -57,12 +57,13 @@ describe('SettingsApplicationActionButton', () => {
expect(onInstall).toHaveBeenCalledTimes(1);
});
- it('disables the button while installing', () => {
+ it('disables the button and communicates a busy state while installing', () => {
renderActionButton({ isInstalling: true });
- expect(
- screen.getByRole('button', { name: /^Installing\b/ }),
- ).toBeDisabled();
+ const button = screen.getByRole('button', { name: /^Installing\b/ });
+
+ expect(button).toBeDisabled();
+ expect(button).toHaveAttribute('aria-busy', 'true');
});
it('shows the installation progress in the label while installing', () => {
diff --git a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationShareLinkButtons.tsx b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationShareLinkButtons.tsx
index c6731fd184d..287b754c2e0 100644
--- a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationShareLinkButtons.tsx
+++ b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationShareLinkButtons.tsx
@@ -15,7 +15,6 @@ import {
IconDownload,
IconInfoCircle,
} from 'twenty-ui/icon';
-import { Loader } from 'twenty-ui/primitives/feedback';
import { Button } from 'twenty-ui/primitives/input';
import { themeCssVariables } from 'twenty-ui/theme';
import { FindMarketplaceAppDetailDocument } from '~/generated-metadata/graphql';
@@ -75,9 +74,9 @@ export const SettingsApplicationRegistrationShareLinkButtons = ({
<>
<Button
startIcon={<IconDownload />}
- endIcon={isInstalling ? <Loader /> : undefined}
onClick={requestInstall}
- disabled={isInstalling}
+ loading={isInstalling}
+ loadingPosition="end"
variant="outline"
>
{isInstalling
diff --git a/packages/twenty-ui/docs/buttonPropDescriptions.ts b/packages/twenty-ui/docs/buttonPropDescriptions.ts
index d54f4cdb652..30c45282cdc 100644
--- a/packages/twenty-ui/docs/buttonPropDescriptions.ts
+++ b/packages/twenty-ui/docs/buttonPropDescriptions.ts
@@ -6,8 +6,9 @@ export const BUTTON_PROP_DESCRIPTIONS = {
color: 'Semantic color of the button.',
size: 'Button height: `sm` (24px) or `md` (32px). The `link` variant uses its content height at either size.',
fullWidth: 'Expands the button to fill its container width.',
- loading:
- 'Shows a loading indicator and disables activation while preserving the button width.',
+ loading: 'Shows a loading indicator and disables activation.',
+ loadingPosition:
+ 'Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner.',
elevated:
'Adds a shadow and backdrop blur. Neutral outline buttons also use elevated surface colors.',
startIcon: 'Decorative content displayed before the label.',
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 14d6838e937..2b1d6e694d3 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -778,6 +778,7 @@
"AutocompleteRootProps": "primitives/input/Autocomplete/types/AutocompleteRootProps",
"ButtonColor": "primitives/input/Button/types/ButtonColor",
"ButtonGroupProps": "primitives/input/ButtonGroup/types/ButtonGroupProps",
+ "ButtonLoadingPosition": "primitives/input/Button/types/ButtonLoadingPosition",
"ButtonProps": "primitives/input/Button/types/ButtonProps",
"ButtonSize": "primitives/input/Button/types/ButtonSize",
"ButtonVariant": "primitives/input/Button/types/ButtonVariant",
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index cebc80e3590..4109f4abe57 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -1259,7 +1259,7 @@
"type": "boolean",
"required": false,
"defaultValue": null,
- "description": "Shows a loading indicator and disables activation while preserving the button width."
+ "description": "Shows a loading indicator and disables activation."
},
{
"name": "render",
@@ -1385,7 +1385,7 @@
"type": "boolean",
"required": false,
"defaultValue": null,
- "description": "Shows a loading indicator and disables activation while preserving the button width."
+ "description": "Shows a loading indicator and disables activation."
},
{
"name": "render",
@@ -1511,7 +1511,14 @@
"type": "boolean",
"required": false,
"defaultValue": null,
- "description": "Shows a loading indicator and disables activation while preserving the button width."
+ "description": "Shows a loading indicator and disables activation."
+ },
+ {
+ "name": "loadingPosition",
+ "type": "\"center\" | \"end\" | \"start\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner."
},
{
"name": "render",
@@ -1630,7 +1637,14 @@
"type": "boolean",
"required": false,
"defaultValue": null,
- "description": "Shows a loading indicator and disables activation while preserving the button width."
+ "description": "Shows a loading indicator and disables activation."
+ },
+ {
+ "name": "loadingPosition",
+ "type": "\"center\" | \"end\" | \"start\"",
+ "required": false,
+ "defaultValue": null,
+ "description": "Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner."
},
{
"name": "render",
@@ -1742,7 +1756,14 @@
"type": "boolean",
"required": false,
"defaultValue": "false",
- "description": "Shows a loading indicator and disables activation while preserving the button width."
+ "description": "Shows a loading indicator and disables activation."
+ },
+ {
+ "name": "loadingPosition",
+ "type": "\"center\" | \"end\" | \"start\"",
+ "required": false,
+ "defaultValue": "center",
+ "description": "Where the loading indicator appears. `center` hides the content while preserving its layout space; `start` and `end` keep children and the opposite icon visible and replace the corresponding icon with the spinner."
},
{
"name": "render",
diff --git a/packages/twenty-ui/src/components/input/IconButton/types/IconButtonProps.ts b/packages/twenty-ui/src/components/input/IconButton/types/IconButtonProps.ts
index 809fb0b9f13..e70baa493f1 100644
--- a/packages/twenty-ui/src/components/input/IconButton/types/IconButtonProps.ts
+++ b/packages/twenty-ui/src/components/input/IconButton/types/IconButtonProps.ts
@@ -15,6 +15,7 @@ export type IconButtonProps = Omit<
| 'shortcut'
| 'shortcutJoinLabel'
| 'fullWidth'
+ | 'loadingPosition'
> & {
size?: IconButtonSize;
shape?: 'square' | 'round';
diff --git a/packages/twenty-ui/src/components/navigation/TabButton/types/TabButtonProps.ts b/packages/twenty-ui/src/components/navigation/TabButton/types/TabButtonProps.ts
index 0e9b9fc0997..08988b5d20e 100644
--- a/packages/twenty-ui/src/components/navigation/TabButton/types/TabButtonProps.ts
+++ b/packages/twenty-ui/src/components/navigation/TabButton/types/TabButtonProps.ts
@@ -7,6 +7,7 @@ export type TabButtonProps = Omit<
| 'color'
| 'fullWidth'
| 'loading'
+ | 'loadingPosition'
| 'elevated'
| 'shortcut'
| 'shortcutJoinLabel'
diff --git a/packages/twenty-ui/src/primitives/input/Button/Button.tsx b/packages/twenty-ui/src/primitives/input/Button/Button.tsx
index 77d1730406b..aa88d054c59 100644
--- a/packages/twenty-ui/src/primitives/input/Button/Button.tsx
+++ b/packages/twenty-ui/src/primitives/input/Button/Button.tsx
@@ -17,6 +17,7 @@ export const Button = ({
size = 'md',
fullWidth = false,
loading = false,
+ loadingPosition = 'center',
elevated = false,
startIcon,
endIcon,
@@ -35,6 +36,11 @@ export const Button = ({
const resolvedSize = buttonGroup?.size ?? size;
const isLink = isDefined(href);
const linkProps = isLink ? { href } : undefined;
+ const isCenterLoading = loading && loadingPosition === 'center';
+ const resolvedStartIcon =
+ loading && loadingPosition === 'start' ? <Loader /> : startIcon;
+ const resolvedEndIcon =
+ loading && loadingPosition === 'end' ? <Loader /> : endIcon;
return (
<ButtonPrimitive
@@ -53,18 +59,18 @@ export const Button = ({
nativeButton={!isLink}
render={render ?? (isLink ? <a href={href}>{children}</a> : undefined)}
>
- <span className={clsx(styles.content, loading && styles.hidden)}>
- {isDefined(startIcon) && (
+ <span className={clsx(styles.content, isCenterLoading && styles.hidden)}>
+ {isDefined(resolvedStartIcon) && (
<span className={styles.icon} aria-hidden>
- {startIcon}
+ {resolvedStartIcon}
</span>
)}
{isDefined(children) && (
<span className={styles.label}>{children}</span>
)}
- {isDefined(endIcon) && (
+ {isDefined(resolvedEndIcon) && (
<span className={styles.icon} aria-hidden>
- {endIcon}
+ {resolvedEndIcon}
</span>
)}
{isDefined(shortcut) && (
@@ -77,7 +83,7 @@ export const Button = ({
/>
)}
</span>
- {loading && (
+ {isCenterLoading && (
<span className={styles.loader} aria-hidden>
<Loader />
</span>
diff --git a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
index d22c55e59de..bf1fe2c4f5a 100644
--- a/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
+++ b/packages/twenty-ui/src/primitives/input/Button/__stories__/Button.stories.tsx
@@ -2,7 +2,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
import { expect, fn, userEvent, within } from 'storybook/test';
-import { IconArrowRight, IconPlus } from '@ui/icon';
+import { IconArrowRight, IconDownload, IconPlus } from '@ui/icon';
import { Pill } from '@ui/primitives/data-display';
import { Text } from '@ui/primitives/typography';
import {
@@ -95,6 +95,7 @@ export const Loading: Story = {
const button = canvas.getByRole('button', { name: 'Create record' });
const width = button.getBoundingClientRect().width;
await userEvent.click(button);
+ await expect(canvas.getByText('Create record')).not.toBeVisible();
await expect(button).toHaveAttribute('aria-busy', 'true');
await expect(button).toBeDisabled();
await expect(button.getBoundingClientRect().width).toBe(width);
@@ -104,6 +105,25 @@ export const Loading: Story = {
await expect(button).toBeEnabled();
},
};
+export const LoadingAtEnd: Story = {
+ ...Default,
+ args: {
+ children: 'Installing (42%)',
+ startIcon: <IconDownload />,
+ loading: true,
+ loadingPosition: 'end',
+ },
+};
+export const LoadingAtEndInteraction: Story = {
+ ...LoadingAtEnd,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const button = canvas.getByRole('button', { name: 'Installing (42%)' });
+ await expect(canvas.getByText('Installing (42%)')).toBeVisible();
+ await expect(button).toHaveAttribute('aria-busy', 'true');
+ await expect(button).toBeDisabled();
+ },
+};
export const NativeForm: Story = {
...Default,
parameters: { a11y: A11Y_DEFER_COLOR_CONTRAST },
diff --git a/packages/twenty-ui/src/primitives/input/Button/__tests__/Button.test.tsx b/packages/twenty-ui/src/primitives/input/Button/__tests__/Button.test.tsx
index 84e8041beff..2c5a7ae8f5b 100644
--- a/packages/twenty-ui/src/primitives/input/Button/__tests__/Button.test.tsx
+++ b/packages/twenty-ui/src/primitives/input/Button/__tests__/Button.test.tsx
@@ -1,3 +1,9 @@
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { createRef } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+import loaderStyles from '@ui/primitives/feedback/Loader/Loader.module.scss';
import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
import { Button } from '../Button';
import styles from '../Button.module.scss';
@@ -8,3 +14,185 @@ runComponentConformance({
refInstanceOf: HTMLButtonElement,
ownClassName: styles.button,
});
+
+describe('Button loading', () => {
+ it('keeps content in its layout space behind the default centered spinner', () => {
+ render(
+ <Button
+ loading
+ startIcon={<span>Download icon</span>}
+ endIcon={<span>Arrow icon</span>}
+ >
+ Installing (42%)
+ </Button>,
+ );
+
+ const button = screen.getByRole('button', { name: 'Installing (42%)' });
+ const content = screen.getByText('Installing (42%)').parentElement;
+ const loader = button.querySelector<HTMLDivElement>(
+ `.${loaderStyles.container}`,
+ );
+
+ expect(content).toHaveClass(styles.hidden);
+ expect(content).toContainElement(screen.getByText('Download icon'));
+ expect(content).toContainElement(screen.getByText('Arrow icon'));
+ expect(loader?.parentElement).toHaveClass(styles.loader);
+ expect(loader?.parentElement?.parentElement).toBe(button);
+ });
+
+ it.each([
+ {
+ loadingPosition: 'start' as const,
+ replacedIcon: 'Download icon',
+ preservedIcon: 'Arrow icon',
+ loaderSibling: 'previousElementSibling' as const,
+ },
+ {
+ loadingPosition: 'end' as const,
+ replacedIcon: 'Arrow icon',
+ preservedIcon: 'Download icon',
+ loaderSibling: 'nextElementSibling' as const,
+ },
+ ])(
+ 'replaces the $loadingPosition icon while preserving children and the opposite icon',
+ ({ loadingPosition, replacedIcon, preservedIcon, loaderSibling }) => {
+ render(
+ <Button
+ loading
+ loadingPosition={loadingPosition}
+ startIcon={<span>Download icon</span>}
+ endIcon={<span>Arrow icon</span>}
+ >
+ Installing (42%)
+ </Button>,
+ );
+
+ const button = screen.getByRole('button', { name: 'Installing (42%)' });
+ const label = screen.getByText('Installing (42%)');
+ const loader = button.querySelector<HTMLDivElement>(
+ `.${loaderStyles.container}`,
+ );
+
+ expect(label.parentElement).not.toHaveClass(styles.hidden);
+ expect(screen.queryByText(replacedIcon)).not.toBeInTheDocument();
+ expect(screen.getByText(preservedIcon)).toBeVisible();
+ expect(loader).toBeInTheDocument();
+ expect(label[loaderSibling]).toContainElement(loader);
+ expect(loader?.parentElement).toHaveAttribute('aria-hidden', 'true');
+ },
+ );
+
+ it.each(['start', 'end'] as const)(
+ 'adds the spinner at %s when no icon was supplied',
+ (loadingPosition) => {
+ render(
+ <Button loading loadingPosition={loadingPosition}>
+ Installing
+ </Button>,
+ );
+
+ const button = screen.getByRole('button', { name: 'Installing' });
+
+ expect(screen.getByText('Installing').parentElement).not.toHaveClass(
+ styles.hidden,
+ );
+ expect(
+ button.querySelector<HTMLDivElement>(`.${loaderStyles.container}`),
+ ).toBeInTheDocument();
+ },
+ );
+
+ it.each(['center', 'start', 'end'] as const)(
+ 'disables activation and communicates a busy state with the spinner at %s',
+ async (loadingPosition) => {
+ const user = userEvent.setup();
+ const onClick = vi.fn();
+
+ render(
+ <Button loading loadingPosition={loadingPosition} onClick={onClick}>
+ Save
+ </Button>,
+ );
+
+ const button = screen.getByRole('button', { name: 'Save' });
+
+ expect(button).toBeDisabled();
+ expect(button).toHaveAttribute('aria-busy', 'true');
+ await user.click(button);
+ await user.tab();
+ await user.keyboard('{Enter} ');
+ expect(onClick).not.toHaveBeenCalled();
+ },
+ );
+
+ it.each(['center', 'start', 'end'] as const)(
+ 'preserves both icons and activation when loading is false with position %s',
+ async (loadingPosition) => {
+ const user = userEvent.setup();
+ const onClick = vi.fn();
+
+ render(
+ <Button
+ loadingPosition={loadingPosition}
+ startIcon={<span>Download icon</span>}
+ endIcon={<span>Arrow icon</span>}
+ onClick={onClick}
+ >
+ Install
+ </Button>,
+ );
+
+ const button = screen.getByRole('button', { name: 'Install' });
+
+ expect(button).toBeEnabled();
+ expect(button).not.toHaveAttribute('aria-busy');
+ expect(screen.getByText('Install').parentElement).not.toHaveClass(
+ styles.hidden,
+ );
+ expect(screen.getByText('Download icon')).toBeVisible();
+ expect(screen.getByText('Arrow icon')).toBeVisible();
+ expect(
+ button.querySelector<HTMLDivElement>(`.${loaderStyles.container}`),
+ ).not.toBeInTheDocument();
+ await user.click(button);
+ expect(onClick).toHaveBeenCalledOnce();
+ },
+ );
+
+ it('preserves custom link rendering and blocks activation while loading', async () => {
+ const user = userEvent.setup();
+ const onClick = vi.fn();
+ const ref = createRef<HTMLButtonElement>();
+
+ render(
+ <Button
+ ref={ref}
+ href="#destination"
+ render={
+ <a href="#destination" data-custom-render>
+ Installing
+ </a>
+ }
+ target="_blank"
+ rel="noreferrer"
+ loading
+ loadingPosition="end"
+ onClick={onClick}
+ >
+ Installing
+ </Button>,
+ );
+
+ const link = screen.getByRole('link', { name: 'Installing' });
+
+ expect(ref.current).toBe(link);
+ expect(link).toHaveAttribute('href', '#destination');
+ expect(link).toHaveAttribute('target', '_blank');
+ expect(link).toHaveAttribute('rel', 'noreferrer');
+ expect(link).toHaveAttribute('data-custom-render');
+ expect(link).toHaveAttribute('aria-disabled', 'true');
+ expect(link).toHaveAttribute('aria-busy', 'true');
+ await user.click(link);
+ expect(onClick).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/twenty-ui/src/primitives/input/Button/types/ButtonLoadingPosition.ts b/packages/twenty-ui/src/primitives/input/Button/types/ButtonLoadingPosition.ts
new file mode 100644
index 00000000000..2ffa4624997
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/input/Button/types/ButtonLoadingPosition.ts
@@ -0,0 +1 @@
+export type ButtonLoadingPosition = 'center' | 'start' | 'end';
diff --git a/packages/twenty-ui/src/primitives/input/Button/types/ButtonProps.ts b/packages/twenty-ui/src/primitives/input/Button/types/ButtonProps.ts
index 99de908f102..ce9fdc416ad 100644
--- a/packages/twenty-ui/src/primitives/input/Button/types/ButtonProps.ts
+++ b/packages/twenty-ui/src/primitives/input/Button/types/ButtonProps.ts
@@ -3,6 +3,7 @@ import { type Button as ButtonPrimitive } from '@base-ui/react/button';
import { type ComponentPropsWithRef, type ReactNode } from 'react';
import { type ButtonColor } from './ButtonColor';
+import { type ButtonLoadingPosition } from './ButtonLoadingPosition';
import { type ButtonSize } from './ButtonSize';
import { type ButtonVariant } from './ButtonVariant';
@@ -16,6 +17,7 @@ export type ButtonProps = Omit<
size?: ButtonSize;
fullWidth?: boolean;
loading?: boolean;
+ loadingPosition?: ButtonLoadingPosition;
elevated?: boolean;
startIcon?: ReactNode;
endIcon?: ReactNode;
diff --git a/packages/twenty-ui/src/primitives/input/index.ts b/packages/twenty-ui/src/primitives/input/index.ts
index fb13c6755f9..a0d4aa922c4 100644
--- a/packages/twenty-ui/src/primitives/input/index.ts
+++ b/packages/twenty-ui/src/primitives/input/index.ts
@@ -17,6 +17,7 @@ export type { AutocompletePopupProps } from './Autocomplete/types/AutocompletePo
export type { AutocompleteRootProps } from './Autocomplete/types/AutocompleteRootProps';
export { Button } from './Button/Button';
export type { ButtonColor } from './Button/types/ButtonColor';
+export type { ButtonLoadingPosition } from './Button/types/ButtonLoadingPosition';
export type { ButtonProps } from './Button/types/ButtonProps';
export type { ButtonSize } from './Button/types/ButtonSize';
export type { ButtonVariant } from './Button/types/ButtonVariant';