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

Dropdown menus in toolbar not working with bootstrap 5 #507

Open
hardik-kapadia opened this issue Aug 9, 2024 · 3 comments
Open

Dropdown menus in toolbar not working with bootstrap 5 #507

hardik-kapadia opened this issue Aug 9, 2024 · 3 comments

Comments

@hardik-kapadia
Copy link

The dropdowns in the toolbar of the the in place widget aren't working with Bootstrap 5.
The issue is pretty straightforward, these buttons have an attribute called data-toggle which needs to be data-bs-toggle. Replacing it seems to be working.

Not working:
image

Working:
image

I have checked everything else, there's no double jquery import, the event listeners are being attached too. This is the only apparent problem

@iragm
Copy link

iragm commented Oct 7, 2024

See summernote/summernote#4604

For now, add this code somewhere:

// Function to replace data-toggle with data-bs-toggle
function replaceDataToggle() {
    document.querySelectorAll('[data-toggle="dropdown"]').forEach(function(el) {
      el.setAttribute('data-bs-toggle', 'dropdown');
      el.removeAttribute('data-toggle');
    });
  }
  
  // Run on page load
  replaceDataToggle();
  
  // Observe for new elements added to the DOM
  const observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      if (mutation.addedNodes.length > 0) {
        replaceDataToggle(); // Replace in newly added elements
      }
    });
  });
  
  // Observe the entire document body for changes
  observer.observe(document.body, { childList: true, subtree: true });

I ran collectstatic and then dumped it into the top of /static/summernote/summernote-bs5.min.js before all the minified js

@hardik-kapadia
Copy link
Author

hardik-kapadia commented Nov 4, 2024

I have since switched from bs5 to Lite version but this wouldn't work as the summernote is being rendered after the page is loading and the function (A similar one I tried before) does not detect the element as the element is not yet present.
Tried a couple of things like, after element loading, deferring js execution, etc. nothing worked.

@iragm
Copy link

iragm commented Nov 4, 2024

The mutation observer I posted watches the document body so even stuff that's added later gets observed. It's working fine for me, maybe check the usual suspects like seeing if the js is actually firing and try with and without an iframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants