The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Complete Card composition (#27632)
Raphaël Bosi16438b3ab640
diff --git a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdxindex 4121a516906..c1d412cd7c3 100644--- a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx+++ b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx@@ -21,12 +21,28 @@Card sections or other content.</ParamField>+<ParamField body="Root.className" type="string">+ CSS class merged with the part class.+</ParamField>+<ParamField body="Root.fullWidth" type="boolean">Sets the card width to 100% of its container.</ParamField>+<ParamField body="Root.ref" type="Ref<HTMLDivElement>">+ Ref to the default div, or the element supplied through render.+</ParamField>++<ParamField body="Root.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.+</ParamField>+<ParamField body="Root.rounded" type="boolean">- Compatibility styling flag. Cards already use the same rounded corners when omitted.+ Cards already use the same rounded corners when omitted.+</ParamField>++<ParamField body="Root.style" type="CSSProperties">+ Native styles applied to the rendered part.</ParamField>### Card.Header@@ -36,7 +52,19 @@</ParamField><ParamField body="Header.className" type="string">- CSS class applied to the header.+ CSS class merged with the part class.+</ParamField>++<ParamField body="Header.ref" type="Ref<HTMLDivElement>">+ Ref to the default div, or the element supplied through render.+</ParamField>++<ParamField body="Header.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.+</ParamField>++<ParamField body="Header.style" type="CSSProperties">+ Native styles applied to the rendered part.</ParamField>### Card.Content@@ -46,19 +74,23 @@</ParamField><ParamField body="Content.className" type="string">- CSS class applied to the body.+ CSS class merged with the part class.</ParamField><ParamField body="Content.divider" type="boolean">Adds a bottom border.</ParamField>-<ParamField body="Content.hasHoverHighlight" type="boolean">- Changes the background on hover. Does not add an action.+<ParamField body="Content.ref" type="Ref<HTMLDivElement>">+ Ref to the default div, or the element supplied through render.+</ParamField>++<ParamField body="Content.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.</ParamField>-<ParamField body="Content.isClickable" type="boolean">- Shows a pointer cursor. Does not add button semantics or keyboard interaction.+<ParamField body="Content.style" type="CSSProperties">+ Native styles applied to the rendered part.</ParamField>### Card.Footer@@ -67,6 +99,22 @@Footer content, such as actions or supporting text.</ParamField>+<ParamField body="Footer.className" type="string">+ CSS class merged with the part class.+</ParamField>+<ParamField body="Footer.divider" type="boolean" default="true">Shows the top border unless explicitly set to false.</ParamField>++<ParamField body="Footer.ref" type="Ref<HTMLDivElement>">+ Ref to the default div, or the element supplied through render.+</ParamField>++<ParamField body="Footer.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.+</ParamField>++<ParamField body="Footer.style" type="CSSProperties">+ Native styles applied to the rendered part.+</ParamField>diff --git a/packages/twenty-docs/ui/primitives/surfaces/card.mdx b/packages/twenty-docs/ui/primitives/surfaces/card.mdxindex c1636f71673..1b8098fe822 100644--- a/packages/twenty-docs/ui/primitives/surfaces/card.mdx+++ b/packages/twenty-docs/ui/primitives/surfaces/card.mdx@@ -20,7 +20,9 @@ Card.Root (outer surface)Import `Card` from `twenty-ui/primitives/surfaces`. `Card.Root` supplies the outer border and clipping, but creates no sections internally. No part requires another part or a particular section order. The sections also work independently, without `Card.Root` or context.-Each part renders a `div` and accepts native div attributes, `className`, and `style`. No part adds heading, button, or HTML `footer` semantics automatically.+Each part renders a `div` by default and accepts native div attributes, event handlers, `className`, `style`, and a DOM `ref`. Use `render` with an element or callback to choose a semantic target. No part infers an element or role from `onClick`.++`CardRootProps`, `CardHeaderProps`, `CardContentProps`, and `CardFooterProps` are exported from `twenty-ui/primitives/surfaces`, `twenty-ui/primitives`, and the root package.<StoryEmbed storyId="ui-surfaces-card--default" title="Card example" />@@ -82,18 +84,66 @@ export const ImportSections = () => ();```-`Card.Content` supports `isClickable` for a pointer cursor and `hasHoverHighlight` for a hover background. These flags only change appearance. They do not add button semantics, keyboard activation, or a click handler.+## Interactive composition-## Independent parts and custom wrappers+Choose a native button for an action or an anchor for navigation through `render`. Supply target-specific attributes such as `type`, `disabled`, `href`, and `target` on that element. The actual owner supplies its keyboard, focus, disabled, and link behavior. Card does not add those behaviors to a display `div`.++```tsx+import { Button } from 'twenty-ui/primitives/input';+import { Card } from 'twenty-ui/primitives/surfaces';+import { Text } from 'twenty-ui/primitives/typography';++type ReviewCardProps = {+ disabled?: boolean;+ onReview: () => void;+ onDismiss: () => void;+};++export const ReviewCard = ({+ disabled,+ onReview,+ onDismiss,+}: ReviewCardProps) => (+ <Card.Root>+ <Card.Content+ render={<button type="button" disabled={disabled} />}+ onClick={onReview}+ >+ <Text render={<span />}>Review 24 ready records</Text>+ </Card.Content>+ <Card.Footer>+ <Button onClick={onDismiss}>Dismiss</Button>+ </Card.Footer>+ </Card.Root>+);+```-A section can be used without the outer surface. Wrappers can derive their props from the corresponding part and spread them to preserve native attributes, event handlers, classes, and styles. Card parts retain their existing props without `ref` support; a wrapper that needs a DOM ref can attach it to a host element it owns.+The action and dismiss button are siblings inside a display card. Do not place another button, link, input, or other interactive control inside a button or link owner. When a button contains Card parts, render those parts as phrasing elements such as `span`.```tsx-import { type ComponentProps } from 'react';import { Card } from 'twenty-ui/primitives/surfaces';import { Text } from 'twenty-ui/primitives/typography';-type SummaryContentProps = ComponentProps<typeof Card.Content>;+export const ImportLinkCard = () => (+ <Card.Root render={<a href="/imports" />} fullWidth>+ <Card.Content>+ <Text>View imports</Text>+ </Card.Content>+ </Card.Root>+);+```++Native button and link owners retain the card layout and get a visible focus outline. Explicit button and link owners highlight on hover. Disabled owners keep their disabled appearance. Custom owners must supply their interaction behavior, including keyboard activation and disabled handling when applicable.++## Independent parts and custom wrappers++A section can be used without the outer surface. Wrappers can use its exported props type and spread it to preserve native attributes, event handlers, refs, render composition, classes, and styles. With a custom target, put its target-specific ref on the supplied element. Base UI merges that ref with the part ref and composed props.++```tsx+import { Card, type CardContentProps } from 'twenty-ui/primitives/surfaces';+import { Text } from 'twenty-ui/primitives/typography';++type SummaryContentProps = CardContentProps;const SummaryContent = ({ children, ...props }: SummaryContentProps) => (<Card.Content {...props}>{children}</Card.Content>@@ -119,7 +169,7 @@ Replace the four separate imports with `import { Card } from 'twenty-ui/primitiv| `ComponentProps<typeof Card>` | `ComponentProps<typeof Card.Root>` || `styled(Card)` | `styled(Card.Root)` |-Apply the same member names to JSX tags, styled wrappers, and prop types. Standalone part exports are removed without compatibility aliases. Existing props, styling defaults, and independent section use remain unchanged.+Apply the same member names to JSX tags, styled wrappers, and prop types. Standalone part exports are removed without compatibility aliases. Layout props, styling defaults, and independent section use remain. Replace `isClickable` and `hasHoverHighlight` with an explicit native owner through `render`. Move action handlers off display-only wrappers, preserve accessible names, and keep nested controls outside the primary action. Use `render={<button type="button" disabled={disabled} />}` for an action and `render={<a href="/imports" />}` for navigation. DOM refs now point to the actual rendered part.## Propsdiff --git a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsxindex 8f5d86f6ad9..1d1b326fab4 100644--- a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx+++ b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx@@ -68,6 +68,7 @@ import { avatarImageTest } from '@/__stories__/twenty-ui-gallery/utils/avatarImaimport { avatarControlsTest } from '@/__stories__/twenty-ui-gallery/utils/avatarControlsTest';import { commandBlockTest } from '@/__stories__/twenty-ui-gallery/utils/commandBlockTest';import { calloutTest } from '@/__stories__/twenty-ui-gallery/utils/calloutTest';+import { cardCompositionTest } from '@/__stories__/twenty-ui-gallery/utils/cardCompositionTest';const meta: Meta<typeof FrontComponentRenderer> = {title: 'FrontComponent/Twenty UI Gallery',@@ -217,6 +218,17 @@ export const SurfacesPreact: Story = createGalleryStory({play: galleryRenderTest,});+export const CardCompositionReact: Story = createGalleryStory({+ frontComponentBundleName: 'twenty-ui-card-composition',+ runtime: 'react',+ play: cardCompositionTest,+});+export const CardCompositionPreact: Story = createGalleryStory({+ frontComponentBundleName: 'twenty-ui-card-composition',+ runtime: 'preact',+ play: cardCompositionTest,+});+export const DialogReact: Story = createGalleryStory({frontComponentBundleName: 'twenty-ui-dialog',runtime: 'react',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.mdindex 480d91f3559..0c14cdaad97 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@@ -13,6 +13,8 @@ Popover composes Portal, Positioner, Popup, Arrow and Viewport. Its focused ReacTypography composition checks constrained text, explicit links, semantic elements, refs and native focus handlers in both runtimes. Overflow tooltip popup acceptance still depends on renderer portal and geometry support.+Card composition checks native part props and DOM refs, customized anatomy, ordinary display semantics, independent nested controls, button keyboard activation and disabled state, and explicit link ownership in both runtimes.+AvatarGroup checks derived counts, partially loaded totals, custom overflow and surviving keyed child state. Its native button and link (`target="_blank"`) verify refs, focus and pointer/keyboard activation in React and Preact.Scenarios share their checks between runtimes where behavior matches. The story@@ -46,6 +48,7 @@ effect within the interaction timeout.| `twenty-ui-phone-country-picker` | PhoneCountryPicker || `twenty-ui-currency-picker` | CurrencyPicker || `twenty-ui-popover` | Popover |+| `twenty-ui-card-composition` | Card (native parts and refs, render composition, display semantics, button/link ownership and nested controls) || `twenty-ui-dialog` | SDK `openCommandConfirmationModal` confirmation request || `twenty-ui-menu` | Menu || `twenty-ui-select` | Select |diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-card-composition.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-card-composition.front-component.tsxnew file mode 100644index 00000000000..7750d1cb0db--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-card-composition.front-component.tsx@@ -0,0 +1,175 @@+import { createElement, useRef, useState } from 'react';+import { defineFrontComponent } from 'twenty-sdk/define';+import { Button } from 'twenty-ui/primitives/input';+import {+ Card,+ type CardContentProps,+ type CardFooterProps,+ type CardHeaderProps,+ type CardRootProps,+} from 'twenty-ui/primitives/surfaces';+import { Heading, Text } from 'twenty-ui/primitives/typography';++import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';++const ROOT_PROPS = {+ id: 'display-card',+ title: 'Display card',+ fullWidth: true,+ rounded: true,+ backgroundColor: 'rgb(245, 246, 247)',+} satisfies CardRootProps;++const HEADER_PROPS = {+ title: 'Display header',+ dir: 'ltr',+} satisfies CardHeaderProps;++const CONTENT_PROPS = {+ title: 'Display content',+ divider: true,+} satisfies CardContentProps;++const FOOTER_PROPS = {+ title: 'Display footer',+ divider: false,+} satisfies CardFooterProps;++const CardComposition = () => {+ const rootRef = useRef<HTMLDivElement>(null);+ const headerRef = useRef<HTMLDivElement>(null);+ const contentRef = useRef<HTMLDivElement>(null);+ const footerRef = useRef<HTMLDivElement>(null);+ const buttonRef = useRef<HTMLButtonElement>(null);+ const linkRef = useRef<HTMLAnchorElement>(null);+ const [refTargets, setRefTargets] = useState('');+ const [displayClicks, setDisplayClicks] = useState(0);+ const [buttonActivations, setButtonActivations] = useState(0);+ const [ownerActivations, setOwnerActivations] = useState(0);+ const [linkActivations, setLinkActivations] = useState(0);+ const [follows, setFollows] = useState(0);+ const [nativeTarget, setNativeTarget] = useState('');++ return (+ <TwentyUiGalleryCard title="Card composition">+ <Card.Root+ id={ROOT_PROPS.id}+ title={ROOT_PROPS.title}+ fullWidth={ROOT_PROPS.fullWidth}+ rounded={ROOT_PROPS.rounded}+ backgroundColor={ROOT_PROPS.backgroundColor}+ ref={rootRef}+ data-card-part="root"+ onClick={() => setDisplayClicks((count) => count + 1)}+ >+ <Card.Header+ title={HEADER_PROPS.title}+ dir={HEADER_PROPS.dir}+ ref={headerRef}+ data-card-part="header"+ >+ <Heading level={3}>Account summary</Heading>+ </Card.Header>+ <Card.Content+ title={CONTENT_PROPS.title}+ divider={CONTENT_PROPS.divider}+ ref={contentRef}+ data-card-part="content"+ >+ <Text>Display-only account details</Text>+ </Card.Content>+ <Card.Footer+ title={FOOTER_PROPS.title}+ divider={FOOTER_PROPS.divider}+ ref={footerRef}+ data-card-part="footer"+ >+ <Button+ onClick={() => {+ setRefTargets(+ [rootRef, headerRef, contentRef, footerRef]+ .map((ref) => ref.current?.getAttribute('data-card-part'))+ .join('/'),+ );+ }}+ >+ Read card refs+ </Button>+ </Card.Footer>+ </Card.Root>+ <Card.Root render={<article aria-labelledby="composed-card-title" />}>+ <Card.Header render={<header />} title="Composed header">+ <Heading id="composed-card-title" level={3}>+ Composed account+ </Heading>+ </Card.Header>+ <Card.Content+ render={(props) =>+ createElement('section', {+ ...props,+ 'aria-label': 'Composed account details',+ })+ }+ >+ <Text>Account owner: Alice</Text>+ </Card.Content>+ <Card.Footer render={<footer />} title="Composed footer">+ <Button onClick={() => setFollows((count) => count + 1)}>+ Follow account+ </Button>+ </Card.Footer>+ </Card.Root>+ <Card.Root+ render={+ <button+ ref={buttonRef}+ type="button"+ data-native-owner="button"+ onClick={() => setOwnerActivations((count) => count + 1)}+ />+ }+ onClick={() => {+ setButtonActivations((count) => count + 1);+ setNativeTarget(+ buttonRef.current?.getAttribute('data-native-owner') ?? '',+ );+ }}+ >+ <Card.Content render={<span />}>Open account</Card.Content>+ </Card.Root>+ <Card.Root+ render={<button type="button" disabled />}+ onClick={() => setButtonActivations((count) => count + 1)}+ >+ <Card.Content render={<span />}>Unavailable account</Card.Content>+ </Card.Root>+ <Card.Root+ render={+ <a ref={linkRef} href="/objects/account" data-native-owner="link" />+ }+ onClick={() => {+ setLinkActivations((count) => count + 1);+ setNativeTarget(+ linkRef.current?.getAttribute('data-native-owner') ?? '',+ );+ }}+ >+ <Card.Content render={<span />}>Account record</Card.Content>+ </Card.Root>+ <Text aria-label="Card ref targets">{refTargets}</Text>+ <Text aria-label="Display card clicks">{displayClicks}</Text>+ <Text aria-label="Card button activations">{buttonActivations}</Text>+ <Text aria-label="Card owner activations">{ownerActivations}</Text>+ <Text aria-label="Card link activations">{linkActivations}</Text>+ <Text aria-label="Account follows">{follows}</Text>+ <Text aria-label="Card native target">{nativeTarget}</Text>+ </TwentyUiGalleryCard>+ );+};++export default defineFrontComponent({+ universalIdentifier: '01554c42-e5bd-43c5-a9f7-0683c5340e95',+ name: 'twenty-ui-card-composition',+ description: 'Card native parts, render composition and interactive owners',+ component: CardComposition,+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardCompositionTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardCompositionTest.tsnew file mode 100644index 00000000000..f58c1f3d3b5--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/cardCompositionTest.ts@@ -0,0 +1,110 @@+import { expect, userEvent, waitFor, within } from 'storybook/test';++import { errorHandler } from '@/__stories__/shared/test-utils/createFrontComponentStoryMeta';+import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';++export const cardCompositionTest: TwentyUiGalleryPlayFunction = async ({+ canvasElement,+}) => {+ const canvas = within(canvasElement);+ await expectFrontComponentMounted(canvas);++ const displayCard = canvas.getByTitle('Display card');+ const displayHeader = canvas.getByTitle('Display header');+ const displayContent = canvas.getByTitle('Display content');+ const displayFooter = canvas.getByTitle('Display footer');++ expect(displayCard.tagName).toBe('DIV');+ expect(displayCard).toHaveAttribute('id', 'display-card');+ expect(displayCard).toHaveAttribute('data-full-width');+ expect(displayCard).toHaveAttribute('data-rounded');+ await waitFor(() =>+ expect(getComputedStyle(displayCard).backgroundColor).toBe(+ 'rgb(245, 246, 247)',+ ),+ );+ expect(displayCard).not.toHaveAttribute('role');+ expect(displayCard).not.toHaveAttribute('tabindex');+ expect(displayHeader).toHaveAttribute('dir', 'ltr');+ expect(displayContent).toHaveAttribute('data-divider');+ expect(displayFooter).toHaveAttribute('data-no-divider');++ await userEvent.click(canvas.getByRole('button', { name: 'Read card refs' }));+ await waitFor(() =>+ expect(canvas.getByLabelText('Card ref targets')).toHaveTextContent(+ 'root/header/content/footer',+ ),+ );+ expect(canvas.getByLabelText('Display card clicks')).toHaveTextContent('1');+ expect(displayCard).not.toHaveAttribute('role');+ expect(displayCard).not.toHaveAttribute('tabindex');++ const composedCard = canvas.getByRole('article', {+ name: 'Composed account',+ });+ const composedContent = within(composedCard).getByRole('region', {+ name: 'Composed account details',+ });++ expect(composedCard.tagName).toBe('ARTICLE');+ expect(canvas.getByTitle('Composed header').tagName).toBe('HEADER');+ expect(composedContent.tagName).toBe('SECTION');+ expect(canvas.getByTitle('Composed footer').tagName).toBe('FOOTER');+ expect(composedCard).not.toHaveAttribute('tabindex');+ await userEvent.click(+ within(composedCard).getByRole('button', { name: 'Follow account' }),+ );+ await waitFor(() =>+ expect(canvas.getByLabelText('Account follows')).toHaveTextContent('1'),+ );++ const button = canvas.getByRole('button', { name: 'Open account' });+ const buttonActivations = canvas.getByLabelText('Card button activations');+ const ownerActivations = canvas.getByLabelText('Card owner activations');++ expect(button.tagName).toBe('BUTTON');+ expect(button).toHaveAttribute('type', 'button');+ expect(button.querySelector('button, a')).toBeNull();+ await userEvent.click(button);+ await expect(button).toHaveFocus();+ await userEvent.keyboard('{Enter}');+ await userEvent.keyboard(' ');+ await waitFor(() => {+ expect(buttonActivations).toHaveTextContent('3');+ expect(ownerActivations).toHaveTextContent('3');+ expect(canvas.getByLabelText('Card native target')).toHaveTextContent(+ 'button',+ );+ });+ const disabledButton = canvas.getByRole('button', {+ name: 'Unavailable account',+ });+ expect(disabledButton).toBeDisabled();+ await userEvent.tab();++ const link = canvas.getByRole('link', { name: 'Account record' });+ expect(link.tagName).toBe('A');+ expect(link).toHaveAttribute('href', '/objects/account');+ await expect(link).toHaveFocus();+ const preventNavigation = (event: Event) => event.preventDefault();+ link.addEventListener('click', preventNavigation);++ try {+ await userEvent.keyboard('{Enter}');+ await waitFor(() =>+ expect(canvas.getByLabelText('Card link activations')).toHaveTextContent(+ '1',+ ),+ );+ expect(canvas.getByLabelText('Card native target')).toHaveTextContent(+ 'link',+ );+ } finally {+ link.removeEventListener('click', preventNavigation);+ }++ await userEvent.click(disabledButton);+ expect(buttonActivations).toHaveTextContent('3');+ expect(errorHandler).not.toHaveBeenCalled();+};diff --git a/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx b/packages/twenty-front/src/modules/activities/components/ActivityRow.tsxindex 062c212063c..44bf5053ae5 100644--- a/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx+++ b/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx@@ -1,5 +1,7 @@+import { CARD_ACTION_CLASS_NAME } from '@/ui/layout/card/styles/CardActionClassName';import { styled } from '@linaria/react';-import React from 'react';+import { type MouseEvent, type PropsWithChildren } from 'react';+import { isDefined } from 'twenty-shared/utils';import { Card } from 'twenty-ui/primitives/surfaces';import { themeCssVariables } from 'twenty-ui/theme';@@ -11,38 +13,74 @@ const StyledRowContentContainer = styled.div`gap: ${themeCssVariables.spacing[2]};height: ${themeCssVariables.spacing[12]};padding: ${themeCssVariables.spacing[0]} ${themeCssVariables.spacing[4]};+ position: relative;}- > div[data-clickable='false'] {- cursor: default;+ > div:has(> .${CARD_ACTION_CLASS_NAME}:not(:disabled)):hover {+ background: ${themeCssVariables.background.transparent.lighter};+ cursor: pointer;}+`;- > div[data-hover-highlight]:hover {- background: ${themeCssVariables.background.transparent.lighter};+const StyledRowAction = styled.button`+ &:disabled {+ cursor: default;+ pointer-events: none;}`;+const INDEPENDENT_ROW_ACTION_SELECTOR = [+ 'a',+ 'button',+ 'input',+ 'select',+ 'textarea',+ '[role="button"]',+ '[role="checkbox"]',+ '[role="link"]',+ '[role="switch"]',+ '[contenteditable]:not([contenteditable="false"])',+].join(', ');++type ActivityRowProps = PropsWithChildren<{+ onClick?: () => void;+ disabled?: boolean;+ label: string;+}>;+export const ActivityRow = ({children,onClick,disabled,-}: React.PropsWithChildren<{- onClick?: (event: React.MouseEvent<HTMLDivElement>) => void;- disabled?: boolean;-}>) => {- const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {- if (disabled !== true) {- onClick?.(event);+ label,+}: ActivityRowProps) => {+ const handleContentClick = (event: MouseEvent<HTMLDivElement>) => {+ const target = event.target;++ if (+ disabled ||+ event.defaultPrevented ||+ !(target instanceof Element) ||+ isDefined(target.closest(INDEPENDENT_ROW_ACTION_SELECTOR))+ ) {+ return;}++ onClick?.();};return (<StyledRowContentContainer>- <Card.Content- onClick={handleClick}- isClickable={disabled !== true}- hasHoverHighlight={disabled !== true}- >+ <Card.Content onClick={handleContentClick}>+ {isDefined(onClick) && (+ <StyledRowAction+ className={CARD_ACTION_CLASS_NAME}+ type="button"+ aria-label={label}+ onClick={onClick}+ disabled={disabled}+ />+ )}{children}</Card.Content></StyledRowContentContainer>diff --git a/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx b/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsxindex 210433cdd42..e9df3773b67 100644--- a/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx+++ b/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx@@ -1,12 +1,20 @@import { ActivityRow } from '@/activities/components/ActivityRow';import { type Meta, type StoryObj } from '@storybook/react-vite';-import { expect, within } from 'storybook/test';+import { expect, fn, userEvent, within } from 'storybook/test';+import { isDefined } from 'twenty-shared/utils';+import { Checkbox } from 'twenty-ui/primitives/input';+import {+ OverflowingTextWithTooltip,+ Text,+} from 'twenty-ui/primitives/typography';const meta: Meta<typeof ActivityRow> = {title: 'Modules/Activities/ActivityRow',component: ActivityRow,args: {children: 'Activity',+ label: 'Open activity',+ onClick: fn(),},};@@ -14,21 +22,183 @@ export default meta;type Story = StoryObj<typeof ActivityRow>;export const Interactive: Story = {- play: async ({ canvasElement }) => {- expect(await within(canvasElement).findByText('Activity')).toHaveAttribute(- 'data-hover-highlight',- 'true',- );+ play: async ({ canvasElement, args }) => {+ const action = within(canvasElement).getByRole('button', {+ name: 'Open activity',+ });++ action.focus();+ await userEvent.keyboard('{Enter} ');+ await expect(args.onClick).toHaveBeenCalledTimes(2);},};export const Disabled: Story = {- args: {- disabled: true,+ args: { disabled: true },+ play: async ({ canvasElement, args }) => {+ const action = within(canvasElement).getByRole('button', {+ name: 'Open activity',+ });++ await expect(action).toBeDisabled();+ action.focus();+ await expect(action).not.toHaveFocus();+ await expect(args.onClick).not.toHaveBeenCalled();+ },+};++export const IndependentCheckbox: Story = {+ render: (args) => (+ <ActivityRow {...args}>+ <span style={{ position: 'relative', zIndex: 1 }}>+ <Checkbox aria-label="Complete activity" />+ </span>+ <Text style={{ position: 'relative', zIndex: 1 }}>+ Activity with independent completion+ </Text>+ </ActivityRow>+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const action = canvas.getByRole('button', { name: 'Open activity' });+ const checkbox = canvas.getByRole('checkbox', {+ name: 'Complete activity',+ });++ await expect(action).not.toContainElement(checkbox);+ await userEvent.click(checkbox);+ await expect(checkbox).toBeChecked();+ await expect(args.onClick).not.toHaveBeenCalled();+ await userEvent.click(+ canvas.getByText('Activity with independent completion'),+ );+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ action.focus();+ await userEvent.keyboard('{Enter}');+ await expect(args.onClick).toHaveBeenCalledTimes(2);+ },+};++export const BodyTooltipAndLink: Story = {+ render: (args) => (+ <ActivityRow {...args}>+ <OverflowingTextWithTooltip+ text={+ <Text render={<span />}>+ Activity body{' '}+ <a+ href="#activity-reference"+ onClick={(event) => event.preventDefault()}+ >+ Reference+ </a>+ </Text>+ }+ tooltipContent="Activity details"+ alwaysShowTooltip+ style={{ position: 'relative', zIndex: 1 }}+ />+ </ActivityRow>+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const body = canvas.getByText('Activity body', { exact: false });++ await userEvent.hover(body);+ await expect(+ await within(canvasElement.ownerDocument.body).findByText(+ 'Activity details',+ ),+ ).toBeVisible();+ await userEvent.click(body);+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ await userEvent.click(canvas.getByRole('link', { name: 'Reference' }));+ await expect(args.onClick).toHaveBeenCalledTimes(1);},- play: async ({ canvasElement }) => {- expect(- await within(canvasElement).findByText('Activity'),- ).not.toHaveAttribute('data-hover-highlight');+};++export const HoverSurface: Story = {+ tags: ['!dev'],+ render: (args) => (+ <>+ <Text>Outside activity</Text>+ <ActivityRow {...args}>+ <Text style={{ position: 'relative', zIndex: 1 }}>+ Raised activity summary+ </Text>+ <span style={{ position: 'relative', zIndex: 1 }}>+ <Checkbox aria-label="Complete hovered activity" />+ </span>+ <a+ href="#hovered-activity-reference"+ onClick={(event) => event.preventDefault()}+ style={{ position: 'relative', zIndex: 1 }}+ >+ Activity reference+ </a>+ </ActivityRow>+ <ActivityRow {...args} disabled label="Unavailable activity">+ <Text style={{ position: 'relative', zIndex: 1 }}>+ Unavailable activity summary+ </Text>+ </ActivityRow>+ </>+ ),+ play: async ({ canvasElement, args }) => {+ const { userEvent: trustedUserEvent } = await import('vitest/browser');+ const canvas = within(canvasElement);+ const action = canvas.getByRole('button', { name: 'Open activity' });+ const disabledAction = canvas.getByRole('button', {+ name: 'Unavailable activity',+ });+ const rowContent = action.parentElement;+ const disabledRowContent = disabledAction.parentElement;++ if (!isDefined(rowContent) || !isDefined(disabledRowContent)) {+ throw new Error('Activity content was not rendered');+ }++ await trustedUserEvent.hover(canvas.getByText('Outside activity'));++ const restingBackground = getComputedStyle(rowContent).backgroundColor;+ const disabledBackground =+ getComputedStyle(disabledRowContent).backgroundColor;+ const body = canvas.getByText('Raised activity summary');+ const checkbox = canvas.getByRole('checkbox', {+ name: 'Complete hovered activity',+ });+ const link = canvas.getByRole('link', { name: 'Activity reference' });++ await trustedUserEvent.hover(body);+ await expect(rowContent).not.toHaveStyle({+ backgroundColor: restingBackground,+ });++ const hoveredBackground = getComputedStyle(rowContent).backgroundColor;++ for (const target of [action, checkbox, link]) {+ await trustedUserEvent.hover(target);+ await expect(rowContent).toHaveStyle({+ backgroundColor: hoveredBackground,+ });+ }++ await expect(body).toHaveStyle({ cursor: 'pointer' });+ await trustedUserEvent.click(checkbox);+ await expect(checkbox).toBeChecked();+ await trustedUserEvent.click(link);+ await expect(args.onClick).not.toHaveBeenCalled();+ await trustedUserEvent.click(body);+ await expect(args.onClick).toHaveBeenCalledTimes(1);++ const disabledBody = canvas.getByText('Unavailable activity summary');++ await trustedUserEvent.hover(disabledBody);+ await expect(disabledRowContent).toHaveStyle({+ backgroundColor: disabledBackground,+ });+ await expect(disabledBody).not.toHaveStyle({ cursor: 'pointer' });+ await trustedUserEvent.click(disabledBody);+ await expect(args.onClick).toHaveBeenCalledTimes(1);},};diff --git a/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx b/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsxindex 5067daa94d8..81a29ae9bab 100644--- a/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx+++ b/packages/twenty-front/src/modules/activities/emails/components/EmailThreadPreview.tsx@@ -6,6 +6,7 @@ import { getEmailParticipantAvatarColorSeed } from '@/activities/emails/utils/geimport { useOpenRecordInSidePanel } from '@/side-panel/hooks/useOpenRecordInSidePanel';import { t } from '@lingui/core/macro';+import { isNonEmptyString } from '@sniptt/guards';import { CoreObjectNameSingular } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';import { Avatar, Tag } from 'twenty-ui/primitives/data-display';@@ -137,8 +138,20 @@ export const EmailThreadPreview = ({ thread }: EmailThreadPreviewProps) => {};const isDisabled = visibility !== MessageChannelVisibility.SHARE_EVERYTHING;+ const isSubjectVisible =+ visibility === MessageChannelVisibility.SUBJECT ||+ visibility === MessageChannelVisibility.SHARE_EVERYTHING;+ const label =+ isSubjectVisible && isNonEmptyString(thread.subject)+ ? thread.subject+ : t`Email thread`;+return (- <ActivityRow onClick={handleThreadClick} disabled={isDisabled}>+ <ActivityRow+ onClick={handleThreadClick}+ disabled={isDisabled}+ label={label}+ ><StyledHeading unread={!thread.read}><StyledParticipantsContainer><Avatardiff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsxindex 14748863e8f..bc6209c2bee 100644--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx@@ -40,6 +40,8 @@ const StyledRightContent = styled.div`align-items: center;display: flex;gap: ${themeCssVariables.spacing['0.5']};+ position: relative;+ z-index: 1;`;const StyledCalendarIconContainer = styled.div`@@ -59,9 +61,11 @@ const StyledLink = styled.a`font-family: inherit;font-size: inherit;padding: 0;+ position: relative;text-align: left;text-decoration: none;width: 100%;+ z-index: 1;:hover {color: ${themeCssVariables.font.color.secondary};@@ -74,7 +78,9 @@ const StyledLinkContainer = styled.div``;const StyledTextInputContainer = styled.div`+ position: relative;width: 100%;+ z-index: 1;`;type AttachmentRowProps = {@@ -194,7 +200,11 @@ export const AttachmentRow = ({} as GenericFieldContextType}>- <ActivityRow onClick={handleRowClick} disabled={isEditing}>+ <ActivityRow+ onClick={handleRowClick}+ disabled={isEditing}+ label={`${attachmentFileName}${attachmentFileExtension}`}+ ><StyledLeftContent><FileIcon fileCategory={fileCategory} thumbnailUrl={fileUrl} />{isEditing ? (diff --git a/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx b/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsxindex c26e8b5b879..c5d09ad174c 100644--- a/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx+++ b/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx@@ -1,5 +1,6 @@import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';+import { isNonEmptyString } from '@sniptt/guards';import { LinkifiedText } from '@/ui/field/display/components/LinkifiedText/LinkifiedText';import { getActivitySummary } from '@/activities/utils/getActivitySummary';@@ -28,7 +29,9 @@ const StyledTaskBody = styled.div`max-width: calc(80% - ${themeCssVariables.spacing[2]});overflow: hidden;padding-bottom: 1px;+ position: relative;text-overflow: ellipsis;+ z-index: 1;`;const StyledTaskTitle = styled.div<{@@ -68,7 +71,9 @@ const StyledRightSideContainer = styled.div`const StyledActivityTargetsContainer = styled.div`overflow: clip;+ position: relative;width: 100%;+ z-index: 1;`;const StyledPlaceholder = styled.div`@@ -85,6 +90,8 @@ const StyledLeftSideContainer = styled.div`const StyledCheckboxContainer = styled.div`display: flex;+ position: relative;+ z-index: 1;`;export const TaskRow = ({ task }: { task: Task }) => {@@ -109,6 +116,7 @@ export const TaskRow = ({ task }: { task: Task }) => {return (<ActivityRow+ label={isNonEmptyString(task.title) ? task.title : t`Task title`}onClick={() => {openRecordInSidePanel({recordId: task.id,diff --git a/packages/twenty-front/src/modules/settings/components/SettingsCard.tsx b/packages/twenty-front/src/modules/settings/components/SettingsCard.tsxindex 427d88ace2f..69b4de368a6 100644--- a/packages/twenty-front/src/modules/settings/components/SettingsCard.tsx+++ b/packages/twenty-front/src/modules/settings/components/SettingsCard.tsx@@ -1,3 +1,4 @@+import { CARD_ACTION_CLASS_NAME } from '@/ui/layout/card/styles/CardActionClassName';import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';@@ -22,14 +23,12 @@ type SettingsCardProps = {const StyledCardWrapper = styled.div<{disabled?: boolean;- clickable?: boolean;}>`color: ${({ disabled }) =>disabled? themeCssVariables.font.color.extraLight: themeCssVariables.font.color.tertiary};- cursor: ${({ disabled, clickable }) =>- disabled ? 'not-allowed' : clickable ? 'pointer' : 'default'};+ cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'default')};width: 100%;> div {@@ -43,11 +42,19 @@ const StyledCardContentContainer = styled.div`flex-direction: column;gap: ${themeCssVariables.spacing[2]};padding: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[2]};+ position: relative;+ }- &:hover {- background-color: ${themeCssVariables.background.quaternary};- cursor: pointer;- }+ a:hover & > div,+ > div:has(> button:not(:disabled):hover) {+ background-color: ${themeCssVariables.background.quaternary};+ cursor: pointer;+ }+`;++const StyledCardAction = styled.button`+ &:disabled {+ cursor: not-allowed;}`;@@ -110,18 +117,19 @@ export const SettingsCard = ({const theme = useTheme();return (- <StyledCardWrapper- disabled={disabled}- clickable={!!onClick}- className={className}- >- <Card.Root- onClick={disabled ? undefined : onClick}- rounded={true}- fullWidth- >+ <StyledCardWrapper disabled={disabled} className={className}>+ <Card.Root rounded={true} fullWidth><StyledCardContentContainer><Card.Content>+ {isDefined(onClick) && (+ <StyledCardAction+ className={CARD_ACTION_CLASS_NAME}+ type="button"+ aria-label={title}+ onClick={onClick}+ disabled={disabled}+ />+ )}<StyledHeader><StyledIconContainer disabled={disabled} iconColor={iconColor}>{Icon}diff --git a/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx b/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsxindex 7c43546c34d..04bebc97771 100644--- a/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx+++ b/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx@@ -1,5 +1,8 @@+import { CARD_ACTION_CLASS_NAME } from '@/ui/layout/card/styles/CardActionClassName';+import { css, cx } from '@linaria/core';import { styled } from '@linaria/react';-import { type ReactNode } from 'react';+import { isNonEmptyString } from '@sniptt/guards';+import { type ReactNode, useId } from 'react';import { Link } from 'react-router-dom';import { isDefined } from 'twenty-shared/utils';import { IconChevronRight, type IconComponent } from 'twenty-ui/icon';@@ -17,6 +20,7 @@ const StyledRowContainer = styled.div`height: ${themeCssVariables.spacing[10]};padding: ${themeCssVariables.spacing[2]};padding-left: ${themeCssVariables.spacing[3]};+ position: relative;> svg {flex-shrink: 0;@@ -29,6 +33,23 @@ const StyledRightContainer = styled.div`display: flex;flex-shrink: 0;gap: ${themeCssVariables.spacing[1]};+ pointer-events: none;+ position: relative;+ z-index: 1;++ :is(+ a,+ button,+ input,+ select,+ textarea,+ [role='button'],+ [role='checkbox'],+ [role='link'],+ [role='switch']+ ) {+ pointer-events: auto;+ }`;const StyledContent = styled.div`@@ -60,10 +81,9 @@ const StyledDescription = styled.span`white-space: nowrap;`;-const StyledLinkContainer = styled.div`- > a {- color: ${themeCssVariables.font.color.secondary};- text-decoration: none;+const rowActionClassName = css`+ &:hover {+ background: ${themeCssVariables.background.transparent.lighter};}`;@@ -89,31 +109,49 @@ export const SettingsListItemCardContent = ({to,}: SettingsListItemCardContentProps) => {const theme = useTheme();- const isInteractive = isDefined(onClick) || isDefined(to);+ const labelId = useId();+ const descriptionId = useId();+ const hasDescription = isNonEmptyString(description);- const content = (+ return (<StyledRowContainer>- <Card.Content- onClick={onClick}- divider={divider}- isClickable={isInteractive}- hasHoverHighlight={isInteractive}- >- {!!LeftIcon && (+ <Card.Content divider={divider}>+ {isDefined(to) ? (+ <Link+ className={cx(CARD_ACTION_CLASS_NAME, rowActionClassName)}+ aria-labelledby={labelId}+ aria-describedby={hasDescription ? descriptionId : undefined}+ onClick={onClick}+ to={to}+ />+ ) : (+ isDefined(onClick) && (+ <button+ className={cx(CARD_ACTION_CLASS_NAME, rowActionClassName)}+ aria-labelledby={labelId}+ aria-describedby={hasDescription ? descriptionId : undefined}+ onClick={onClick}+ type="button"+ />+ )+ )}+ {isDefined(LeftIcon) && (<LeftIconsize={theme.icon.size.md}color={LeftIconColor ?? 'currentColor'}/>)}<StyledContent>- <StyledLabel>{label}</StyledLabel>- {!!description && (- <StyledDescription>{description}</StyledDescription>+ <StyledLabel id={labelId}>{label}</StyledLabel>+ {hasDescription && (+ <StyledDescription id={descriptionId}>+ {description}+ </StyledDescription>)}</StyledContent><StyledRightContainer>{rightComponent}- {!!to && (+ {isDefined(to) && (<IconChevronRightsize={theme.icon.size.md}color={theme.font.color.tertiary}@@ -123,14 +161,4 @@ export const SettingsListItemCardContent = ({</Card.Content></StyledRowContainer>);-- if (isDefined(to)) {- return (- <StyledLinkContainer>- <Link to={to}>{content}</Link>- </StyledLinkContainer>- );- }-- return content;};diff --git a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsCard.stories.tsx b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsCard.stories.tsxindex ebd3ede8afd..3116d83919e 100644--- a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsCard.stories.tsx+++ b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsCard.stories.tsx@@ -1,6 +1,7 @@import { SettingsCard } from '@/settings/components/SettingsCard';import { type Meta, type StoryObj } from '@storybook/react-vite';import React from 'react';+import { expect, fn, userEvent, within } from 'storybook/test';import { IconMailCog } from 'twenty-ui/icon';import { ComponentDecorator } from 'twenty-ui/testing';@@ -14,7 +15,7 @@ type Story = StoryObj<typeof SettingsCard>;export const Default: Story = {args: {- onClick: () => {},+ onClick: fn(),Icon: React.createElement(IconMailCog),title: 'Settings Card',},@@ -22,4 +23,32 @@ export const Default: Story = {className: { control: false },Icon: { control: false },},+ play: async ({ canvasElement, args }) => {+ const action = within(canvasElement).getByRole('button', {+ name: 'Settings Card',+ });++ action.focus();+ await userEvent.keyboard('{Enter} ');+ await expect(args.onClick).toHaveBeenCalledTimes(2);+ await expect(action).toHaveStyle({+ position: 'absolute',+ outlineWidth: '2px',+ outlineStyle: 'solid',+ outlineOffset: '-2px',+ });+ },+};++export const Disabled: Story = {+ args: { ...Default.args, disabled: true },+ play: async ({ canvasElement, args }) => {+ const action = within(canvasElement).getByRole('button', {+ name: 'Settings Card',+ });++ await expect(action).toBeDisabled();+ await userEvent.click(action);+ await expect(args.onClick).not.toHaveBeenCalled();+ },};diff --git a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsListItemCardContent.stories.tsx b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsListItemCardContent.stories.tsxindex 61e9ef948c8..5599033ddda 100644--- a/packages/twenty-front/src/modules/settings/components/__stories__/SettingsListItemCardContent.stories.tsx+++ b/packages/twenty-front/src/modules/settings/components/__stories__/SettingsListItemCardContent.stories.tsx@@ -1,6 +1,9 @@import { SettingsListItemCardContent } from '@/settings/components/SettingsListItemCardContent';import { type Meta, type StoryObj } from '@storybook/react-vite';-import { expect, fn, within } from 'storybook/test';+import { MemoryRouter, Route, Routes } from 'react-router-dom';+import { expect, fn, userEvent, within } from 'storybook/test';+import { Button } from 'twenty-ui/primitives/input';+import { Text } from 'twenty-ui/primitives/typography';const meta: Meta<typeof SettingsListItemCardContent> = {title: 'Modules/Settings/SettingsListItemCardContent',@@ -16,11 +19,68 @@ export default meta;type Story = StoryObj<typeof SettingsListItemCardContent>;export const Default: Story = {+ play: async ({ canvasElement, args }) => {+ const action = within(canvasElement).getByRole('button', {+ name: 'Callback row',+ });++ action.focus();+ await userEvent.keyboard('{Enter} ');+ await expect(args.onClick).toHaveBeenCalledTimes(2);+ await expect(action).toHaveStyle({+ position: 'absolute',+ outlineWidth: '2px',+ outlineStyle: 'solid',+ outlineOffset: '-2px',+ });+ },+};++export const DisplayRow: Story = {+ args: { onClick: undefined, label: 'Display row' },play: async ({ canvasElement }) => {- expect(- (await within(canvasElement).findByText('Callback row')).closest(- '[data-clickable]',- ),- ).toHaveAttribute('data-hover-highlight', 'true');+ const canvas = within(canvasElement);++ await expect(canvas.getByText('Display row')).toBeVisible();+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();+ await expect(canvas.queryByRole('link')).not.toBeInTheDocument();+ },+};++export const LinkWithIndependentControl: Story = {+ args: { label: 'Domain settings', to: '/card-detail' },+ render: (args) => (+ <MemoryRouter>+ <SettingsListItemCardContent+ {...args}+ rightComponent={<Button>More options</Button>}+ />+ <Routes>+ <Route path="/" element={null} />+ <Route+ path="/card-detail"+ element={<Text>Domain settings opened</Text>}+ />+ </Routes>+ </MemoryRouter>+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const link = canvas.getByRole('link', { name: 'Domain settings' });+ const control = canvas.getByRole('button', { name: 'More options' });++ await expect(link).toHaveAttribute('href', '/card-detail');+ await expect(link).not.toContainElement(control);+ await userEvent.click(control);+ await expect(args.onClick).not.toHaveBeenCalled();+ await expect(+ canvas.queryByText('Domain settings opened'),+ ).not.toBeInTheDocument();+ link.focus();+ await userEvent.keyboard('{Enter}');+ await expect(+ await canvas.findByText('Domain settings opened'),+ ).toBeVisible();+ await expect(args.onClick).toHaveBeenCalledTimes(1);},};diff --git a/packages/twenty-front/src/modules/settings/roles/role-permissions/object-level-permissions/components/SettingsRolePermissionsObjectLevelObjectPicker.tsx b/packages/twenty-front/src/modules/settings/roles/role-permissions/object-level-permissions/components/SettingsRolePermissionsObjectLevelObjectPicker.tsxindex 7c933191350..c549248db47 100644--- a/packages/twenty-front/src/modules/settings/roles/role-permissions/object-level-permissions/components/SettingsRolePermissionsObjectLevelObjectPicker.tsx+++ b/packages/twenty-front/src/modules/settings/roles/role-permissions/object-level-permissions/components/SettingsRolePermissionsObjectLevelObjectPicker.tsx@@ -127,12 +127,7 @@ export const SettingsRolePermissionsObjectLevelObjectPicker = ({/><StyledContainer>{standardObjects.map((objectMetadataItem) => (- <StyledCardContainer- key={objectMetadataItem.id}- onClick={() =>- handleSelectObjectMetadata(objectMetadataItem.id)- }- >+ <StyledCardContainer key={objectMetadataItem.id}><SettingsCardIcon={<ObjectMetadataIcon@@ -142,6 +137,9 @@ export const SettingsRolePermissionsObjectLevelObjectPicker = ({/>}title={objectMetadataItem.labelPlural}+ onClick={() =>+ handleSelectObjectMetadata(objectMetadataItem.id)+ }/></StyledCardContainer>))}@@ -156,12 +154,7 @@ export const SettingsRolePermissionsObjectLevelObjectPicker = ({/><StyledContainer>{customObjects.map((objectMetadataItem) => (- <StyledCardContainer- key={objectMetadataItem.id}- onClick={() =>- handleSelectObjectMetadata(objectMetadataItem.id)- }- >+ <StyledCardContainer key={objectMetadataItem.id}><SettingsCardIcon={<ObjectMetadataIcon@@ -171,6 +164,9 @@ export const SettingsRolePermissionsObjectLevelObjectPicker = ({/>}title={objectMetadataItem.labelPlural}+ onClick={() =>+ handleSelectObjectMetadata(objectMetadataItem.id)+ }/></StyledCardContainer>))}diff --git a/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.ts b/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.tsnew file mode 100644index 00000000000..5bdc4667181--- /dev/null+++ b/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.ts@@ -0,0 +1,16 @@+import { css } from '@linaria/core';+import { themeCssVariables } from 'twenty-ui/theme';++export const CARD_ACTION_CLASS_NAME = css`+ background: transparent;+ border: none;+ cursor: pointer;+ inset: 0;+ padding: 0;+ position: absolute;++ &:focus-visible {+ outline: 2px solid ${themeCssVariables.color.blue};+ outline-offset: -2px;+ }+`;diff --git a/packages/twenty-ui/docs/cardContentPropDescriptions.ts b/packages/twenty-ui/docs/cardContentPropDescriptions.tsindex 271ec473916..ed055c509ba 100644--- a/packages/twenty-ui/docs/cardContentPropDescriptions.ts+++ b/packages/twenty-ui/docs/cardContentPropDescriptions.ts@@ -1,12 +1,11 @@-import { type ComponentProps } from 'react';--import { type Card } from '../src/primitives/surfaces/Card/Card';+import { type CardContentProps } from '../src/primitives/surfaces/Card/types/CardContentProps';export const CARD_CONTENT_PROP_DESCRIPTIONS = {children: 'Content displayed in the padded body.',- className: 'CSS class applied to the body.',divider: 'Adds a bottom border.',- isClickable:- 'Shows a pointer cursor. Does not add button semantics or keyboard interaction.',- hasHoverHighlight: 'Changes the background on hover. Does not add an action.',-} satisfies Partial<Record<keyof ComponentProps<typeof Card.Content>, string>>;+ className: 'CSS class merged with the part class.',+ style: 'Native styles applied to the rendered part.',+ ref: 'Ref to the default div, or the element supplied through render.',+ render:+ 'Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.',+} satisfies Partial<Record<keyof CardContentProps, string>>;diff --git a/packages/twenty-ui/docs/cardFooterPropDescriptions.ts b/packages/twenty-ui/docs/cardFooterPropDescriptions.tsindex 6966844c833..704264ff383 100644--- a/packages/twenty-ui/docs/cardFooterPropDescriptions.ts+++ b/packages/twenty-ui/docs/cardFooterPropDescriptions.ts@@ -1,8 +1,11 @@-import { type ComponentProps } from 'react';--import { type Card } from '../src/primitives/surfaces/Card/Card';+import { type CardFooterProps } from '../src/primitives/surfaces/Card/types/CardFooterProps';export const CARD_FOOTER_PROP_DESCRIPTIONS = {children: 'Footer content, such as actions or supporting text.',divider: 'Shows the top border unless explicitly set to false.',-} satisfies Partial<Record<keyof ComponentProps<typeof Card.Footer>, string>>;+ className: 'CSS class merged with the part class.',+ style: 'Native styles applied to the rendered part.',+ ref: 'Ref to the default div, or the element supplied through render.',+ render:+ 'Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.',+} satisfies Partial<Record<keyof CardFooterProps, string>>;diff --git a/packages/twenty-ui/docs/cardHeaderPropDescriptions.ts b/packages/twenty-ui/docs/cardHeaderPropDescriptions.tsindex 4edbab060b8..ad2bc9b1c2f 100644--- a/packages/twenty-ui/docs/cardHeaderPropDescriptions.ts+++ b/packages/twenty-ui/docs/cardHeaderPropDescriptions.ts@@ -1,9 +1,11 @@-import { type ComponentProps } from 'react';--import { type Card } from '../src/primitives/surfaces/Card/Card';+import { type CardHeaderProps } from '../src/primitives/surfaces/Card/types/CardHeaderProps';export const CARD_HEADER_PROP_DESCRIPTIONS = {children:'Header content. Supply a Heading when the title should be a semantic heading.',- className: 'CSS class applied to the header.',-} satisfies Partial<Record<keyof ComponentProps<typeof Card.Header>, string>>;+ className: 'CSS class merged with the part class.',+ style: 'Native styles applied to the rendered part.',+ ref: 'Ref to the default div, or the element supplied through render.',+ render:+ 'Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.',+} satisfies Partial<Record<keyof CardHeaderProps, string>>;diff --git a/packages/twenty-ui/docs/cardPropDescriptions.ts b/packages/twenty-ui/docs/cardPropDescriptions.tsindex e0a6d94afaa..875a4971e89 100644--- a/packages/twenty-ui/docs/cardPropDescriptions.ts+++ b/packages/twenty-ui/docs/cardPropDescriptions.ts@@ -1,12 +1,14 @@-import { type ComponentProps } from 'react';--import { type Card } from '../src/primitives/surfaces/Card/Card';+import { type CardRootProps } from '../src/primitives/surfaces/Card/types/CardRootProps';export const CARD_PROP_DESCRIPTIONS = {children: 'Card sections or other content.',fullWidth: 'Sets the card width to 100% of its container.',- rounded:- 'Compatibility styling flag. Cards already use the same rounded corners when omitted.',+ rounded: 'Cards already use the same rounded corners when omitted.',backgroundColor:'CSS background color of the outer card. Child sections have their own backgrounds.',-} satisfies Partial<Record<keyof ComponentProps<typeof Card.Root>, string>>;+ className: 'CSS class merged with the part class.',+ style: 'Native styles applied to the rendered part.',+ ref: 'Ref to the default div, or the element supplied through render.',+ render:+ 'Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner.',+} satisfies Partial<Record<keyof CardRootProps, string>>;diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.jsonindex e2afe5774ef..652cc2e5f21 100644--- a/packages/twenty-ui/docs/public-exports.json+++ b/packages/twenty-ui/docs/public-exports.json@@ -931,6 +931,10 @@"AlertDialogTriggerState": "primitives/surfaces/AlertDialog/types/AlertDialogTriggerState","AlertDialogViewportProps": "primitives/surfaces/AlertDialog/types/AlertDialogViewportProps","AlertDialogViewportState": "primitives/surfaces/AlertDialog/types/AlertDialogViewportState",+ "CardContentProps": "primitives/surfaces/Card/types/CardContentProps",+ "CardFooterProps": "primitives/surfaces/Card/types/CardFooterProps",+ "CardHeaderProps": "primitives/surfaces/Card/types/CardHeaderProps",+ "CardRootProps": "primitives/surfaces/Card/types/CardRootProps","DialogBackdropProps": "primitives/surfaces/Dialog/types/DialogBackdropProps","DialogBackdropState": "primitives/surfaces/Dialog/types/DialogBackdropState","DialogBodyProps": "primitives/surfaces/Dialog/types/DialogBodyProps",diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.jsonindex 7f2faf28d13..fe7b43902d6 100644--- a/packages/twenty-ui/generated/components.docs.json+++ b/packages/twenty-ui/generated/components.docs.json@@ -5577,6 +5577,13 @@"defaultValue": null,"description": "Card sections or other content."},+ {+ "name": "className",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "CSS class merged with the part class."+ },{"name": "fullWidth","type": "boolean",@@ -5584,12 +5591,33 @@"defaultValue": null,"description": "Sets the card width to 100% of its container."},+ {+ "name": "ref",+ "type": "Ref<HTMLDivElement>",+ "required": false,+ "defaultValue": null,+ "description": "Ref to the default div, or the element supplied through render."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner."+ },{"name": "rounded","type": "boolean","required": false,"defaultValue": null,- "description": "Compatibility styling flag. Cards already use the same rounded corners when omitted."+ "description": "Cards already use the same rounded corners when omitted."+ },+ {+ "name": "style",+ "type": "CSSProperties",+ "required": false,+ "defaultValue": null,+ "description": "Native styles applied to the rendered part."}]},@@ -5608,7 +5636,28 @@"type": "string","required": false,"defaultValue": null,- "description": "CSS class applied to the header."+ "description": "CSS class merged with the part class."+ },+ {+ "name": "ref",+ "type": "Ref<HTMLDivElement>",+ "required": false,+ "defaultValue": null,+ "description": "Ref to the default div, or the element supplied through render."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner."+ },+ {+ "name": "style",+ "type": "CSSProperties",+ "required": false,+ "defaultValue": null,+ "description": "Native styles applied to the rendered part."}]},@@ -5627,7 +5676,7 @@"type": "string","required": false,"defaultValue": null,- "description": "CSS class applied to the body."+ "description": "CSS class merged with the part class."},{"name": "divider",@@ -5637,18 +5686,25 @@"description": "Adds a bottom border."},{- "name": "hasHoverHighlight",- "type": "boolean",+ "name": "ref",+ "type": "Ref<HTMLDivElement>","required": false,"defaultValue": null,- "description": "Changes the background on hover. Does not add an action."+ "description": "Ref to the default div, or the element supplied through render."},{- "name": "isClickable",- "type": "boolean",+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner."+ },+ {+ "name": "style",+ "type": "CSSProperties","required": false,"defaultValue": null,- "description": "Shows a pointer cursor. Does not add button semantics or keyboard interaction."+ "description": "Native styles applied to the rendered part."}]},@@ -5662,12 +5718,40 @@"defaultValue": null,"description": "Footer content, such as actions or supporting text."},+ {+ "name": "className",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "CSS class merged with the part class."+ },{"name": "divider","type": "boolean","required": false,"defaultValue": "true","description": "Shows the top border unless explicitly set to false."+ },+ {+ "name": "ref",+ "type": "Ref<HTMLDivElement>",+ "required": false,+ "defaultValue": null,+ "description": "Ref to the default div, or the element supplied through render."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Element or render callback composed through Base UI useRender. Supply native button or link attributes on the rendered owner."+ },+ {+ "name": "style",+ "type": "CSSProperties",+ "required": false,+ "defaultValue": null,+ "description": "Native styles applied to the rendered part."}]}diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scssindex 610bf786051..79b55b0269a 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss+++ b/packages/twenty-ui/src/primitives/surfaces/Card/Card.module.scss@@ -1,8 +1,16 @@+@use './CardOwner';+.card {+ @include CardOwner.card-owner;++ --card-section-background-color: initial;+background-color: var(--card-background-color, transparent);border: 1px solid var(--t-border-color-medium);border-radius: var(--t-border-radius-md);color: var(--t-font-color-secondary);+ font-size: inherit;+ font-weight: inherit;overflow: hidden;width: auto;diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scssindex 49e6da56c25..a4894bd8eff 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardContent.module.scss@@ -1,20 +1,19 @@-.cardContent {- background-color: var(--t-background-secondary);- padding: var(--t-spacing-4);+@use './CardOwner';- border-bottom: none;+.cardContent {+ @include CardOwner.card-owner;- cursor: default;+ background-color: var(+ --card-section-background-color,+ var(--t-background-secondary)+ );+ border: 0;+ font-size: inherit;+ font-weight: inherit;+ padding: var(--t-spacing-4);+ width: 100%;&[data-divider] {border-bottom: 1px solid var(--t-border-color-medium);}-- &[data-clickable] {- cursor: pointer;- }-- &[data-hover-highlight]:hover {- background: var(--t-background-transparent-light);- }}diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scssindex 6f62704e3d5..daa1288faf8 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardFooter.module.scss@@ -1,8 +1,17 @@+@use './CardOwner';+.cardFooter {- background-color: var(--t-background-primary);+ @include CardOwner.card-owner;++ background-color: var(+ --card-section-background-color,+ var(--t-background-primary)+ );+ border: 0;border-top: 1px solid var(--t-border-color-medium);font-size: var(--t-font-size-sm);padding: var(--t-spacing-2) var(--t-spacing-4);+ width: 100%;// divider defaults to true; only an explicit false removes the border&[data-no-divider] {diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scssindex 9dc125916ef..60b129ed7be 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardHeader.module.scss@@ -1,7 +1,16 @@+@use './CardOwner';+.cardHeader {- background-color: var(--t-background-primary);+ @include CardOwner.card-owner;++ background-color: var(+ --card-section-background-color,+ var(--t-background-primary)+ );+ border: 0;border-bottom: 1px solid var(--t-border-color-medium);font-size: var(--t-font-size-sm);font-weight: var(--t-font-weight-medium);padding: var(--t-spacing-2) var(--t-spacing-4);+ width: 100%;}diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss b/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scssnew file mode 100644index 00000000000..92d905abff6--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss@@ -0,0 +1,38 @@+@use '../../../styles/abstracts/mixins' as *;++@mixin card-owner {+ box-sizing: border-box;+ color: inherit;+ display: block;+ font-family: inherit;+ line-height: inherit;+ margin: 0;+ padding: 0;+ text-align: inherit;+ text-decoration: none;++ &:is(button, a[href], [role='button'], [role='link']) {+ @include focus-ring;++ cursor: pointer;++ &:focus-visible {+ outline-offset: -2px;+ }++ &:not(:disabled, [aria-disabled='true'], [data-disabled]) {+ @include hover-capable {+ &:hover {+ --card-section-background-color: transparent;++ background-color: var(--t-background-transparent-light);+ }+ }+ }++ &:is(:disabled, [aria-disabled='true'], [data-disabled]) {+ cursor: not-allowed;+ opacity: 0.5;+ }+ }+}diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsxindex 7b47e27b6d5..ecdf681895c 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/Card.stories.tsx@@ -1,6 +1,7 @@import { type Meta, type StoryObj } from '@storybook/react-vite';import { ComponentDecorator } from '@ui/testing';+import { Button } from '@ui/primitives/input/Button/Button';import { Card } from '@ui/primitives/surfaces/Card/Card';const meta: Meta<typeof Card.Root> = {@@ -9,13 +10,11 @@ const meta: Meta<typeof Card.Root> = {decorators: [ComponentDecorator],render: (args) => (<Card.Root {...args}>- <Card.Header>Lorem ipsum</Card.Header>+ <Card.Header>Customer import</Card.Header><Card.Content>- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec id massa- vel odio ullamcorper molestie eu nec ipsum. Sed semper convallis- consectetur.+ Review the imported customers before adding them to your workspace.</Card.Content>- <Card.Footer>Lorem ipsum</Card.Footer>+ <Card.Footer>24 customers are ready to import.</Card.Footer></Card.Root>),argTypes: {},@@ -25,3 +24,69 @@ export default meta;type Story = StoryObj<typeof Card.Root>;export const Default: Story = {};++export const NativeParts: Story = {+ render: (args) => (+ <Card.Root {...args} render={<article aria-label="Customer import" />}>+ <Card.Header render={<header />}>Customer import</Card.Header>+ <Card.Content render={<section aria-label="Ready customers" />} divider>+ 24 customers are ready to import.+ </Card.Content>+ <Card.Content render={<section aria-label="Customers to review" />}>+ Review 3 customers with missing email addresses.+ </Card.Content>+ <Card.Footer render={<footer />} divider={false}>+ Last checked just now.+ </Card.Footer>+ </Card.Root>+ ),+};++export const InteractiveContent: Story = {+ render: (args) => (+ <Card.Root {...args}>+ <Card.Header>Customer import</Card.Header>+ <Card.Content render={<button type="button" />} divider>+ Review 24 customers+ </Card.Content>+ <Card.Footer>Opens the customer review.</Card.Footer>+ </Card.Root>+ ),+};++export const WholeCardLink: Story = {+ render: (args) => (+ <Card.Root+ {...args}+ render={<a href="#customer-report" aria-label="Customer import report" />}+ >+ <Card.Header>Customer import</Card.Header>+ <Card.Content>Open the customer import report.</Card.Content>+ <Card.Footer>24 customers are ready.</Card.Footer>+ </Card.Root>+ ),+};++export const SeparateActions: Story = {+ render: (args) => (+ <Card.Root {...args} render={<article aria-label="Customer import" />}>+ <Card.Header>Customer import</Card.Header>+ <Card.Content+ render={+ <a+ href="#customer-report"+ aria-label="Open the customer import report"+ />+ }+ >+ Open the customer import report.+ </Card.Content>+ <Card.Footer style={{ display: 'flex', gap: 8 }}>+ <Button type="button">Import customers</Button>+ <Button type="button" variant="ghost">+ Cancel+ </Button>+ </Card.Footer>+ </Card.Root>+ ),+};diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsxnew file mode 100644index 00000000000..6a82f05793f--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx@@ -0,0 +1,300 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { createRef, useState } from 'react';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';++import { Button } from '@ui/primitives/input/Button/Button';+import { ComponentDecorator } from '@ui/testing';++import { Card } from '../Card';++const SeparateCardControls = () => {+ const [imported, setImported] = useState(false);++ return (+ <Card.Root render={<article aria-label="Customer import" />}>+ <Card.Header>Customer import</Card.Header>+ <Card.Content+ render={<a href="#card-report" aria-label="Open the report" />}+ >+ Open the report+ </Card.Content>+ <Card.Footer>+ <Button type="button" onClick={() => setImported(true)}>+ {imported ? 'Customers imported' : 'Import customers'}+ </Button>+ </Card.Footer>+ </Card.Root>+ );+};++const meta: Meta<typeof Card.Root> = {+ title: 'UI/Surfaces/Card/Interactions',+ component: Card.Root,+ tags: ['!autodocs'],+ decorators: [ComponentDecorator],+ args: { onClick: fn() },+};++export default meta;+type Story = StoryObj<typeof Card.Root>;++export const ButtonOwner: Story = {+ render: (args) => (+ <Card.Root {...args} render={<button type="button" />}>+ <Card.Content render={<span />}>Review import</Card.Content>+ </Card.Root>+ ),+ play: async ({ canvasElement, args }) => {+ const button = within(canvasElement).getByRole('button', {+ name: 'Review import',+ });++ button.focus();+ await userEvent.keyboard('{Enter}');+ await userEvent.keyboard(' ');++ await expect(args.onClick).toHaveBeenCalledTimes(2);+ await expect(button).toHaveFocus();+ await expect(button).toHaveAttribute('type', 'button');+ await expect(button).toHaveStyle({+ cursor: 'pointer',+ display: 'block',+ outlineWidth: '2px',+ outlineStyle: 'solid',+ });+ },+};++export const LinkOwner: Story = {+ render: (args) => (+ <>+ <Card.Root+ {...args}+ render={+ <a+ href="about:blank#card-report"+ target="card-report-target"+ aria-label="Open the import report"+ />+ }+ >+ <Card.Header>Customer import</Card.Header>+ <Card.Content>Open the import report</Card.Content>+ </Card.Root>+ <iframe+ hidden+ name="card-report-target"+ title="Import report destination"+ />+ </>+ ),+ play: async ({ canvasElement, args }) => {+ const link = within(canvasElement).getByRole('link', {+ name: 'Open the import report',+ });+ const destination = within(canvasElement).getByTitle<HTMLIFrameElement>(+ 'Import report destination',+ );++ link.focus();+ await userEvent.keyboard('{Enter}');++ await waitFor(() =>+ expect(destination.contentWindow?.location.hash).toBe('#card-report'),+ );+ await expect(args.onClick).toHaveBeenCalledTimes(1);+ await expect(args.onClick).toHaveBeenCalledWith(+ expect.objectContaining({ defaultPrevented: false }),+ );+ await expect(link).toHaveAttribute('href', 'about:blank#card-report');+ await expect(link).toHaveAttribute('target', 'card-report-target');+ await expect(link).not.toHaveAttribute('role');+ await expect(link).toHaveStyle({ textDecorationLine: 'none' });+ },+};++export const DisabledOwner: Story = {+ render: (args) => (+ <>+ <Button type="button">Before import</Button>+ <Card.Root {...args} render={<button type="button" disabled />}>+ <Card.Content render={<span />}>Import unavailable</Card.Content>+ </Card.Root>+ <Button type="button">After import</Button>+ </>+ ),+ play: async ({ canvasElement, args }) => {+ const canvas = within(canvasElement);+ const disabledCard = canvas.getByRole('button', {+ name: 'Import unavailable',+ });++ canvas.getByRole('button', { name: 'Before import' }).focus();+ await userEvent.tab();++ await expect(+ canvas.getByRole('button', { name: 'After import' }),+ ).toHaveFocus();+ await expect(disabledCard).toBeDisabled();+ await expect(disabledCard).toHaveStyle({ cursor: 'not-allowed' });++ await userEvent.click(disabledCard);++ await expect(args.onClick).not.toHaveBeenCalled();+ },+};++export const SeparateControls: Story = {+ render: () => <SeparateCardControls />,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const article = canvas.getByRole('article', { name: 'Customer import' });+ const link = canvas.getByRole('link', { name: 'Open the report' });+ const action = canvas.getByRole('button', { name: 'Import customers' });++ link.focus();+ await userEvent.tab();+ await userEvent.keyboard(' ');++ await expect(action).toHaveFocus();+ await expect(action).toHaveAccessibleName('Customers imported');+ await expect(article).not.toHaveAttribute('tabindex');+ await expect(article).not.toHaveAttribute('role');+ await expect(link).not.toContainElement(action);+ },+};++export const NativePartsAndRefs: Story = {+ render: (args) => {+ const rootRef = createRef<HTMLDivElement>();+ const headerRef = createRef<HTMLHeadingElement>();+ const contentRef = createRef<HTMLElement>();+ const footerRef = createRef<HTMLElement>();++ return (+ <>+ <Card.Root {...args} ref={rootRef}>+ <Card.Header+ render={+ <h2 ref={headerRef} tabIndex={-1}>+ Customer import+ </h2>+ }+ />+ <Card.Content+ render={(props) => (+ <section+ {...props}+ ref={contentRef}+ aria-label="Import summary"+ />+ )}+ tabIndex={-1}+ >+ 24 customers are ready.+ </Card.Content>+ <Card.Footer render={<footer ref={footerRef} />} tabIndex={-1}>+ Last checked just now.+ </Card.Footer>+ </Card.Root>+ <Button type="button" onClick={() => rootRef.current?.focus()}>+ Focus card+ </Button>+ <Button type="button" onClick={() => headerRef.current?.focus()}>+ Focus heading+ </Button>+ <Button type="button" onClick={() => contentRef.current?.focus()}>+ Focus summary+ </Button>+ <Button type="button" onClick={() => footerRef.current?.focus()}>+ Focus footer+ </Button>+ </>+ );+ },+ args: { tabIndex: -1 },+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ await userEvent.click(canvas.getByRole('button', { name: 'Focus card' }));+ await expect(canvas.getByRole('heading').parentElement).toHaveFocus();++ await userEvent.click(+ canvas.getByRole('button', { name: 'Focus heading' }),+ );+ await expect(+ canvas.getByRole('heading', { name: 'Customer import' }),+ ).toHaveFocus();++ await userEvent.click(+ canvas.getByRole('button', { name: 'Focus summary' }),+ );+ await expect(+ canvas.getByRole('region', { name: 'Import summary' }),+ ).toHaveFocus();++ await userEvent.click(canvas.getByRole('button', { name: 'Focus footer' }));+ await expect(canvas.getByText('Last checked just now.')).toHaveFocus();+ },+};++export const HoverOwners: Story = {+ tags: ['!dev'],+ render: () => (+ <>+ {[+ <button type="button" aria-label="Review import" />,+ <a href="#card-report" aria-label="Open report" />,+ <button type="button" aria-label="Import unavailable" disabled />,+ ].map((owner) => (+ <Card.Root key={owner.props['aria-label']} render={owner}>+ <Card.Header render={<span />}>Customer import</Card.Header>+ <Card.Content render={<span />}>24 customers are ready.</Card.Content>+ <Card.Footer render={<span />}>Last checked just now.</Card.Footer>+ </Card.Root>+ ))}+ </>+ ),+ play: async ({ canvasElement }) => {+ const { userEvent: trustedUserEvent } = await import('vitest/browser');+ const canvas = within(canvasElement);+ const sectionLabels = [+ 'Customer import',+ '24 customers are ready.',+ 'Last checked just now.',+ ];++ for (const owner of [+ canvas.getByRole('button', { name: 'Review import' }),+ canvas.getByRole('link', { name: 'Open report' }),+ ]) {+ await trustedUserEvent.hover(owner);++ await expect(owner).not.toHaveStyle({+ backgroundColor: 'rgba(0, 0, 0, 0)',+ });++ for (const sectionLabel of sectionLabels) {+ await expect(within(owner).getByText(sectionLabel)).toHaveStyle({+ backgroundColor: 'rgba(0, 0, 0, 0)',+ });+ }+ }++ const disabledOwner = canvas.getByRole('button', {+ name: 'Import unavailable',+ });++ await trustedUserEvent.hover(disabledOwner);++ await expect(disabledOwner).toHaveStyle({+ backgroundColor: 'rgba(0, 0, 0, 0)',+ });++ for (const sectionLabel of sectionLabels) {+ await expect(+ within(disabledOwner).getByText(sectionLabel),+ ).not.toHaveStyle({ backgroundColor: 'rgba(0, 0, 0, 0)' });+ }+ },+};diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsxindex 37a94d6929f..d356dc3e221 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx@@ -1,5 +1,7 @@import { render, screen } from '@testing-library/react';-import { describe, expect, it } from 'vitest';+import userEvent from '@testing-library/user-event';+import { createRef } from 'react';+import { describe, expect, it, vi } from 'vitest';import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';@@ -33,7 +35,44 @@ for (const { name, Component, ownClassName } of [element: <Component>Import summary</Component>,ownClassName,refInstanceOf: HTMLDivElement,- skip: ['ref', 'renderProp'],+ });++ it(`composes Card.${name} with a native button's attributes, handlers and ref`, async () => {+ const user = userEvent.setup();+ const nativeRef = createRef<HTMLButtonElement>();+ const onCardClick = vi.fn();+ const onButtonClick = vi.fn();++ render(+ <Component+ aria-describedby="import-description"+ onClick={onCardClick}+ render={+ <button+ type="button"+ name="import"+ value="ready"+ ref={nativeRef}+ onClick={onButtonClick}+ />+ }+ >+ Import records+ </Component>,+ );++ const button = screen.getByRole('button', { name: 'Import records' });++ expect(nativeRef.current).toBe(button);+ expect(button).toHaveAttribute('type', 'button');+ expect(button).toHaveAttribute('name', 'import');+ expect(button).toHaveAttribute('value', 'ready');+ expect(button).toHaveAttribute('aria-describedby', 'import-description');++ await user.click(button);++ expect(onCardClick).toHaveBeenCalledTimes(1);+ expect(onButtonClick).toHaveBeenCalledTimes(1);});}@@ -64,9 +103,7 @@ describe('Card rendering', () => {render(<Card.Root aria-label="Import summary" role="region"><Card.Header>Summary</Card.Header>- <Card.Content divider isClickable hasHoverHighlight>- Ready records- </Card.Content>+ <Card.Content divider>Ready records</Card.Content><Card.Content>Records to review</Card.Content><Card.Footer>Last checked</Card.Footer><Card.Footer divider={false}>Import actions</Card.Footer>@@ -88,23 +125,9 @@ describe('Card rendering', () => {'data-divider','true',);- expect(screen.getByText('Ready records')).toHaveAttribute(- 'data-clickable',- 'true',- );- expect(screen.getByText('Ready records')).toHaveAttribute(- 'data-hover-highlight',- 'true',- );expect(screen.getByText('Records to review')).not.toHaveAttribute('data-divider',);- expect(screen.getByText('Records to review')).not.toHaveAttribute(- 'data-clickable',- );- expect(screen.getByText('Records to review')).not.toHaveAttribute(- 'data-hover-highlight',- );expect(screen.getByText('Last checked')).not.toHaveAttribute('data-no-divider',);@@ -113,4 +136,28 @@ describe('Card rendering', () => {'true',);});++ it('keeps display cards presentational when they observe click events', async () => {+ const user = userEvent.setup();+ const onClick = vi.fn();++ render(+ <Card.Root onClick={onClick}>+ <Card.Content>Import summary</Card.Content>+ </Card.Root>,+ );++ const content = screen.getByText('Import summary');+ const root = content.parentElement;++ expect(root?.localName).toBe('div');+ expect(root).not.toHaveAttribute('role');+ expect(root).not.toHaveAttribute('tabindex');+ expect(screen.queryByRole('button')).not.toBeInTheDocument();+ expect(screen.queryByRole('link')).not.toBeInTheDocument();++ await user.click(content);++ expect(onClick).toHaveBeenCalledTimes(1);+ });});diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardContent.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardContent.tsxindex 52b1cf154c7..48cdc4ef3a2 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardContent.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardContent.tsx@@ -1,33 +1,23 @@+import { useRender } from '@base-ui/react/use-render';import { clsx } from 'clsx';-import { type ComponentPropsWithoutRef, type ReactNode } from 'react';-import styles from '../CardContent.module.scss';+import { type CardContentProps } from '../types/CardContentProps';-type CardContentProps = {- children?: ReactNode;- className?: string;- divider?: boolean;- isClickable?: boolean;- hasHoverHighlight?: boolean;-} & ComponentPropsWithoutRef<'div'>;+import styles from '../CardContent.module.scss';export const CardContent = ({- children,className,divider,- isClickable,- hasHoverHighlight,- ...rest-}: CardContentProps) => {- return (- <div- className={clsx(styles.cardContent, className)}- data-divider={divider || undefined}- data-clickable={isClickable || undefined}- data-hover-highlight={hasHoverHighlight || undefined}- {...rest}- >- {children}- </div>- );-};+ render,+ ref,+ ...props+}: CardContentProps) =>+ useRender({+ render,+ ref,+ props: {+ ...props,+ className: clsx(styles.cardContent, className),+ 'data-divider': divider || undefined,+ },+ });diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardFooter.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardFooter.tsxindex e92e7562cc9..9912a554b03 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardFooter.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardFooter.tsx@@ -1,25 +1,23 @@+import { useRender } from '@base-ui/react/use-render';import { clsx } from 'clsx';-import { type ComponentPropsWithoutRef } from 'react';-import styles from '../CardFooter.module.scss';+import { type CardFooterProps } from '../types/CardFooterProps';-type CardFooterProps = ComponentPropsWithoutRef<'div'> & {- divider?: boolean;-};+import styles from '../CardFooter.module.scss';export const CardFooter = ({- children,className,divider,- ...rest-}: CardFooterProps) => {- return (- <div- className={clsx(styles.cardFooter, className)}- data-no-divider={divider === false || undefined}- {...rest}- >- {children}- </div>- );-};+ render,+ ref,+ ...props+}: CardFooterProps) =>+ useRender({+ render,+ ref,+ props: {+ ...props,+ className: clsx(styles.cardFooter, className),+ 'data-no-divider': divider === false || undefined,+ },+ });diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardHeader.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardHeader.tsxindex 0f1959023af..56790ab8ec8 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardHeader.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardHeader.tsx@@ -1,18 +1,21 @@+import { useRender } from '@base-ui/react/use-render';import { clsx } from 'clsx';-import { type ComponentPropsWithoutRef } from 'react';-import styles from '../CardHeader.module.scss';+import { type CardHeaderProps } from '../types/CardHeaderProps';-type CardHeaderProps = ComponentPropsWithoutRef<'div'>;+import styles from '../CardHeader.module.scss';export const CardHeader = ({- children,className,- ...rest-}: CardHeaderProps) => {- return (- <div className={clsx(styles.cardHeader, className)} {...rest}>- {children}- </div>- );-};+ render,+ ref,+ ...props+}: CardHeaderProps) =>+ useRender({+ render,+ ref,+ props: {+ ...props,+ className: clsx(styles.cardHeader, className),+ },+ });diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsxindex c3b60f9c026..42c5cdbbc75 100644--- a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardRoot.tsx@@ -1,40 +1,36 @@+import { useRender } from '@base-ui/react/use-render';import { clsx } from 'clsx';-import { type ComponentPropsWithoutRef, type CSSProperties } from 'react';+import { type CSSProperties } from 'react';+import { isDefined } from '@ui/utilities/utils/isDefined';-import styles from '../Card.module.scss';+import { type CardRootProps } from '../types/CardRootProps';-type CardRootProps = ComponentPropsWithoutRef<'div'> & {- fullWidth?: boolean;- rounded?: boolean;- backgroundColor?: string;-};+import styles from '../Card.module.scss';export const CardRoot = ({- children,className,fullWidth,rounded,backgroundColor,style,- ...rest-}: CardRootProps) => {- return (- <div- className={clsx(styles.card, className)}- data-full-width={fullWidth || undefined}- data-rounded={rounded || undefined}- style={- isDefined(backgroundColor)- ? ({- ...style,- '--card-background-color': backgroundColor,- } as CSSProperties)- : style- }- {...rest}- >- {children}- </div>- );-};+ render,+ ref,+ ...props+}: CardRootProps) =>+ useRender({+ render,+ ref,+ props: {+ ...props,+ className: clsx(styles.card, className),+ 'data-full-width': fullWidth || undefined,+ 'data-rounded': rounded || undefined,+ style: isDefined(backgroundColor)+ ? ({+ ...style,+ '--card-background-color': backgroundColor,+ } as CSSProperties)+ : style,+ },+ });diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardContentProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardContentProps.tsnew file mode 100644index 00000000000..4f389ef1768--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardContentProps.ts@@ -0,0 +1,5 @@+import { type useRender } from '@base-ui/react/use-render';++export type CardContentProps = useRender.ComponentProps<'div'> & {+ divider?: boolean;+};diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardFooterProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardFooterProps.tsnew file mode 100644index 00000000000..a17e9532cfc--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardFooterProps.ts@@ -0,0 +1,5 @@+import { type useRender } from '@base-ui/react/use-render';++export type CardFooterProps = useRender.ComponentProps<'div'> & {+ divider?: boolean;+};diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardHeaderProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardHeaderProps.tsnew file mode 100644index 00000000000..0af6f45a95c--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardHeaderProps.ts@@ -0,0 +1,3 @@+import { type useRender } from '@base-ui/react/use-render';++export type CardHeaderProps = useRender.ComponentProps<'div'>;diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.tsnew file mode 100644index 00000000000..0ec20c0ae24--- /dev/null+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardRootProps.ts@@ -0,0 +1,7 @@+import { type useRender } from '@base-ui/react/use-render';++export type CardRootProps = useRender.ComponentProps<'div'> & {+ fullWidth?: boolean;+ rounded?: boolean;+ backgroundColor?: string;+};diff --git a/packages/twenty-ui/src/primitives/surfaces/index.ts b/packages/twenty-ui/src/primitives/surfaces/index.tsindex 85f2153e1d9..379a615a1c3 100644--- a/packages/twenty-ui/src/primitives/surfaces/index.ts+++ b/packages/twenty-ui/src/primitives/surfaces/index.ts@@ -35,6 +35,10 @@ export type { AlertDialogTriggerState } from './AlertDialog/types/AlertDialogTriexport type { AlertDialogViewportProps } from './AlertDialog/types/AlertDialogViewportProps';export type { AlertDialogViewportState } from './AlertDialog/types/AlertDialogViewportState';export { Card } from './Card/Card';+export type { CardContentProps } from './Card/types/CardContentProps';+export type { CardFooterProps } from './Card/types/CardFooterProps';+export type { CardHeaderProps } from './Card/types/CardHeaderProps';+export type { CardRootProps } from './Card/types/CardRootProps';export { Dialog } from './Dialog/Dialog';export type { DialogBackdropProps } from './Dialog/types/DialogBackdropProps';export type { DialogBackdropState } from './Dialog/types/DialogBackdropState';