Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/components/mui/formik-inputs/mui-formik-text-editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import { useField } from "formik";
import { InputLabel } from "@mui/material";
import TextEditorV3 from "../../inputs/editor-input-v3";
import { normalizeHtmlString } from "../../../utils/methods";

const FormikTextEditor = ({ name, label = "", options = {}, licence, ...props }) => {
const [field, meta, helpers] = useField(name);
const mergedOptions = { tabIndex: 0, allowTabNavigation: true, ...options };

return (
<>
{label && (
<InputLabel htmlFor={name}>
{label}
</InputLabel>
)}
<TextEditorV3
id={name}
value={field.value}
options={mergedOptions}
onChange={(e) => {
const stringValue = normalizeHtmlString(e.target.value);
helpers.setValue(stringValue);
}}
error={meta.touched && meta.error}
license={licence}
{...props}
/>
</>
);
};

export default FormikTextEditor;
6 changes: 6 additions & 0 deletions src/utils/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,9 @@ export const empty = (value) => {
};

export const isSentryInitialized = () => typeof window !== "undefined" && !!window.SENTRY_DSN;

export const normalizeHtmlString = (textInput) => {
if (!textInput) return "";
const doc = new DOMParser().parseFromString(textInput, "text/html");
return doc.body.textContent.trim().length === 0 ? "" : textInput;
};
Loading