Skip to content

Commit

Permalink
update: change character_limit to be passed as a props( maxlength) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xjjda22 authored Dec 31, 2022
1 parent 6e65c98 commit e107039
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/lexical-playground/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export default function Editor(): JSX.Element {
</>
)}
{(isCharLimit || isCharLimitUtf8) && (
<CharacterLimitPlugin charset={isCharLimit ? 'UTF-16' : 'UTF-8'} />
<CharacterLimitPlugin
charset={isCharLimit ? 'UTF-16' : 'UTF-8'}
maxLength={5}
/>
)}
{isAutocomplete && <AutocompletePlugin />}
<div>{showTableOfContents && <TableOfContentsPlugin />}</div>
Expand Down
6 changes: 4 additions & 2 deletions packages/lexical-react/src/LexicalCharacterLimitPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ function utf8Length(text: string) {

export function CharacterLimitPlugin({
charset = 'UTF-16',
maxLength = CHARACTER_LIMIT,
}: {
charset: 'UTF-8' | 'UTF-16';
maxLength: number;
}): JSX.Element {
const [editor] = useLexicalComposerContext();

const [remainingCharacters, setRemainingCharacters] = useState(0);
const [remainingCharacters, setRemainingCharacters] = useState(maxLength);

const characterLimitProps = useMemo(
() => ({
Expand All @@ -64,7 +66,7 @@ export function CharacterLimitPlugin({
[charset],
);

useCharacterLimit(editor, CHARACTER_LIMIT, characterLimitProps);
useCharacterLimit(editor, maxLength, characterLimitProps);

return (
<span
Expand Down

2 comments on commit e107039

@vercel
Copy link

@vercel vercel bot commented on e107039 Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical – ./packages/lexical-website

lexical-fbopensource.vercel.app
lexical.dev
lexical-git-main-fbopensource.vercel.app
www.lexical.dev
lexicaljs.org
lexicaljs.com

@vercel
Copy link

@vercel vercel bot commented on e107039 Dec 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

lexical-playground – ./packages/lexical-playground

lexical-playground-git-main-fbopensource.vercel.app
lexical-playground-fbopensource.vercel.app
lexical-playground.vercel.app
playground.lexical.dev

Please sign in to comment.