Is it possible to create dropdown where the layout has a sticky header and footer and the middle/content part is scrollable.
P.S. I was able to do it with setting the height, but that's not a feasable solution because it would stay always that same height even when the content is less.
I have created a stackblitz preview, please check out the example: https://stackblitz.com/edit/stackblitz-starters-qxjh28?file=src%2FApp.tsx
Yes, it is possible to create a dropdown with a sticky header and footer, and a scrollable middle/content part. In the provided code using
@floating-ui/react, you can achieve this behavior by making use of CSS and theposition: stickyproperty.To make the header and footer sticky, you can add the following CSS styles to the header and footer elements within the dropdown:
Here's the updated App component with the necessary CSS styles:
With the above CSS styles, the
<h3>elements inside the.dropdown-containerwill become sticky at the top and bottom respectively, creating the sticky header and footer effect. The middle/content part, represented by the<ul>element, will be scrollable when the content exceeds the available height.Please note that
position: stickyhas some browser compatibility considerations, so ensure that it works as expected in your target browsers. The provided CSS styles are suitable for modern web browsers that supportposition: sticky.