Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/inline-tools/inline-tool-convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export default class ConvertInlineTool implements InlineTool {
return result;
}, []);

/**
* Do not show the "Convert to" item when there is nothing to convert to
*/
if (convertToItems.length === 0) {
return [];
}

const currentBlockToolboxItem = await currentBlock.getActiveToolboxEntry();
const icon = currentBlockToolboxItem !== undefined ? currentBlockToolboxItem.icon : IconReplace;
const isDesktop = !_.isMobileScreen();
Expand Down
9 changes: 9 additions & 0 deletions src/components/utils/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export async function getConvertibleToolsForBlock(block: BlockAPI, allBlockTools
return true;
});

/**
* Skip tools whose toolbox entries were all filtered out:
* such tools have nothing a block could be converted to,
* so they should not be treated as convertible
*/
if (actualToolboxItems.length === 0) {
return result;
}

result.push({
...tool,
toolbox: actualToolboxItems,
Expand Down
33 changes: 33 additions & 0 deletions test/cypress/tests/modules/InlineToolbar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,39 @@ describe('Inline Toolbar', () => {
});
});

describe('Conversion toolbar without convertible tools', () => {
it('should not show the convert-to item when there are no tools to convert to', () => {
/**
* Only the default paragraph tool is available,
* so the current block cannot be converted to anything
*/
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: 'Some text',
},
},
],
},
});

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.selectText('Some text');

/** Inline Toolbar should be opened with the usual inline tools */
cy.get('[data-cy="inline-toolbar"] .ce-popover__container')
.should('be.visible');

cy.get('[data-cy=editorjs]')
.get('[data-item-name=convert-to]')
.should('not.exist');
});
});

describe('Nested Editor instance inline toolbar', () => {
it('should not close inline toolbar of the nested Editor instance when clicking within that toolbar', () => {
cy.createEditor({
Expand Down