Style block on Enter

This example shows how to get the current block after Enter and apply inline styles such as padding and border.

Code

<div id="entry-block-on-enter"></div>
const app = Redactor('#entry-block-on-enter', {});

app.on('key:up', ({ event, inEditable }) => {
    if (!inEditable || event.key !== 'Enter' || event.shiftKey || event.isComposing) return;

    const block = app.block.get();
    if (!block) return;

    block.setStyles({
        padding: '12px 16px',
        border: '1px solid #cbd5e1',
        borderRadius: '8px'
    });
});