question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot override fonts with classeNames for Tabs component

See original GitHub issue

Hello,

We cannot find a way to override fonts easily in the Tabs component (or any component actually)… We are using the styled-system package together with styled-components to setup our scales and responsive behavior and everything we implement using material-ui has font sizes 2 times lower than expected. For the tabs component, I found this css:

screen shot 2018-08-23 at 4 52 13 pm

which I have no idea on how to access it.

Code snippet of our tabs implementation (edited version of https://github.com/mui-org/material-ui/blob/master/docs/src/pages/demos/tabs/CustomizedTabs.js ):

import * as React from 'react';
import { withStyles } from '@material-ui/core/styles';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import { Grid } from "../ui-grid/ui-grid.component"
import styled from "styled-components"

const Wrapper = styled(Grid)`
  border: 1px solid ${(props) => props.theme.colors.border};
  grid-auto-flow: row;
  min-width: 0px;
`

interface UiTextEventTarget extends EventTarget {
  index?: number
}

interface UiMouseEvent extends React.MouseEvent<HTMLElement> {
  target: UiTextEventTarget
}

const styles: any = () => ({
  root: {
    border: "1px solid #eee",
    backgroundColor: "white",
    fontSize: "16px"
  },
  tabsRoot: {
    backgroundColor: "#eee"
  },
  tabsIndicator: {
    display: "none"
  },
  tabRoot: {
    fontSize: "16px !important",
    textTransform: 'initial',
    minWidth: 72,
    fontWeight: "normal",
    fontFamily: [
      'Roboto',
    ].join(','),
    '&:hover': {
      color: '#40a9ff',
      opacity: 1,
    },
    '&$tabSelected': {
      color: '#1890ff',
      fontWeight: "500",
      borderBottom: "none !important"
    },
    '&:focus': {
      color: '#40a9ff',
    },
  },
  selected: {
    borderBottom: "none !important",
  },
  tabSelected: {
    backgroundColor: "white",
    borderTop: "1px solid #eee",
  }
});

class CustomizedTabs extends React.Component<any> {
  state = {
    value: 0,
  };

  handleChange = (event: UiMouseEvent, value: number) => {
    this.setState({ value });
  };

  render() {
    const { classes } = this.props;
    const { value } = this.state;

    return (
      <Wrapper className={classes.root}>
        <Tabs
          value={value}
          onChange={this.handleChange}
          fullWidth={true}
          classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }}
        >
          <Tab
            disableRipple={true}
            classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
            label="Tab 1"
          />
          <Tab
            disableRipple={true}
            classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
            label="Tab 2"
          />
          <Tab
            disableRipple={true}
            classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
            label="Tab 3"
          />
        </Tabs>
        {this.props.children}
      </Wrapper>
    );
  }
}


export const TabbedPanel = withStyles(styles)(CustomizedTabs);

and a screenshot of the result by just calling that component:

screen shot 2018-08-23 at 4 57 44 pm

Ideally, I wanna be able to call the component in the following way:

<TabbedPanel fontSize={[3, 2, 2]}> ... </TabbedPanel>

With fontSize a styled-system parameter that takes care of various screen sizes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adeelibrcommented, Aug 25, 2018

If no one is working on this issue, can I work on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot override fonts with classeNames for Tabs component
Hello, We cannot find a way to override fonts easily in the Tabs component (or any component actually)... We are using the styled-system ......
Read more >
Material UI Tab label font-size is really small - Stack Overflow
Material-ui Tab component label prop type is node. So if you want to add styles you need to put plain text inside div...
Read more >
Styles API | Mantine
With Styles API you can overwrite styles of inner elements in Mantine components with classNames or styles props. Styling with classNames. Let's say...
Read more >
How do I change the fonts on just one open tab?
Two days ago, one of my tabs changed fonts inexplicably and I cannot change it back. What settings could have been changed?
Read more >
font-size-adjust - CSS: Cascading Style Sheets | MDN
The font-size-adjust CSS property sets the size of lower-case letters relative to the current font size (which defines the size of upper-case ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found