Skip to content
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

Context menu don´t work inside shadowDOM. #49

Open
bonafe opened this issue Mar 16, 2022 · 7 comments
Open

Context menu don´t work inside shadowDOM. #49

bonafe opened this issue Mar 16, 2022 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@bonafe
Copy link

bonafe commented Mar 16, 2022

If you create a component that extends HTMLElement and use shadowDOM, the context menus wont appear.
How to reproduce:

  1. Create a class that extends HTMLElement
  2. Create a ShadowDOM via: this.attachShadow({mode: 'open'});
  3. Create a svelt-jsoneditor inside this custom Element
  4. Context menu don´t work.

If you keep everthing the same but don´t use shadowDOM it works as expected.

@josdejong
Copy link
Owner

Thanks for reporting this issue Fernando.

Anyone able to look into this bug? Help would be welcome.

@josdejong josdejong added bug Something isn't working help wanted Extra attention is needed labels Mar 16, 2022
@vdwees
Copy link

vdwees commented Apr 12, 2023

hmm for me they work, at least with the current version.

I am using lit, however

@josdejong
Copy link
Owner

Thanks for your feedback @vdwees.

I tried to reproduce but can't get the editor working in Shadow DOM in the first place, it misses styling. Do you know how to add styling @vdwees?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />

    <title>JSONEditor | Shadow DOM</title>

    <script type="module">
      import { JSONEditor } from 'https://cdn.jsdelivr.net/npm/[email protected]/index.js'

      class JSONEditorElement extends HTMLElement {
        constructor() {
          super();

          // Create a shadow root
          const shadow = this.attachShadow({ mode: "open" });
          const target = document.createElement('div')
          shadow.append(target)

          const editor = new JSONEditor({
            target,
            props: {
              content: {
                json: [1, 2, 3]
              }
            }
          })
        }
      }

      // Define the new element
      customElements.define('json-editor', JSONEditorElement)
    </script>
  </head>
  <body>
    <h1>JSONEditor in Shadow DOM</h1>

    <json-editor></json-editor>
  </body>
</html>

@vdwees
Copy link

vdwees commented Apr 19, 2023 via email

@josdejong
Copy link
Owner

Ah, I see it indeed works when loading for example themes/jse-theme-default.css, thanks. I can now reproduce your issue with the following example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />

  <title>JSONEditor | Shadow DOM</title>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/jse-theme-default.css" />

  <script type="module">
    import { JSONEditor } from 'https://cdn.jsdelivr.net/npm/[email protected]/index.js'

    class JSONEditorElement extends HTMLElement {
      constructor() {
        super()

        const shadow = this.attachShadow({ mode: "open" })
        const target = document.createElement('div')

        const style = document.createElement('style')
        style.textContent = `
          div.shadow-dom-editor {
            width: 500px;
            height: 500px;
          }`
        shadow.appendChild(style)

        target.className = 'shadow-dom-editor'
        shadow.append(target)

        const editor = new JSONEditor({
          target,
          props: {
            content: {
              json: [1, 2, 3]
            }
          }
        })
      }
    }

    customElements.define('json-editor', JSONEditorElement)
  </script>
</head>
<body>
<h1>JSONEditor in Shadow DOM</h1>

<json-editor></json-editor>
</body>
</html>

The ContextMenu opens, but indeed nothing happens when you click an action. At first sight, it looks like the editor is not aware that it has focus. It may be easy to fix. I'll try to do some debugging soon, though help would be very welcome.

@thernstig
Copy link

@josdejong did you manage to look into this? :)

@josdejong
Copy link
Owner

No, help would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants