Skip to content

Commit

Permalink
Fix primefaces#3454: Editor respect max length property
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 10, 2022
1 parent 0d0bc80 commit eb50f7b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 10 additions & 1 deletion components/lib/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ export const Editor = React.memo(
}
}

if (props.maxLength) {
const length = quill.current.getLength();

if (length > props.maxLength) {
quill.current.deleteText(props.maxLength, length);
}
}

if (props.onTextChange) {
props.onTextChange({
htmlValue: html,
Expand Down Expand Up @@ -213,5 +221,6 @@ Editor.defaultProps = {
headerTemplate: null,
onTextChange: null,
onSelectionChange: null,
onLoad: null
onLoad: null,
maxLength: null
};
3 changes: 0 additions & 3 deletions components/lib/editor/editor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ interface EditorSelectionChangeParams {
}

export interface EditorProps extends Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'ref'> {
id?: string;
value?: string;
style?: React.CSSProperties;
className?: string;
placeholder?: string;
readOnly?: boolean;
modules?: any;
Expand Down

0 comments on commit eb50f7b

Please sign in to comment.