Skip to content

Commit

Permalink
fix(core): restore platform-aware keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed May 30, 2024
1 parent 52e4cfa commit 85536c5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable camelcase */
import {Flex, Hotkeys, LayerProvider, Stack, Text} from '@sanity/ui'
import {Flex, LayerProvider, Stack, Text} from '@sanity/ui'
import {memo, useMemo, useState} from 'react'
import {
type DocumentActionComponent,
type DocumentActionDescription,
Hotkeys,
useTimelineSelector,
} from 'sanity'

Expand Down Expand Up @@ -35,6 +36,7 @@ function DocumentStatusBarActionsInner(props: DocumentStatusBarActionsInnerProps
{firstActionState.title && <Text size={1}>{firstActionState.title}</Text>}
{firstActionState.shortcut && (
<Hotkeys
data-testid="document-status-bar-hotkeys"
fontSize={1}
style={{marginTop: -4, marginBottom: -4}}
keys={String(firstActionState.shortcut)
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/ui-components/menuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Badge,
Box,
Flex,
Hotkeys,
MenuItem as UIMenuItem,
type MenuItemProps as UIMenuItemProps,
Stack,
Expand All @@ -21,6 +20,7 @@ import {
useMemo,
} from 'react'
import {isValidElementType} from 'react-is'
import {Hotkeys} from 'sanity'
import {styled} from 'styled-components'

import {Tooltip, type TooltipProps} from '..'
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/ui-components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import {
Box,
Flex,
Hotkeys,
type HotkeysProps,
Text,
Tooltip as UITooltip,
type TooltipProps as UITooltipProps,
} from '@sanity/ui'
import {type ForwardedRef, forwardRef} from 'react'
import {Hotkeys} from 'sanity'

import {TOOLTIP_DELAY_PROPS} from './constants'

Expand Down
14 changes: 14 additions & 0 deletions test/e2e/tests/document-actions/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ test(`document panel displays correct title for published document`, async ({
// Ensure the correct title is displayed before publishing.
await expect(page.getByTestId('document-panel-document-title')).toHaveText(title)

// Focus the publish button to trigger the tooltip showing the keyboard shortcut
page.getByTestId('action-Publish').focus()

// There is a delay before the tooltip opens, let's explicitly wait for it
await page.waitForTimeout(300)

// Now look for the tooltip to appear, with platform-aware keyboard shortcuts
// It'll have a data-testid of 'document-status-bar-hotkeys'
await page.waitForSelector('[data-testid="document-status-bar-hotkeys"]')
const hotkeys = page.getByTestId('document-status-bar-hotkeys')

const isMac = await page.evaluate(() => /Mac|iPod|iPhone|iPad/.test(navigator.platform || ''))
expect(hotkeys).toHaveText(isMac ? 'CtrlOptionP' : 'CtrlAltP')

// Wait for the document to be published.
page.getByTestId('action-Publish').click()
await expect(page.getByText('Published just now')).toBeVisible()
Expand Down

0 comments on commit 85536c5

Please sign in to comment.