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

Mapping multiple slate editor, when deleting one of the array element the values are not correctly shows #5667

Open
arian0zen opened this issue Jun 25, 2024 · 0 comments
Labels

Comments

@arian0zen
Copy link

Description
I have an array of something, now i map the array to display a slate readOnly editor element for each element, but when I delete one of the array element, the value(initialValue) of that particular deleted editor is shifted to its next one, and next one's value shifted to next

Recording
please consider this loom
https://www.loom.com/share/0f2ce6560d2947fe936213ead567f905?sid=6b3d5b67-69b9-4754-af4e-635349d37401

Expectation
when i delete any element it should not shift other mapped element's initial value

Environment

  • Slate Version: [e.g. 0.59]
  • Operating System: [e.g. iOS]
  • Browser: [e.g. Chrome, Safari]

mapped code:

 {changelogLists.map((changelog: ChangelogType, index: number) => {
              return (
                <div
                  key={index}
                  className="-ml-8 py-4 px-12 flex flex-col gap-1 border-b border-gray-300"
                >
                  
                  <ChangelogCard
                    initialValue_={changelog.slateJsDescendantContent}
                  />
                </div>
              );
            })}

the slate editor card component:

const ChangelogCard = ({ initialValue_ }: ChangelogCardProps) => {
  const [initialValue] = useState<Descendant[]>(JSON.parse(initialValue_));
  const renderElement = useCallback((props: any) => <Element {...props} />, []);
  const renderLeaf = useCallback((props: any) => <Leaf {...props} />, []);
  const editor = useMemo(
    () => withImages(withHistory(withReact(createEditor()))),
    []
  );

  return (
    <Slate editor={editor} initialValue={initialValue}>
      <Editable
        className="relative w-full h-fit text-sm rounded-md overflow-y-auto max-h-[700px] thin-scrollbar"
        style={{
          outline: "none",
          whiteSpace: "pre-wrap",
        }}
        disableDefaultStyles={true}
        renderElement={renderElement}
        renderLeaf={renderLeaf}
        readOnly={true}
      />
    </Slate>
  );
};

note: I am open to any kind of feedback and suggestion, please help me fix this issue

@arian0zen arian0zen added the bug label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant