Skip to content

Commit

Permalink
fix(form): open hotspot editor using focusPath (#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored Nov 9, 2023
1 parent fa7625d commit 5673f2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import React, {MouseEventHandler, ReactNode, useCallback, useEffect, useState} from 'react'
import {EllipsisVerticalIcon, CropIcon} from '@sanity/icons'
import {Button, Inline, Menu, Popover, useClickOutside, useGlobalKeyDown} from '@sanity/ui'
import {
Button,
Inline,
Menu,
Popover,
Text,
Tooltip,
useClickOutside,
useGlobalKeyDown,
} from '@sanity/ui'
import styled from 'styled-components'

export const MenuActionsWrapper = styled(Inline)`
Expand Down Expand Up @@ -82,14 +91,16 @@ export function ImageActionsMenu(props: ImageActionsMenuProps) {
return (
<MenuActionsWrapper data-buttons space={1} padding={2}>
{showEdit && (
<Button
aria-label="Open image edit dialog"
data-testid="options-menu-edit-details"
icon={CropIcon}
mode="ghost"
onClick={onEdit}
ref={setHotspotButtonElement}
/>
<Tooltip content={<Text size={1}>Crop image</Text>} padding={2}>
<Button
aria-label="Open image edit dialog"
data-testid="options-menu-edit-details"
icon={CropIcon}
mode="ghost"
onClick={onEdit}
ref={setHotspotButtonElement}
/>
</Tooltip>
)}
{/* Using a customized Popover instead of MenuButton because a MenuButton will close on click
and break replacing an uploaded file. */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,11 @@ export class BaseImageInput extends React.PureComponent<BaseImageInputProps, Bas
}

handleOpenDialog = () => {
const {onFieldOpen} = this.props
onFieldOpen('hotspot')
this.props.onPathFocus(['hotspot'])
}

handleCloseDialog = () => {
const {onFieldClose} = this.props
onFieldClose('hotspot')
this.props.onPathFocus([])

// Set focus on hotspot button in `ImageActionsMenu` when closing the dialog
this.state.hotspotButtonElement?.focus()
Expand Down Expand Up @@ -787,6 +785,7 @@ export class BaseImageInput extends React.PureComponent<BaseImageInputProps, Bas

render() {
const {
focusPath,
members,
renderAnnotation,
renderBlock,
Expand Down Expand Up @@ -851,7 +850,8 @@ export class BaseImageInput extends React.PureComponent<BaseImageInputProps, Bas
//@ts-expect-error all possible cases should be covered
return <>Unknown member kind: ${member.kind}</>
})}
{hotspotField?.open && (

{hotspotField && focusPath[0] === 'hotspot' && (
<FormInput
{...this.props}
absolutePath={hotspotField.field.path}
Expand Down

2 comments on commit 5673f2a

@vercel
Copy link

@vercel vercel bot commented on 5673f2a Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 5673f2a Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.