Skip to content

Commit

Permalink
fix(form/inputs): fix bug with onRemove cb for TextBlock (#5061)
Browse files Browse the repository at this point in the history
This will fix a issue with the wrong path being sent to the delete function and
focus can now be called without a setTimeout because of a bugfix in the PortableTextEditor.
  • Loading branch information
skogsmaskin authored Nov 2, 2023
1 parent ddd25cd commit c64d0e2
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ export function TextBlock(props: TextBlockProps) {
}, [onItemOpen, memberItem])

const onRemove = useCallback(() => {
const sel: EditorSelection = {focus: {path, offset: 0}, anchor: {path, offset: 0}}
const point = {path: path.slice(-1), offset: 0}
const sel: EditorSelection = {
focus: point,
anchor: point,
}
PortableTextEditor.delete(editor, sel, {mode: 'blocks'})
// Focus will not stick unless this is done through a timeout when deleted through clicking the menu button.
setTimeout(() => PortableTextEditor.focus(editor))
}, [editor, path])
PortableTextEditor.focus(editor)
}, [path, editor])

const text = useMemo(() => {
return (
Expand Down

2 comments on commit c64d0e2

@vercel
Copy link

@vercel vercel bot commented on c64d0e2 Nov 2, 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 c64d0e2 Nov 2, 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.