Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `Fix` - Invoke tool `reset()` methods on `Tools.destroy()`, catching and logging any errors as warnings
- `Fix` - `blocks.insertMany()` now triggers `onChange` with a `block-added` event for each inserted block
- `Fix` - Inline Tools shortcuts work in every Editor instance on a page and are released when an Editor is destroyed
- `Fix` - Focus the contenteditable input when setting the caret, so autofocus works inside iframes

### 2.31.7

Expand Down
7 changes: 6 additions & 1 deletion src/components/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export default class SelectionUtils {
* @param element - element where to set focus
* @param offset - offset of cursor
*/
public static setCursor(element: HTMLElement, offset = 0): DOMRect {
public static setCursor(element: Node, offset = 0): DOMRect {
const range = document.createRange();
const selection = window.getSelection();

Expand All @@ -342,6 +342,11 @@ export default class SelectionUtils {
return element.getBoundingClientRect();
}

const editable = (element instanceof Element ? element : element.parentElement)
?.closest<HTMLElement>('[contenteditable="true"]');

editable?.focus({ preventScroll: true });

range.setStart(element, offset);
Comment thread
neSpecc marked this conversation as resolved.
Resolved
range.setEnd(element, offset);

Expand Down
12 changes: 12 additions & 0 deletions test/cypress/tests/initialization.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ describe('Editor basic initialization', () => {
});
});

describe('autofocus', () => {
it('should focus the first block input when true passed', () => {
cy.createEditor({
autofocus: true,
}).as('editorInstance');

cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.should('have.focus');
});
});

describe('style', () => {
describe('nonce', () => {
it('should add passed nonce as attribute to editor style tag', () => {
Expand Down
Loading