Skip to content

fix(inline-toolbar): do not show "Convert to" when there is nothing to convert to - #3040

Open
playlikeboy wants to merge 1 commit into
codex-team:nextfrom
playlikeboy:fix/2833-hide-empty-convert-to
Open

playlikeboy wants to merge 1 commit into
codex-team:nextfrom
playlikeboy:fix/2833-hide-empty-convert-to

Conversation

@playlikeboy

Copy link
Copy Markdown

Summary

The inline toolbar shows a Convert to item even when there is nothing the current block can be converted to — it opens an empty submenu. As confirmed in #2833: "We should not show convertTo if there is no blocks to convert to."

This PR fixes that for the inline toolbar. (It does not make convertTo configurable via inlineToolbar — per the discussion in #2833 that part is not planned.)

Root cause

getConvertibleToolsForBlock() filters each candidate tool's toolbox entries (dropping entries that describe the current block itself, entries without icons, etc.) but then keeps the tool even when all of its entries were filtered out, leaving it with an empty toolbox.

Example: in an editor with only the default paragraph tool, the paragraph's single toolbox entry is filtered out (it describes the current block), yet the tool was still returned as "convertible".

ConvertInlineTool.render() only checked the number of convertible tools, not the number of resulting menu items, so it returned a Convert to item whose items list is empty. The block tunes menu (blockSettings.ts) already guards on the items count, which is why the bug only appeared in the inline toolbar.

Changes

  • src/components/utils/blocks.ts — getConvertibleToolsForBlock() now skips tools whose toolbox entries were all filtered out.
  • src/components/inline-tools/inline-tool-convert.ts — render() returns no item when there are no convert items, mirroring the existing guard in the block tunes menu.
  • test/cypress/tests/modules/InlineToolbar.cy.ts — regression test: with only the default paragraph tool available, selecting text opens the inline toolbar without a convert-to item.

Related issue

#2833 (the maintainer-confirmed part: Convert to must not be shown when there are no blocks to convert to)

Testing

  • eslint on all changed files: no errors. Full eslint src/ totals are identical before and after this change (257 problems — 23 errors / 234 warnings — pre-existing on next with the locally resolved toolchain).
  • vite build (production): passes.
  • vite build --mode test (build:test): passes.
  • New Cypress regression test added (see above). I could not run Cypress locally — the Cypress binary download does not complete in my sandbox — so the Cypress suite result is left to CI here; the test follows the existing patterns in the same spec file. The reproduction itself was verified against the published @editorjs/paragraph package (single toolbox entry without data, conversionConfig import/export text), which is exactly the case that produced an empty Convert to submenu.

…o convert to

The inline "Convert to" item was rendered even when no conversion
targets were available for the current block.

getConvertibleToolsForBlock() kept tools whose toolbox entries had all
been filtered out (for example the block's own tool, whose only toolbox
entry describes the block itself), leaving them with an empty toolbox.
ConvertInlineTool.render() then only checked the number of convertible
tools, not the number of resulting menu items, so it returned a
"Convert to" item with an empty items list. The block tunes menu in
blockSettings.ts already guards on the items count, which is why the
bug only appeared in the inline toolbar.

- utils/blocks: skip tools whose toolbox entries were all filtered out
- inline-tool-convert: return no item when there are no convert items,
  mirroring the existing guard in the block tunes menu

Adds a Cypress regression test: with only the default paragraph tool
available, the inline toolbar opens without a convert-to item.

Related to codex-team#2833

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant