The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Use Twenty UI buttons in Menu and Popover stories (#26001)
Raphaël Bosi186c9808160b
diff --git a/packages/twenty-ui/src/primitives/input/Button/Button.tsx b/packages/twenty-ui/src/primitives/input/Button/Button.tsxindex 463490b6113..2eb58d152a1 100644--- a/packages/twenty-ui/src/primitives/input/Button/Button.tsx+++ b/packages/twenty-ui/src/primitives/input/Button/Button.tsx@@ -41,7 +41,31 @@ export type ButtonProps = {ariaLabel?: string;ariaExpanded?: boolean;isLoading?: boolean;-} & Pick<React.ComponentProps<'button'>, 'type'> &+ 'data-base-ui-click-trigger'?: string;+ 'data-popup-open'?: string;+ 'data-pressed'?: string;+} & Pick<+ React.ComponentPropsWithRef<'button'>,+ | 'ref'+ | 'type'+ | 'role'+ | 'tabIndex'+ | 'style'+ | 'aria-label'+ | 'aria-expanded'+ | 'aria-controls'+ | 'aria-haspopup'+ | 'aria-disabled'+ | 'onFocus'+ | 'onBlur'+ | 'onKeyDown'+ | 'onKeyUp'+ | 'onMouseDown'+ | 'onMouseMove'+ | 'onMouseLeave'+ | 'onPointerDown'+ | 'onPointerEnter'+> &ClickOutsideAttributes;export const Button = ({@@ -67,7 +91,28 @@ export const Button = ({dataGloballyPreventClickOutside,hotkeys,ariaLabel,+ 'aria-label': nativeAriaLabel,ariaExpanded,+ 'aria-expanded': nativeAriaExpanded,+ 'aria-controls': ariaControls,+ 'aria-haspopup': ariaHasPopup,+ 'aria-disabled': ariaDisabled,+ 'data-base-ui-click-trigger': dataBaseUiClickTrigger,+ 'data-popup-open': dataPopupOpen,+ 'data-pressed': dataPressed,+ onFocus,+ onBlur,+ onKeyDown,+ onKeyUp,+ onMouseDown,+ onMouseMove,+ onMouseLeave,+ onPointerDown,+ onPointerEnter,+ ref,+ role,+ tabIndex,+ style,type,isLoading = false,}: ButtonProps) => {@@ -91,7 +136,10 @@ export const Button = ({)}><ButtonComponent+ ref={ref}id={id}+ role={role}+ tabIndex={tabIndex}className={clsx(styles.button,styles[size],@@ -106,17 +154,36 @@ export const Button = ({data-focus={isFocused || undefined}disabled={isDisabled}onClick={onClick}+ onKeyDown={onKeyDown}+ onKeyUp={onKeyUp}+ onMouseDown={onMouseDown}+ onMouseMove={onMouseMove}+ onMouseLeave={onMouseLeave}+ onPointerDown={onPointerDown}+ onPointerEnter={onPointerEnter}to={to}target={target}data-testid={dataTestId}data-click-outside-id={dataClickOutsideId}data-globally-prevent-click-outside={dataGloballyPreventClickOutside}- aria-label={ariaLabel}- aria-expanded={ariaExpanded}+ data-base-ui-click-trigger={dataBaseUiClickTrigger}+ data-popup-open={dataPopupOpen}+ data-pressed={dataPressed}+ aria-label={ariaLabel ?? nativeAriaLabel}+ aria-expanded={ariaExpanded ?? nativeAriaExpanded}+ aria-controls={ariaControls}+ aria-haspopup={ariaHasPopup}+ aria-disabled={ariaDisabled}type={type}- onFocus={() => setIsFocused(true)}- onBlur={() => setIsFocused(false)}- style={{ '--btn-justify': justify } as React.CSSProperties}+ onFocus={(event: React.FocusEvent<HTMLButtonElement>) => {+ setIsFocused(true);+ onFocus?.(event);+ }}+ onBlur={(event: React.FocusEvent<HTMLButtonElement>) => {+ setIsFocused(false);+ onBlur?.(event);+ }}+ style={{ ...style, '--btn-justify': justify } as React.CSSProperties}>{(isLoading || Icon) && (<ButtonIcon Icon={Icon} isLoading={!!isLoading} />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.tsxnew file mode 100644index 00000000000..9ebb9205d4e--- /dev/null+++ b/packages/twenty-ui/src/primitives/input/Button/__tests__/Button.test.tsx@@ -0,0 +1,31 @@+import { render, screen } from '@testing-library/react';+import { MemoryRouter } from 'react-router-dom';+import { describe, expect, it } from 'vitest';++import { ThemeProvider } from '@ui/theme-constants/ThemeProvider';++import { Button } from '../Button';++describe('Button', () => {+ it('ignores unsupported button attributes when rendered as a link', () => {+ const nativeButtonProps = { formAction: '/submit' };++ render(+ <MemoryRouter>+ <ThemeProvider colorScheme="light">+ <Button+ {...nativeButtonProps}+ to="/contacts"+ title="Contacts"+ ariaLabel="Contacts"+ />+ </ThemeProvider>+ </MemoryRouter>,+ );++ const link = screen.getByRole('link', { name: 'Contacts' });++ expect(link).toHaveAttribute('href', '/contacts');+ expect(link).not.toHaveAttribute('formaction');+ });+});diff --git a/packages/twenty-ui/src/primitives/surfaces/Menu/__stories__/Menu.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Menu/__stories__/Menu.stories.tsxindex 321da28e189..d18590dac99 100644--- a/packages/twenty-ui/src/primitives/surfaces/Menu/__stories__/Menu.stories.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Menu/__stories__/Menu.stories.tsx@@ -9,6 +9,7 @@ import {IconShare,IconTrash,} from '@ui/icon';+import { Button } from '@ui/primitives/input/Button/Button';import {A11Y_DEFER_COLOR_CONTRAST,CatalogDecorator,@@ -118,9 +119,12 @@ const MenuStory = ({ content = 'basic', ...props }: MenuStoryProps) => {return (<Menu.Root defaultOpen defaultTriggerId={triggerId} {...props}>- <Menu.Trigger id={triggerId} style={{ alignSelf: 'flex-start' }}>- Options- </Menu.Trigger>+ <Menu.Trigger+ id={triggerId}+ aria-label="Options"+ style={{ alignSelf: 'flex-start' }}+ render={<Button title="Options" />}+ /><Menu.Popup>{MENU_STORY_CONTENT[content]}</Menu.Popup></Menu.Root>);@@ -155,6 +159,36 @@ export const Documentation: Story = {args: { defaultOpen: false },play: undefined,};++export const DocumentationInteractions: Story = {+ ...Documentation,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const trigger = canvas.getByRole('button', { name: 'Options' });++ await userEvent.click(trigger);+ const menu = await body.findByRole('menu', { name: 'Options' });+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await expect(trigger).toHaveAttribute('aria-controls', menu.id);++ await userEvent.keyboard('{Escape}');+ await waitFor(() =>+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),+ );+ await expect(trigger).toHaveFocus();++ await userEvent.keyboard('{ArrowDown}');+ const reopenedMenu = await body.findByRole('menu', { name: 'Options' });+ await userEvent.click(+ within(reopenedMenu).getByRole('menuitem', { name: /Duplicate/ }),+ );+ await waitFor(() =>+ expect(body.queryByRole('menu')).not.toBeInTheDocument(),+ );+ await expect(trigger).toHaveFocus();+ },+};export const Selection: Story = {decorators: [ComponentDecorator],parameters: { container: { width: 240, height: 320 } },@@ -233,9 +267,11 @@ const MenuCatalogCell = ({ content = 'basic' }: MenuStoryProps) => {style={{ position: 'relative', width: 220, height: 230 }}><Menu.Root open triggerId={triggerId} modal={false}>- <Menu.Trigger id={triggerId} aria-label={`${content} options`}>- Options- </Menu.Trigger>+ <Menu.Trigger+ id={triggerId}+ aria-label={`${content} options`}+ render={<Button title="Options" />}+ /><Menu.Popup container={cellElement} side="bottom" align="start">{contentByType[content]}</Menu.Popup>diff --git a/packages/twenty-ui/src/primitives/surfaces/Popover/__stories__/Popover.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Popover/__stories__/Popover.stories.tsxindex cc9fc8a3643..775006529b8 100644--- a/packages/twenty-ui/src/primitives/surfaces/Popover/__stories__/Popover.stories.tsx+++ b/packages/twenty-ui/src/primitives/surfaces/Popover/__stories__/Popover.stories.tsx@@ -4,6 +4,7 @@ import { expect, fn, userEvent, waitFor, within } from 'storybook/test';import { IconX } from '@ui/icon';import { Button } from '@ui/primitives/input/Button/Button';+import { IconButton } from '@ui/primitives/input/IconButton/IconButton';import {A11Y_DEFER_COLOR_CONTRAST,CatalogDecorator,@@ -34,10 +35,10 @@ const PopoverStory = ({<><Popover.Root {...props}><Popover.Trigger+ aria-label="Open"style={{ alignSelf: 'flex-start', marginInline: 'auto' }}- >- Open- </Popover.Trigger>+ render={<Button title="Open" />}+ /><Popover.Popupside={side}align={align}@@ -48,9 +49,10 @@ const PopoverStory = ({<Popover.Title>Details</Popover.Title><Popover.Description>More information</Popover.Description><Button type="button" title="First action" ariaLabel="First action" />- <Popover.Close aria-label="Close" style={{ alignSelf: 'flex-start' }}>- <IconX size={16} />- </Popover.Close>+ <Popover.Close+ style={{ alignSelf: 'flex-start' }}+ render={<IconButton Icon={IconX} ariaLabel="Close" size="small" />}+ /></Popover.Popup></Popover.Root><Button type="button" title="Outside" ariaLabel="Outside" />@@ -128,15 +130,17 @@ export const Documentation: Story = {parameters: { container: { width: 240, height: 200 } },render: () => (<Popover.Root>- <Popover.Trigger style={{ alignSelf: 'flex-start' }}>- Show details- </Popover.Trigger>+ <Popover.Trigger+ aria-label="Show details"+ style={{ alignSelf: 'flex-start' }}+ render={<Button title="Show details" />}+ /><Popover.Popup><Popover.Title>Contact details</Popover.Title><Popover.Description>Add notes and contact information here.</Popover.Description>- <Popover.Close>Close</Popover.Close>+ <Popover.Close aria-label="Close" render={<Button title="Close" />} /></Popover.Popup></Popover.Root>),@@ -318,7 +322,7 @@ export const WithoutTabbableContent: Story = {args: {},render: (args) => (<Popover.Root {...args}>- <Popover.Trigger>Open</Popover.Trigger>+ <Popover.Trigger aria-label="Open" render={<Button title="Open" />} /><Popover.Popup><Popover.Title>Details</Popover.Title></Popover.Popup>