material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[AppBar] height changes when trying to make content scrollable

Open nareshbhatia opened this issue 10 years ago • 5 comments

Problem description

I am trying to make the AppBar stick to the top while the content to be scrollable in the remaining height of the viewport. I am using flex: 1 1 auto for the content to take up the remaining height and overflow: auto to make it scrollable. However the AppBar is not able to keep its height of 64px. It is being squeezed out by the content.

Steps to reproduce

Modify two files in material-ui-webpack-example:

main.js

import React from 'react';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import AppBar from 'material-ui/AppBar';
import {Card, CardHeader, CardMedia} from 'material-ui/Card';

class Main extends React.Component {

    render() {
        return (
            <MuiThemeProvider>
                <div className="app-shell flex flex-column flex-auto">
                    <AppBar title="Material-UI" />

                    <div className="app-content overflow-auto flex flex-column flex-auto">
                        <Card>
                            <CardHeader title="Fracking is Clean?" />

                            <CardMedia>
                                <img src="http://www.naturalgaswatch.org/wp-content/uploads/2011/05/clean_glass_fracking_cartoon_051220115.jpeg" />
                            </CardMedia>
                        </Card>
                        <br/>
                        <Card>
                            <CardHeader title="Ayurvedic Medicine" />

                            <CardMedia>
                                <img src="http://easyayurveda.com/wp-content/uploads/2015/03/ayurvedic-medicines1.jpg" />
                            </CardMedia>
                        </Card>
                    </div>
                </div>

            </MuiThemeProvider>
        );
    }
}

export default Main;

main.css

html,
body {
    height: 100%;
    width: 100%;
}

html {
    font-family: 'Roboto', sans-serif;
}

body {
    margin: 0;
    font-size: 13px;
    line-height: 20px;
}

#app {
    height: 100%;
    display: flex;
}

.app-content {
    padding: 10px;
}

.overflow-auto {
    overflow: auto;
}

/* ---- Flexbox ---- */
.flex {
    display: flex
}

.flex-row {
    flex-direction: row
}

.flex-column {
    flex-direction: column
}

/* 1. Fix for Chrome 44 bug. https://code.google.com/p/chromium/issues/detail?id=506893 */
.flex-auto {
    flex: 1 1 auto;
    min-width: 0; /* 1 */
    min-height: 0; /* 1 */
}

Versions

  • Material-UI: 0.15.4
  • React: 15.3.1
  • Browser: Chrome 53.0.2785.89, Safari 9.1.2 (11601.7.7)

nareshbhatia avatar Sep 04 '16 03:09 nareshbhatia

I am having the same issue with tabs on Safari (Chrome works just fine). It seems that both these components need to fix their heights at the wrapper level to make them flexbox friendly. Am I missing something?

nareshbhatia avatar Sep 04 '16 14:09 nareshbhatia

I reproduced the appBar issue. It looks like you must give the appBar a percentage height. I added this class to the appBar flex-auto-appbar { flex: 1 1 auto; min-height: 9%; }

this seemed to solve the problem. Is this what you are looking for?

pratimary avatar Sep 22 '16 01:09 pratimary

I just wrapped the AppBar in another div and the problem went away, granted the div was really a View since it was integrated with some React Native compatible code.

mattferrin avatar Dec 12 '16 20:12 mattferrin

Set flex-shrink: 0 on the app bar

Zuurkern avatar Apr 24 '17 15:04 Zuurkern

We have been adding flex-shrink: 0 in the v1-beta branch.

oliviertassinari avatar Sep 11 '17 12:09 oliviertassinari