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

PortableTextInput in a custom component #8451

Open
iamdangavin opened this issue Jan 29, 2025 · 2 comments
Open

PortableTextInput in a custom component #8451

iamdangavin opened this issue Jan 29, 2025 · 2 comments

Comments

@iamdangavin
Copy link

Trying to find any documentation or help in regard to using a PortableTextInput rather than a TextArea field within a custom component. Example:

import React, { useState } from "react";
import { Stack } from "@sanity/ui";
import { useClient, set, unset, PatchEvent, PortableTextInput } from "sanity";

const FileTranscriber = React.forwardRef((props, ref) => {
  const { elementProps, type, value, onChange } = props;
  const client = useClient();
  return (
    <Stack space={3}>
      {props.renderDefault(props)}
      <PortableTextInput />
    </Stack>
  )
})
@iamdangavin
Copy link
Author

Disregard, it appears if you are using the PortableTextInput within another schema type you need to do the following:

<PortableTextInput
  schemaType={{
    type: "array",
    of: [{ type: "block" }],
  }}
/>

@iamdangavin
Copy link
Author

While that does work and renders a field it requires the {...props} passed to it which then in turn produces this error after you start typing TypeError: JSON.stringify cannot serialize cyclic structures. so I am back to square one.

Additional context:
I want to have a file field that has a custom component with a Button + PortableTextInput. The button triggers an api call to transcribe the audio file and then pass that into the PortableTextInput. That would allow the admin/editor to edit the transcription.

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

No branches or pull requests

1 participant