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

Flowbite multi-level dropdown does not display with external resource #238

Open
mlapeyre3 opened this issue Aug 12, 2022 · 0 comments
Open
Labels
v1.6.3 Issues and tasks for v1.6.3 release

Comments

@mlapeyre3
Copy link

I am working on a simple HTML page using Alpine.js and TailwindCSS (with Flowbite). I have to display a two-level Dropdown button (I followed this implementation from Flowbite) which leverages a simple .json input coming from an external resource.

My first test with the .json input defined directly in the page is working properly (see this JSFiddle) as the dropdown button shows the two levels of items.
However, as soon as I switched to an external .json resource, only the first level is displayed (see this JSFiddle)
My implementation of Alpine.js looks pretty simple though. I might have missed something with the x-data="..." or x-init"..."

const directoryApp = () => ({
    directoryNOK: {},
  fetchDirectory() {
    fetch('https://myjson.dit.upm.es/api/bins/aagg')
      .then(response => response.json())
      .then(data => this.directoryNOK = data);
  },
});

<ul x-data="directoryApp()" x-init="fetchDirectory()" aria-labelledby="multiLevelDropdownButton">
  <template x-for="folder in directoryNOK.folders" :key="folder.id">
    <li>
      <a x-show="!folder.pages.length" href="#" x-text="folder.name"></a>
      <div x-show="folder.pages.length" x-id="['doubleDropdownButton', 'doubleDropdown']">
        <button :id="$id('doubleDropdownButton')" :data-dropdown-toggle="$id('doubleDropdown')" data-dropdown-placement="right-start" type="button"><div x-text="folder.name"></div></button>
        <div :id="$id('doubleDropdown')" class="hidden">
          <ul :aria-labelledby="$id('doubleDropdown')">
            <template x-for="page in folder.pages" :key="page.id">
              <li>
                <a x-text="page.name" :href="page.url"></a>
              </li>
            </template>
          </ul>
        </div>
      </div>
    </li>
  </template>
</ul>

I think this is similar to #86 where the component is already generated before the actual resource to fill the dropdown menu is loaded 🤔

Thank you for your help 🙏

@zoltanszogyenyi zoltanszogyenyi added the v1.6.3 Issues and tasks for v1.6.3 release label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1.6.3 Issues and tasks for v1.6.3 release
Projects
Development

No branches or pull requests

2 participants