Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tabs] Align left #4420

Closed
MattKetmo opened this issue Jun 4, 2016 · 8 comments · Fixed by #5604
Closed

[Tabs] Align left #4420

MattKetmo opened this issue Jun 4, 2016 · 8 comments · Fixed by #5604
Labels
component: tabs This is the name of the generic UI component, not the React module!

Comments

@MattKetmo
Copy link

Description

Using full width to display tabs is not always the best experience especially when width is large (like on desktop or tablet) and there is few tabs.

It would be nice to have an option to have tabs aligned on the left instead of centered.

Even better tabs could be auto aligned on left or center according to the current container width and scroll would auto activate when this width is too small.

Images & references

This is the how tabs are currently displayed on "large" screen:

capture d ecran 2016-06-04 a 18 02 51

This is what I'd like to have:

capture d ecran 2016-06-04 a 18 02 45

An other example using Polymer paper tabs (in a toolbar):

capture d ecran 2016-06-04 a 17 54 38

And with Angular material:

capture d ecran 2016-06-04 a 17 44 48

@mbrookes
Copy link
Member

mbrookes commented Jun 4, 2016

@MattKetmo:

      <div style={{backgroundColor: 'sameAsTabs'}}>
        <Tabs value={window.location.pathname} style={{width: 200, float: 'left'}}>
          <Tab
            label="Item One"
            value="/"
            onActive={this.handleActiveTab}
          />
          <Tab
            label="Item Two"
            value="/item2"
            onActive={this.handleActiveTab}
          />
        </Tabs>
      </div>

This sets the Tabs container to the desired width. Alternatively you can probably set each tab to a fixed width, but I didn't try.

@MattKetmo
Copy link
Author

Well… that's more a hack than a real solution. I don't want to force a fixed width to the tabs nor the container (and forcing a tab width will break the ink bar). I'd rather want it to naturally fit what's inside the tabs (text or icon) instead of expanding to max width.

@mbrookes
Copy link
Member

mbrookes commented Jun 5, 2016

@MattKetmo

Yes, it's a workaround for sure.

GAumala added a commit to GAumala/material-ui that referenced this issue Sep 30, 2016
The fixedTabWidth property sets a fixed width to each tab label and aligns them
to the left instead of using full width. If the prop is not set, behavior is
back to normal. This solves issue mui#4420.

The docs have also been updated with information and an example for this prop.
GAumala added a commit to GAumala/material-ui that referenced this issue Sep 30, 2016
The fixedTabWidth property sets a fixed width to each tab label and aligns them
to the left instead of using full width. If the prop is not set, behavior is
back to normal. This solves issue mui#4420.

The docs have also been updated with information and an example for this prop.
GAumala added a commit to GAumala/material-ui that referenced this issue Oct 17, 2016
The Tab component has a new prop of type number: labelWidth. This number
is the width of the label in pixels. The user must either set this prop
to every tab or none. If this condition is not met, the ink bar is not
drawn, and a warning is displayed in the console.

The docs have also been updated with information and an example for this
prop.

This solves issue mui#4420. This approach was suggested in mui#5301.
GAumala added a commit to GAumala/material-ui that referenced this issue Oct 19, 2016
The Tab component has a new prop of type number: labelWidth. This number
is the width of the label in pixels. The user must either set this prop
to every tab or none. If this condition is not met, the ink bar is not
drawn, and a warning is displayed in the console.

The Tabs directory has a new file: TabUtils.js. For now this file
has a single function: calculateTabWidthAndInkbarPosition which is
necessary now that widths are variable. A test for this function has
been written in the TabUtils.spec.js file.

The docs have also been updated with information and an example for this
prop.

This solves issue mui#4420. This approach was suggested in mui#5301.
@oliviertassinari oliviertassinari added component: tabs This is the name of the generic UI component, not the React module! and removed component: tabs This is the name of the generic UI component, not the React module! labels Oct 19, 2016
@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 22, 2016

An initial migration of the Tabs component has been merged on the next branch.
That feature was implemented and is now the default behavior.
Thanks for providing those details.

@pavanmehta91
Copy link

@mbrookes I can't get the desired results using the technique. Can you help.

` <div style={{backgroundColor:'#4AA4B8'}}>
<Tabs
tabItemContainerStyle={{backgroundColor:'#4AA4B8',width:'500px'}}
contentContainerStyle={{backgroundColor:'#FFF'}}
value={this.state.value}
onChange={this.handleChange}
>
All the <tab tags

`

tabs-not-working-well
tabs-working-well

Initially it does not work i.e Tab A does not work but Tab B and Tab C works fine.

@pavanmehta91
Copy link

Here's the webpackbin link to it

https://www.webpackbin.com/bins/-KpxVgwKOLPfM8CFcu5-

@oliviertassinari
Copy link
Member

@pavanmehta91 The issue was closed. Move to the v1-beta release if you need the feature.

@john-mbone
Copy link

Use this on Tab element
sx={{alignSelf:'start'}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants