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
6 changes: 2 additions & 4 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default class Toolbar extends Module<ToolbarNodes> {
* Move Toolbar to the Top coordinate of Block
*/
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.nodes.wrapper!.style.top = `${Math.floor(toolbarY)}px`;
this.nodes.wrapper!.style.top = `${Math.max(0, Math.floor(toolbarY))}px`;

/**
* Do not show Block Tunes Toggler near single and empty block
Expand Down Expand Up @@ -411,9 +411,7 @@ export default class Toolbar extends Module<ToolbarNodes> {
*/
private async make(): Promise<void> {
this.nodes.wrapper = $.make('div', this.CSS.toolbar);
/**
* @todo detect test environment and add data-cy="toolbar" to use it in tests instead of class name
*/
this.nodes.wrapper.dataset.cy = 'toolbar';

/**
* Make Content Zone and Actions Zone
Expand Down
54 changes: 54 additions & 0 deletions test/cypress/tests/ui/Toolbar.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
describe('Toolbar', () => {
it('should not be placed above the editor when the first input is shifted up', () => {
class OffsetTool {
public static get isReadOnlySupported(): boolean {
return true;
}

private text: string;

constructor({ data }: { data: { text?: string } }) {
this.text = data?.text ?? 'Text';
}

public render(): HTMLElement {
const wrapper = document.createElement('div');

wrapper.innerHTML = '<div contenteditable="true" style="position: relative; top: -120px;">Text</div>';

return wrapper;
}

public save(): { text: string } {
return { text: this.text };
}
}

cy.createEditor({
tools: {
offset: OffsetTool,
},
data: {
blocks: [
{
type: 'offset',
data: { text: 'Text' },
},
],
},
}).then((editor) => {
editor.caret.focus();
cy.wait(200);
editor.toolbar.open();

cy
.get('[data-cy=toolbar]')
.first()
.should(($toolbar) => {
const top = parseInt($toolbar[0].style.top, 10);

expect(top).to.be.at.least(0);
});
});
});
});
Loading