Skip to content

Cannot focus on input element inside iframe when the editor has focus. #167

Closed
@tomoam

Description

@tomoam

Describe the problem

Cannot focus on input element inside iframe when the editor has focus.

focus_issue_480p.mov

This is probably related to #161.
I suppose the intent of #161 is to consider pointerdown event as a human operation. However, events that occur inside iframe cannot be handled from outside iframe.

<svelte:window
on:pointerdown={(e) => {
if (!container.contains(/** @type {HTMLElement} */ (e.target))) {
preserve_focus = false;
}
}}
/>

on:focusout={() => {
if (preserve_focus) {
setTimeout(() => {
instance?.editor.focus();
}, 0);
}
}}

Describe the proposed solution

when body element inside iframe gets focus, set focus on the editor. (using postMessage)

https://github.com/tomoam/learn.svelte.dev/blob/e291cb8c0d08f011d358427f7990fe7f2e6257d3/content/tutorial/common/src/__client.js#L93-L106

https://github.com/tomoam/learn.svelte.dev/blob/e291cb8c0d08f011d358427f7990fe7f2e6257d3/src/routes/tutorial/%5Bslug%5D/Editor.svelte#L236-L242

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions