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

Title block doesn't respect "Disable new blocks" restriction from DX Layout #6306

Open
avoinea opened this issue Sep 24, 2024 · 4 comments
Open

Comments

@avoinea
Copy link
Member

avoinea commented Sep 24, 2024

Describe the bug

Title-Layout.webm

To Reproduce

  1. Go to ControlPanel > Content Types
  2. Add new content type: Book
  3. Go to Layout for Book and enable editable blocks
  4. Click on Title block and then on Settings in the Sidebar
  5. Select "Disable new blocks" you will notice the "+" disappears and Save
  6. Go to Home Page and add a new Book
  7. Fill the Title block and press Enter.

Expected behavior
A new block should not be created when you press Enter in the Title block if it has "Disable new blocks"

Screenshots
If applicable, add screenshots to help explain your problem.

Software (please complete the following information):

  • OS: macOS
  • Browser Chrome
  • Volto Version 18.0.0-alpha.43
  • Plone Version 6.0.13
  • Plone REST API Version 9.7.2

Additional context

@MAX-786
Copy link
Contributor

MAX-786 commented Nov 11, 2024

Hi @avoinea , i came across the same issue! you got any lead on fixing it?

@avoinea
Copy link
Member Author

avoinea commented Nov 12, 2024

@MAX-786 Here is a starting point

onKeyDown={
!(blockHasOwnFocusManagement || disableNewBlocks)
? (e) =>
this.props.handleKeyDown(
e,
this.props.index,
this.props.id,
this.blockNode.current,
)
: null
}

@avoinea
Copy link
Member Author

avoinea commented Nov 12, 2024

vs

@MAX-786
Copy link
Contributor

MAX-786 commented Nov 12, 2024

thanks @avoinea and I looked briefly and i think problem for Title Block lies here:

const disableNewBlocks = useMemo(() => detached, [detached]);

So, i don't have solid idea about 'detached' but i think it checks for 'blockHasOwnFocusManagement', i might be wrong but doesn't matter and the solution would be simple with jsut adding new flag like 'disableNewBlocksByDefault' and check for both flags like

  const disableNewBlocksByDefault = useMemo(() => data?.disableNewBlocks, [data?.disableNewBlocks]);

And check for it here:

if (!disableNewBlocks) {
onSelectBlock(
onAddBlock(config.settings.defaultBlockType, index + 1),
);
}

Now for Text Block, i think it has to do with slate because if you enter when its empty and 'disableNewBlocks' is true, it removes the block itself instead of doing 'nothing' and when you type in something and press enter it adds new block which it should not.
This might be because slate is overriding the 'data' prop of 'Block/Edit' compnent which contains 'disableNewBlocks' flag and removes it.
So the fix for this might be more than one line fix but IG we can open new ticket targeting that issue and I can open a PR for fixing title issue separately?

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

No branches or pull requests

2 participants