Skip to content

Add support for Custom Element #6652

@vtsvetkov-splunk

Description

@vtsvetkov-splunk

Context

I added Custom Elements with shadow root via custom elements because I don't want the styles of mkdocs has influence on forms I am adding. When I have a form inside my custom component, the global keyboard handler catches some keys I am typing like s and takes focus to search.
The reason is if there is input focused inside the shadow root, the parent's document.activeElement would point to the custom element itself, not to it's underlying element.

Since 'the bug' is caused by extra javascript, I cannot mark it as a bug, so I am asking about adding support for custom elements.

Description

While having additional functionality via extra_javascript is a great feature, it lacks a full support for adding custom elements. I was able to add the custom element, but the keyboard shortcut is not aware about such type of element.
There is a check for activeElement which works differently for elements with shadowRoot. I am asking to add support for such kind of elements here:

export function getActiveElement(): HTMLElement | undefined {
return document.activeElement instanceof HTMLElement
? document.activeElement || undefined
: undefined
}

The active element of shadowRoot can be accessed via document.activeElement.shadowRoot.activeElement.

Related links

Use Cases

It will allow to have forms inside custom elements

Visuals

No response

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions