Replies: 1 comment 1 reply
-
Hey, were you able to find any resolution for this issue ? EDIT : Found a way to do this. CustomMentionElement.tsximport type { Value } from '@udecode/plate-common';
import { getHandler } from '@udecode/plate-common';
import type { TMentionElement } from '@udecode/plate-mention';
import type { StyledElementProps } from '@udecode/plate-styled-components';
import { getRootProps } from '@udecode/plate-styled-components';
import React from 'react';
import { useFocused, useSelected } from 'slate-react';
import styled from 'styled-components';
import tw from 'twin.macro';
export const CustomMentionElement = <V extends Value>(
props: MentionElementProps<V>
) => {
const {
attributes,
children,
nodeProps,
element,
prefix,
onClick,
renderLabel,
} = props;
const rootProps = getRootProps(props) as any;
const selected = useSelected();
const focused = useFocused();
// const styles = getMentionElementStyles({ ...props, selected, focused });
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
<StyledSpan
selected={selected}
focused={focused}
{...attributes}
data-slate-value={element.value}
contentEditable={false}
onClick={getHandler(onClick, element)}
{...rootProps}
{...nodeProps}
>
{prefix}
{renderLabel ? renderLabel(element) : `@${element.mention_value}`}
{children}
</StyledSpan>
);
};
export interface MentionElementStyleProps<V extends Value>
extends MentionElementProps<V> {
selected?: boolean;
focused?: boolean;
}
// renderElement props
export interface MentionElementProps<V extends Value>
extends StyledElementProps<V, TMentionElement> {
/**
* Prefix rendered before mention
*/
prefix?: string;
onClick?: (mentionNode: any) => void;
renderLabel?: (mentionable: TMentionElement) => string;
}
const StyledSpan = styled.span<StyledSpanProps>`
${tw`my-0 mx-px align-baseline inline-block`}
${({ selected, focused }) =>
selected && focused && tw`shadow-[0 0 0 2px #B4D5FF]`}
padding: 1px 1px 1px;
border-radius: 4px;
font-size: 0.9em;
color: blue;
`;
type StyledSpanProps = {
selected?: boolean;
focused?: boolean;
}; config.tsexport const components = createPlateUI({
[ELEMENT_MENTION]: CustomMentionElement,
});
export const mentionPlugin = {
key: '@',
component: CustomMentionElement,
options: {
trigger: '@',
createMentionNode: (item: TComboboxItemBase) => ({
mention_uuid: item.key,
mention_value: item.text,
}),
},
}; EDIT 2 : change |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
We are using a custom mention element. We are encountering an issue when we try to delete multiple mention elements. The error can best be seen on this video:
Screen.Recording.2023-03-31.at.13.13.10.mov
The error is Cannot resolve a DOM node from Slate node: {"text":""}.
I could not reproduce this in Slate sandbox so I guess it is related to our custom mention component. This is the component code:
Any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions