Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve inline blocks to be able to easily access a block in context #1536

Closed
chrisdmacrae opened this issue Oct 8, 2020 · 0 comments · Fixed by #1538
Closed

Improve inline blocks to be able to easily access a block in context #1536

chrisdmacrae opened this issue Oct 8, 2020 · 0 comments · Fixed by #1538
Labels
enhancement New feature or request

Comments

@chrisdmacrae
Copy link
Contributor

chrisdmacrae commented Oct 8, 2020

Summary

I want to render a tooltip on the focussed inline block when it is focussed. Right now, it's hard to figure this out, because in the context of a block, you only know what index of the block is, and the form name is dictated by the implementation of InlineBlocks, and can only be well-known at runtime.

I'd like an InlineBlock to receive name of the parent blocks instance. I'd also be able to do useInlineField and get the closest field in the context of the hook.

Basic example

For example:

export const ExampleBlocks = () => {
const [,form] = useForm(MyBlocksData);

return (
  <InlineForm form={form}>
    <InlineBlocks
      name="blocks"
      blocks={MyBlocks}
    />
  </InlineForm>
}

export const MyBlocksData = {
  blocks: [
    { _template: Example }
  ]
}

export const MyBlocks = {
  Example: {
    component: (props) => <div>{props.name}.{props.index}</div>
  }
}

In this case, my "Example" block would receive name as blocks.0.

Alternatively, I could just call useInlineField inside the block and get the name off of the context returned:

export type useInlineField: () => InlineField;

Motivation

Allow people to easily add inline form functionality to a block without having to have an extremely intimate understanding of how the form field inheritance works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant