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

Overriding the FieldContainer styling #240

Open
isaacoviedo opened this issue Jun 29, 2024 · 2 comments
Open

Overriding the FieldContainer styling #240

isaacoviedo opened this issue Jun 29, 2024 · 2 comments

Comments

@isaacoviedo
Copy link

Hello 👋

I'm trying to override the FieldContainer border styles applied when the component is focused - specifically these styles here. Can someone help suggest on how to go about doing this? I've tried using the RichTextFieldProps.classes prop on the RichTextEditor component but it doesn't seem to be doing the trick.

Currently my theme is making the border orange on focus which I'd like to change to black:
Screenshot

Current effort:

import React, { useRef } from "react";
import { LinkBubbleMenu, RichTextEditor, RichTextEditorRef, TableBubbleMenu } from "mui-tiptap";
import InputLabel from "@mui/material/InputLabel";
import Box from "@mui/material/Box";
import { makeStyles } from "@mui/styles";
import EditorMenuControls from "./EditorMenuControls";
import useExtensions from "./useExtensions";
import "./editor.css";

const useStyles = makeStyles({
  root: {
    "&.focused .notchedOutline": {
      borderColor: "black",
      borderWidth: 2,
    },
  },
});

const Editor = function ({
  label,
  required = false,
  error = false,
  value,
  onChange,
}: {
  label: string;
  required: boolean;
  error: boolean;
  value: string;
  // eslint-disable-next-line no-unused-vars
  onChange: (content: string) => void;
}) {
  const extensions = useExtensions({
    placeholder: "Add your own content here...",
  });

  const rteRef = useRef<RichTextEditorRef>(null);

  const styles = useStyles();

  return (
    <Box>
      <InputLabel required={required} error={error}>
        {label}
      </InputLabel>
      <RichTextEditor
        ref={rteRef}
        onUpdate={(props) => {
          onChange(props.editor.getHTML());
        }}
        extensions={extensions}
        content={value}
        renderControls={() => <EditorMenuControls />}
        RichTextFieldProps={{
          variant: "outlined",
          classes: {
            root: styles.root,
          },
        }}
      >
        {() => (
          <>
            <LinkBubbleMenu />
            <TableBubbleMenu />
          </>
        )}
      </RichTextEditor>
    </Box>
  );
};

export default Editor;
@mortmoe
Copy link
Contributor

mortmoe commented Jul 15, 2024

Struggling a bit with the same issue. Would it be a solution to add a color attribute to the RichTextEditor like a normal mui text-field? (so we can choose ie. "secondary")

@mortmoe
Copy link
Contributor

mortmoe commented Jul 16, 2024

A workaround I use for now is to just change the primary mui theme color for my component:

    const customTheme = createTheme({
        ...theme,
        palette: {
            ...theme.palette,
            primary: {
                main: theme.palette.secondary.main // or whatever color you want for the border
            }
        },
    })

    return (
        <ThemeProvider theme={customTheme}>
          <MyEditorComponent/>
        </ThemeProvider>
   )

Notice that this also changes the color of quite a few buttons around town... which is nice in my use-case but might not fit others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants