You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Framework7:弹窗中输入框触发Autocomplete组件显示层级问题求助

Fixing Framework7 Autocomplete Being Hidden Behind Modals

Got it, this is a super common issue with Framework7's Autocomplete component when used inside modals. The core problem is that the Autocomplete dropdown's default z-index is lower than the modal's, so it gets tucked behind the modal content and only becomes visible once you close the modal. Let's walk through a few solid solutions:

The cleanest way is to add a custom CSS class to your Autocomplete instance and bump its z-index above the modal's. Framework7 modals typically have a z-index around 2000, so we'll set ours higher to ensure it sits on top.

First, initialize the Autocomplete with the custom class:

// Target your input element inside the modal
const autocomplete = app.autocomplete.create({
  inputEl: '#modal-autocomplete-input',
  openIn: 'dropdown', // Make sure this is set to "dropdown" (critical for this fix!)
  cssClass: 'modal-autocomplete-fix', // Our custom class for z-index adjustment
  source: (query, render) => {
    // Example data source—replace with your own logic
    const matchingItems = ['Apple', 'Banana', 'Cherry', 'Date'].filter(item => 
      item.toLowerCase().includes(query.toLowerCase())
    );
    render(matchingItems);
  },
  // Add any other Autocomplete config you need (placeholder, etc.)
});

Then add this CSS to your stylesheet:

/* Force the dropdown to sit above the modal */
.modal-autocomplete-fix .autocomplete-dropdown {
  z-index: 2500 !important;
}

2. Override Global Autocomplete Styles (Quick Fix, Less Clean)

If you don't want to add a custom class, you can directly override the default Autocomplete dropdown z-index. Just note this will affect all Autocomplete instances in your app:

.autocomplete-dropdown {
  z-index: 2500 !important;
}

3. Initialize Autocomplete After Modal Opens

Sometimes if your modal is dynamically rendered, initializing the Autocomplete before the modal is fully open can cause z-index calculation issues. Fix this by listening for the modal's open event and initializing the component only after the modal is visible:

// Create your modal instance first
const myModal = app.modal.create({
  el: '#my-modal',
  on: {
    open: () => {
      // Initialize Autocomplete once the modal is fully open
      const autocomplete = app.autocomplete.create({
        inputEl: '#modal-autocomplete-input',
        openIn: 'dropdown',
        cssClass: 'modal-autocomplete-fix',
        source: (query, render) => {
          const items = ['Apple', 'Banana', 'Cherry'];
          render(items);
        }
      });
    }
  }
});

Quick Checks to Avoid Headaches

  • Double-check that openIn is set to dropdown—if you're using page mode, the Autocomplete will render as a full page, which won't play nicely with modals.
  • If your modal uses the modal-static class, its z-index might be higher than 2000—adjust the Autocomplete's z-index to match (e.g., 3000) if needed.

内容的提问来源于stack exchange,提问作者Raz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:33:44