The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Show shortcuts in command menu button tooltips (#26009)
Thomas des Francs845ed164a2b2
diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsxindex 9071061fd71..606545baded 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/CommandMenuItemRenderer.tsx@@ -58,7 +58,13 @@ const CommandMenuItemButtonRenderer = ({label,});- const command = { key: item.id, label, shortLabel, Icon };+ const command = {+ key: item.id,+ label,+ shortLabel,+ Icon,+ hotKeys: item.hotKeys,+ };if (isInPreviewMode) {return (diff --git a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsxindex 3e3122dd66f..bd333c6a7ab 100644--- a/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx+++ b/packages/twenty-front/src/modules/command-menu/components/CommandMenuButton.tsx@@ -1,7 +1,6 @@-import { styled } from '@linaria/react';-import { type MouseEvent } from 'react';+import { type MouseEvent, useId } from 'react';import { type Nullable } from 'twenty-shared/types';-import { isDefined } from 'twenty-shared/utils';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';import { type IconComponent } from 'twenty-ui/icon';import {AppTooltip,@@ -9,17 +8,13 @@ import {TooltipPosition,} from 'twenty-ui/primitives/surfaces';import { Button, IconButton } from 'twenty-ui/primitives/input';-import { themeCssVariables } from 'twenty-ui/theme-constants';--const StyledWrapper = styled.div`- font-size: ${themeCssVariables.font.size.md};-`;export type CommandMenuButtonProps = {command: {key: string;label: string;shortLabel?: Nullable<string>;+ hotKeys?: Nullable<string[]>;Icon: IconComponent;isPrimaryCTA?: boolean;};@@ -38,6 +33,13 @@ export const CommandMenuButton = ({isPrimaryAction = false,shouldHideLabel = false,}: CommandMenuButtonProps) => {+ const tooltipId = useId();+ const { hotKeys } = command;+ const hasHotKeys = isNonEmptyArray(hotKeys);+ const tooltipTitle = hasHotKeys+ ? `${command.label} (${hotKeys.join(' → ')})`+ : command.label;+const resolvedShortLabel =isDefined(command.shortLabel) && !shouldHideLabel? command.shortLabel@@ -47,9 +49,10 @@ export const CommandMenuButton = ({isPrimaryAction || command.isPrimaryCTA === true ? 'blue' : 'default';return (- <>+ <div data-tooltip-id={tooltipId}>{resolvedShortLabel !== undefined ? (<Button+ id={tooltipId}Icon={command.Icon}size="small"variant="primary"@@ -61,29 +64,32 @@ export const CommandMenuButton = ({ariaLabel={command.label}/>) : (- <div id={`command-menu-item-entry-${command.key}`} key={command.key}>- <IconButton- Icon={command.Icon}- size="small"- variant="primary"- accent={buttonAccent}- to={to}- onClick={onClick}- disabled={disabled}- ariaLabel={command.label}- />- <StyledWrapper>- <AppTooltip- anchorSelect={`#command-menu-item-entry-${command.key}`}- title={command.label}- delay={TooltipDelay.longDelay}- place={TooltipPosition.Bottom}- offset={5}- noArrow- />- </StyledWrapper>- </div>+ <IconButton+ id={tooltipId}+ Icon={command.Icon}+ size="small"+ variant="primary"+ accent={buttonAccent}+ to={to}+ onClick={onClick}+ disabled={disabled}+ ariaLabel={command.label}+ />+ )}+ {(hasHotKeys || !isDefined(resolvedShortLabel)) && (+ <AppTooltip+ anchorSelect={+ disabled+ ? `[data-tooltip-id='${tooltipId}']`+ : `[id='${tooltipId}']`+ }+ title={tooltipTitle}+ delay={TooltipDelay.longDelay}+ place={TooltipPosition.Bottom}+ offset={5}+ noArrow+ />)}- </>+ </div>);};diff --git a/packages/twenty-front/src/modules/command-menu/components/__tests__/CommandMenuButton.test.tsx b/packages/twenty-front/src/modules/command-menu/components/__tests__/CommandMenuButton.test.tsxnew file mode 100644index 00000000000..e28bd5383a6--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu/components/__tests__/CommandMenuButton.test.tsx@@ -0,0 +1,55 @@+import { CommandMenuButton } from '@/command-menu/components/CommandMenuButton';+import { render, screen } from '@testing-library/react';+import userEvent from '@testing-library/user-event';+import { MemoryRouter } from 'react-router-dom';+import { IconSearch } from 'twenty-ui/icon';++describe('CommandMenuButton', () => {+ it.each([+ {+ variant: 'labeled button',+ shortLabel: 'Search',+ to: undefined,+ role: 'button',+ },+ {+ variant: 'labeled link',+ shortLabel: 'Search',+ to: '/search',+ role: 'link',+ },+ {+ variant: 'icon button',+ shortLabel: undefined,+ to: undefined,+ role: 'button',+ },+ ])(+ 'shows the shortcut when tabbing to the $variant',+ async ({ shortLabel, to, role }) => {+ const user = userEvent.setup();++ render(+ <MemoryRouter>+ <CommandMenuButton+ command={{+ key: 'search',+ label: 'Search records',+ shortLabel,+ Icon: IconSearch,+ hotKeys: ['/'],+ }}+ to={to}+ />+ </MemoryRouter>,+ );++ await user.tab();++ expect(screen.getByRole(role, { name: 'Search records' })).toHaveFocus();+ expect(+ await screen.findByRole('tooltip', {}, { timeout: 2000 }),+ ).toHaveTextContent('Search records (/)');+ },+ );+});