In base I have a list of filter chips. This chips are li
elements and placed in the ul
parent element:
<Stack
className={`${className} filter-list`}
width='100%'
component='ul'
padding={0}
margin={0}
spacing={1.5}
direction='row'
useFlexGap
flexWrap='wrap'>
<FilterButtonMolecule className='filter-list__filter-button' />
{currentFilters.map((filter) => (
<Box
className='filter-list__item'
component='li'
key={filter.id}
sx={{ listStyle: 'none' }}>
<FilterChipMolecule
className='filter-list__item-chip'
filter={filter}
/>
</Box>
))}
</Stack>
The flexWrap
and flexGap
properties are specifically applied in the parent ul
so that the children li
are moved depending on the size of the parent ul
. Everything works as intended.
But now I needed to add another button to the upper-right corner without breaking the moving of elements, e.g. :
Is this even possible?
I’m thinking now of removing the buttons from the list. Put them in the parent, which is made absolute. And add invisible chips to the list, which will displace visible chips from the upper corners. But I would like to ask for advice first.
2
Answers
I would step back and consider the semantics of your
<ul>
. As an unordered list, it should contain a list of items, like your filter tags. The icon buttons before and after the tag list aren’t really part of that list.In fact, your markup is invalid because the
<ul>
has direct children that aren’t list items (<li>
).So the short answer to your question is: you don’t. What you should do is restructure your markup to be valid and semantic. Something like:
Then only the list items wrap, which is what you want.
If you are not afraid of
float
, then use it: