What's the right way to float right or left using the material-ui appbar with material-ui-next?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



What's the right way to float right or left using the material-ui appbar with material-ui-next?



I can't figure out if I'm using the right approach to get the login/logout buttons to float right in while using material-ui-next ("material-ui": "^1.0.0-beta.22",)



It seems they removed iconElementRight= from the api. Do we have to use the <Grid> now in the appbar? It feels kinds of cludgy. What's the right way to float buttons (e.g. login) in the appbar?


iconElementRight=


<Grid>


<AppBar position="static">
<Toolbar>
<Grid container spacing=24>
<Grid item xs=11>
<Typography type="title" color="inherit">
Title
</Typography>
</Grid>

<Grid item xs=1>
<div>
<HeartIcon />
<Button raised color="accent">
Login
</Button>
</div>
</Grid>
</Grid>
</Toolbar>
</AppBar>



enter image description here




2 Answers
2



You need to add flex: 1 to your <Typography /> component so it pushes the <div /> to the rightmost part of the AppBar:


flex: 1


<Typography />


<div />


<AppBar position="static">
<Toolbar>
<Typography type="title" color="inherit" style= flex: 1 >
Title
</Typography>
<div>
<HeartIcon />
<Button raised color="accent">
Login
</Button>
</div>
</Toolbar>
</AppBar>





this sent me down a flexbox rabbit hole. I still don't quite get how this works but I should be able to figure it out
– Kyle Pennell
Dec 10 '17 at 21:43





I figured out this solution. "Flex: 1" means "flex-grow: 1" which means that the Typography element should receive all the used space, That pushes the icons, etc to the right.
– Iteria
Jul 8 at 21:39





I'd also add that if one wants to right-align a <Typography /> component, in addition to giving it the flexGrow: 1 style one should also add align: "right" to its props as seen in the API. The App Bar demo currently only demos right-aligned icons, not text.
– Felipe Maia
Aug 14 at 21:19



<Typography />


flexGrow: 1


align: "right"



@Kyle You had it right :)



just add to the grid container:



justify="space-between"



With your example:


<AppBar position="static">
<Toolbar>
<Grid
justify="space-between" // Add it here :)
container
spacing=24
>
<Grid item>
<Typography type="title" color="inherit">
Title
</Typography>
</Grid>

<Grid item>
<div>
<HeartIcon />
<Button raised color="accent">
Login
</Button>
</div>
</Grid>
</Grid>
</Toolbar>
</AppBar>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard