简体   繁体   English

如何正确溢出顺风下拉菜单?

[英]How to properly overflow a dropdown in tailwind?

I am trying to make the dropdown on the right overflow so that it is completely visible.我正在尝试使右侧溢出的下拉菜单完全可见。 I do not want to make the table bigger, I want the dropdown to be bigger than the table.我不想让表格变大,我希望下拉菜单比表格大。 I tried multiple different things with overflow and absolute/relative positioning but failed.我尝试了多种不同的溢出和绝对/相对定位但失败了。 What classes do I need to change to make it work?我需要更改哪些课程才能使其正常工作? I appreciate any inputs!我感谢任何输入!

Tailwind playground for testing: https://play.tailwindcss.com/0iiSxy59aP用于测试的 Tailwind 游乐场: https://play.tailwindcss.com/0iiSxy59aP

Cheers干杯

Removing overflow-x-auto in line 3 and overflow-hidden in line 5 fixed it!删除第 3 行中的 overflow-x-auto 和第 5 行中的 overflow-hidden 修复了它!

The accepted answer solves the problem.接受的答案解决了这个问题。 But there are cases when we actually need an overflow.但有些情况下我们确实需要溢出。

In such a scenario, we need to remove the current relative-absolute approach and can make use of this library在这种情况下,我们需要删除当前的relative-absolute方法,并可以利用这个

Setup useFloating Hook设置useFloating Hook

import { useFloating, shift } from "@floating-ui/react-dom";
   
const { x, y, reference, floating, strategy } = useFloating({
    placement: "bottom-start",
    middleware: [shift()],
  });

add reference ref in the button which triggers dropdown在触发下拉的按钮中添加reference ref

<button ref={reference} type="button""> Options </button>

add floating ref in the div which was previously made absolute在之前设为绝对的 div 中添加floating引用

 <div ref={floating}
          style={{
            position: strategy,
            top: y ?? "",
            left: x ?? "",
          }}> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM