Skip to content

Commit

Permalink
fix(form-builder): update portable text block style on style change
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed May 17, 2021
1 parent 9cee365 commit 917fd80
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import classNames from 'classnames'
import React, {useCallback} from 'react'
import {Path, SchemaType} from '@sanity/types'
import {FOCUS_TERMINATOR, toString as pathToString} from '@sanity/util/paths'
import {FOCUS_TERMINATOR} from '@sanity/util/paths'
import {resolveInitialValueForType} from '@sanity/initial-value-templates'
import {useToast} from '@sanity/ui'
import ActionMenu from './ActionMenu'
Expand Down Expand Up @@ -118,11 +118,7 @@ function PTEToolbar(props: Props) {
[editor, selection, handleInsertAnnotation, hotkeys]
)
const actionsLen = actionGroups.reduce((acc, x) => acc + x.actions.length, 0)
const selectedPath = selection?.anchor?.path && pathToString(selection.anchor.path)
const blockStyleSelectProps = React.useMemo(
() => (editor ? getBlockStyleSelectProps(editor, selectedPath) : null),
[editor, selectedPath]
)
const blockStyleSelectProps = editor ? getBlockStyleSelectProps(editor) : null

const insertMenuItems = React.useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ export function getPTEToolbarActionGroups(
}

export function getBlockStyleSelectProps(
editor: PortableTextEditor,
selectedPath?: string
editor: PortableTextEditor
): {items: BlockStyleItem[]; value: BlockStyleItem[]} {
const features = PortableTextEditor.getPortableTextFeatures(editor)
const items = features.styles.map((style: PortableTextFeature) => {
Expand Down

0 comments on commit 917fd80

Please sign in to comment.