Skip to content

Commit

Permalink
[form-builder] Use FocusManager with inline items (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed May 23, 2018
1 parent bdc174e commit 69e3bbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types'
import React from 'react'
import FormBuilderPropTypes from '../../FormBuilderPropTypes'
import FocusManager from '../../sanity/focusManagers/SimpleFocusManager'

export default class ItemForm extends React.PureComponent {
static propTypes = {
Expand Down Expand Up @@ -31,6 +32,20 @@ export default class ItemForm extends React.PureComponent {
return <div>No input component resolved for type {`"${type.name}"`}</div>
}

return <InputComponent value={value} type={type} level={level} onChange={this.handleChange} />
return (
<FocusManager>
{({onFocus, onBlur, focusPath}) => (
<InputComponent
value={value}
type={type}
level={level}
onChange={this.handleChange}
onFocus={onFocus}
focusPath={focusPath}
onBlur={onBlur}
/>
)}
</FocusManager>
)
}
}
16 changes: 15 additions & 1 deletion packages/test-studio/schemas/blocks.js
Expand Up @@ -153,7 +153,21 @@ export default {
title: 'Customized with block types',
type: 'array',
of: [
{type: 'image', title: 'Image', options: {inline: true}},
{
type: 'image',
title: 'Image',
fields: [
{title: 'Caption', name: 'caption', type: 'string', options: {isHighlighted: true}},
{
title: 'Authors',
name: 'authors',
type: 'array',
options: {isHighlighted: true},
of: [{type: 'author', title: 'Author'}]
}
],
options: {inline: true}
},
{type: 'author', title: 'Author'},
{
type: 'block',
Expand Down

0 comments on commit 69e3bbd

Please sign in to comment.