Skip to content

Iframes (browsing context containers) are focusable and should be focused if iframe child is focused #1619

@acusti

Description

@acusti

Spec

https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps (the 5th entry under focusing step 1)

If new focus target is a browsing context container with a non-null nested browsing context
Let new focus target be the browsing context container's nested browsing context's active document.

https://www.w3.org/TR/html5/editing.html#focus

When a child browsing context is focused, its browsing context container must also have focus.

Test

https://github.com/w3c/web-platform-tests/blob/master/html/editing/focus/document-level-focus-apis/document-level-apis.html

Required changes

In lib/jsdom/living/helpers/focusing.js:

  • exports.isFocusableAreaElement should return true iframe element. Could use something like:
  if (elImpl instanceof elImpl._ownerDocument._defaultView.HTMLIFrameElement) {
    return true;
  }

(using the defaultView's HTMLIFrameElement constructor means that if nested browsing contexts are ever made separate / sandboxed, the check will still work)

In lib/jsdom/living/nodes/HTMLElement-impl.js:

  • focus needs to recursively check ownerDocument.defaultView.parent and invoke .focus() on any parent HTMLIFrameElement:
    if (this._ownerDocument._defaultView._frameElement) {
      this._ownerDocument._defaultView._frameElement.focus();
    }
  • blur shouldn’t need to change, I don’t think. When a focusable element inside an iframe is blurred, the iframe element itself (the browsing context container) is still the activeElement of its parent.

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