-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Cannot focus element inside content editable element #2717
Comments
I'm able to focus and type into a content editable paragraph with the following: cy.get("p")
.focus()
.type("hello") Do you have a code sample or any additional information that could help us debug? |
So typing works, but focus does not. For example, if you check this ProseMirror example if you focus on the content editable which is for example all text bold, you will see that the toolbar changes and detect that editor is focused and that content is bold. But if I do It does work if I create a selection manually: cy.window().then((window) => {
cy.get('.editor p').then(($el) => {
const el = $el.get(0);
const range = window.document.createRange();
range.setStart(el, 0);
range.setEnd(el, 0);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
});
}); |
Hey @mitar, the If you'd like to highlight text as you've shown above, that would require a branch new Cypress command. I'd suggest updating this issue to reflect that feature request if that's the case. |
I mean, focus on content edible is this. From the user perspective. If I click on content editable as an user, it makes a selection in the browser. So is Cypress API mimicking the user or the events? I thought high level calls like |
@mitar focus does not imply selection. for example in the DOM API, for text inputs, we have |
But in the context of content editable, when you click as user (not select) to focus, you are making a collapsed selection. I think you should really decide if |
@mitar calling calling .focus() places the cursor at the very start of the contenteditable. We do not cause a click side-effect because that would lead to a lot of confusion. We are actually changing this API in the next iteration:
|
@mitar ah, I see what you mean now. Calling focus on an element inside a contenteditable does not give that element focus, nor set we still will be able to append text to it with @mitar I think .focus() should remain as is, but we should consider this when adding text selection API to cypress |
The code for this is done in cypress-io/cypress#9066, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
If I try to
.get
a content editablep
element, I cannot use.focus()
to focus it, since calling.focus
on a DOM element inside a contenteditable will not give focus nor setdocument.activeElement
Desired behavior:
I should be able to focus content editable element to set cursor position to that element
Versions
Cypress: 3.1.1
OS: Linux Ubuntu 18.04
The text was updated successfully, but these errors were encountered: