themesberg / themesberg/flowbite

Flowbite multi-level dropdown does not display with external resource

Open
#238 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v1.6.3
Dominant language
HTML
Stars
9.4k
Forks
862
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/themesberg/flowbite/issues/86 where the component is already generated before the actual resource to fill the dropdown menu is loaded 🤔

Thank you for your help 🙏

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Flowbite multi-level dropdown documentation and compare the two JSFiddles, especially the difference between inline and externally fetched JSON. Check whether Flowbite initializes the generated dropdown before the Alpine.js fetch completes; done means both dropdown levels render from the external resource.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, tailwindcss
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.