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

Set contentWidth to 100% #404

Open
KLeo13 opened this issue May 28, 2024 · 6 comments
Open

Set contentWidth to 100% #404

KLeo13 opened this issue May 28, 2024 · 6 comments

Comments

@KLeo13
Copy link

KLeo13 commented May 28, 2024

Hello,

I'm trying to set the default contentWidth into 100%. According to here, you can set it using the .setBodyValues. It works initially however, when I go to the Body options, it reverts back to 500px (dafault).

I've also tried adding some eventListener on design:updated however, the issue still persist with the only changes is, it returns to 100% once I leave the Body options

Is there a way I can retain the 100% contentWidth even if I'm in Body options?

Here's my code, its in nextjs .tsx

"use client"
import React, { useRef } from 'react';
import EmailEditor, { EditorRef, EmailEditorProps } from 'react-email-editor';

const EmailEditorComponent = () => {
  const emailEditorRef = useRef<EditorRef>(null);

  const onReady: EmailEditorProps['onReady'] = (unlayer) => {
    unlayer.setAppearance({
        theme: 'modern_dark'
    });
    unlayer.setBodyValues({
      contentWidth: '100%'
    })
    unlayer.addEventListener('design:updated', () => {
      unlayer.setBodyValues({
        contentWidth: '100%'
      })
    })
  };

  return (
    <div className='h-full'>
      <EmailEditor ref={emailEditorRef} onReady={onReady} minHeight={'100%'}/>
    </div>
  );
};

export default EmailEditorComponent;

Here are some screenshots
image
image

Thank you :)

@officialbatman
Copy link

I understand you're looking to maintain a 100% content width in the Unlayer Email Editor, specifically when working within the Body options. Can you try to passing the set body values in the onReady event:

const onReady: EmailEditorProps['onReady'] = (unlayer) => {
        unlayer.setBodyValues({
      contentWidth: '100%'
    })
});

@KLeo13
Copy link
Author

KLeo13 commented May 29, 2024

Hi @officialbatman, I tried passing only the .setBodyValues on onReady event and I still get the issue

"use client"
import React, { useRef } from 'react';
import EmailEditor, { EditorRef, EmailEditorProps } from 'react-email-editor';

const EmailEditorComponent = () => {
  const emailEditorRef = useRef<EditorRef>(null);

  const onReady: EmailEditorProps['onReady'] = (unlayer) => {
    unlayer.setBodyValues({
      contentWidth: '100%'
    })
  };

  return (
    <div>
      <EmailEditor ref={emailEditorRef} onReady={onReady} minHeight={'100vh'}/>
    </div>
  );
};

export default EmailEditorComponent;

record-2024-05-29_10.40.18.mp4

@KLeo13
Copy link
Author

KLeo13 commented May 29, 2024

I tried clicking the + button and it can only reach up to 900px' when i set the contentWidth` to 900px. It doesn't revert to 500px even when i go to Body Options.

Was the maximum contentWidth only 900px? Is setting it to 100% not possible yet?

@officialbatman
Copy link

Try passing the width for the body value in px. For email mode, 900px is the maximum limit achievable by default. Also, try the correct reference for your function, such as:

Screenshot 2024-05-29 at 11 05 13 AM

Your callback should be:

this.EditorRef.current?.setBodyValues({

@crezol2k
Copy link

crezol2k commented Aug 6, 2024

Can you try contentWidth: 'inherit'

@harshsavasil
Copy link

Thanks @crezol2k setting contentWidth to inherit works.

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

4 participants