I am new to React/MUI, so a little help would be great.
I have a Stack of TextFields
, they are resizing with the screen width very nicely.
<Stack
direction="row"
sx={{
margin: "16px"
}}
>
<Stack sx={{ flexGrow: 1 }}>
<Box sx={{ flexWrap: "wrap" }}>
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
<TextField sx={{ width: "180px" }} />
</Box>
</Stack>
</Stack>
I am trying to put an action button that is:
- always aligned to the right of the screen
- always stays on the same row with at least one
TextField
(never on its own row) - does not take all vertical space (
TextFields
can be on top and to the left of it)
The closest I got is to wrap it in flex-inline
, block-inline
Box
, but I cannot always satisfy all the requirements.
Thank you!
2
Answers
Someone put a correct answer but then deleted it for whatever reason, therefore I am reposting it:
The
Stack
has a defaultflexDirection
ofcolumn
. You can change it torow
.To align to the right you can use
justifyContent: "end"
.For the minimal 2 at a row you can add a
minWidth: "360px"
which is twice the TextField width.