最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to fix styling on react-select dropdown when using menuPortalTarget - Stack Overflow

programmeradmin0浏览0评论

When I use menuPortalTarget it breaks the styling on my dropdown. Here is a codesandbox showing the problem. In the codesandbox I have a button to toggle menuPortalTarget. When menuPortalTarget is active and you open the dropdown you can see the messed up styling vs when its not active.

I tried playing around with the parent styling and the menuPortal styling but I couldn't get it working.

This example is based off this from the react-select docs.

When I use menuPortalTarget it breaks the styling on my dropdown. Here is a codesandbox showing the problem. In the codesandbox I have a button to toggle menuPortalTarget. When menuPortalTarget is active and you open the dropdown you can see the messed up styling vs when its not active.

I tried playing around with the parent styling and the menuPortal styling but I couldn't get it working.

This example is based off this from the react-select docs.

Share Improve this question edited Jun 13, 2021 at 1:06 Antespo asked Jun 11, 2021 at 22:41 AntespoAntespo 1491 gold badge2 silver badges9 bronze badges 1
  • Facing similar issue too. This worked for me enter link description here. – Shrey Marwaha Commented Sep 23, 2022 at 22:22
Add a ment  | 

2 Answers 2

Reset to default 2

You can try this

const selectStyles = {
  control: (provided) => ({ ...provided, minWidth: 240, margin: 8 }),
  menu: () => ({ boxShadow: "inset 0 1px 0 rgba(0, 0, 0, 0.1)" }),
  menuPortal: () => ({ zIndex: "1000", width: "240px", position: "absolute", top: "214px", backgroundColor: "white", left: "17px", boxShadow: "inset 0 1px 0 rgba(0, 0, 0, 0.1)" })
};

What worked for me:

<Select menuPosition="fixed" />

发布评论

评论列表(0)

  1. 暂无评论