Tips for resizing tab components in Materials-UI

I am currently developing a basic app that showcases heart rate, blood glucose levels, and other measurements. I am utilizing React and Redux for the development process and incorporating Materials-UI for the user interface.

For displaying these metrics, I am designing a component that will be present on each side of the screen. Underneath each metric, there will be a set of tabs allowing users to switch between different views within the component.

I am looking to adjust the size of the tabs to make them smaller as they are currently too large and occupying too much space. I have reviewed resources like this and this, but I am uncertain how to achieve this resizing.

I attempted using withStyles(styles) as demonstrated below, but encountered issues with its functionality:

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import { withStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';


const BottomTab = ({}) => (
  <Grid item direction="column" alignItems="center" justify="center">
      <Tabs
        value={0}
        indicatorColor="primary"
        textColor="primary"
        variant="fullWidth"
      >
        <Tab label="Current" />
        <Tab label="Set New" />
        <Tab label="Alarm" />
      </Tabs>
  </Grid>
);
const styles = {
  tab: {
      width: '10', // specific number
  }
};

export default withStyles(styles)(BottomTab);

The following code snippet illustrates where I incorporate the BottomTab:

interface Props {
  labelId: string,
  value: number
}

const Knob = ({labelId, value}: Props) => (
  <Grid item container direction="row" alignItems="center" justify="center">
    <Grid item xs>
      <ValueDisplay labelId={labelId} value={value} />
    </Grid>
    <Grid item container direction="column" alignItems="center" justify="space-evenly">
      <BottomTab />
    </Grid>
  </Grid>
)

export default Knob

Answer №1

When working with the BottomTab, it's important to create a specific class that includes a property called minWidth: <your tab size>. This class should then be used to style the Tab component as shown below:

const useStyles = makeStyles((theme) => ({
  ...
  tabs: {
    '& button': {
      minWidth: 50
    }
  }
}));

const BottomTab = ({}) => {
  const classes = useStyles()
  return (
  <Grid item direction="column" alignItems="center" justify="center">
      <Tabs
        value={0}
        indicatorColor="primary"
        textColor="primary"
        variant="fullWidth"
        className={classes.tabs}
      >
        <Tab label="Current" />
        <Tab label="Set New" />
        <Tab label="Alarm" />
      </Tabs>
  </Grid>
)
};

Answer №2

One potential solution could be to place the component in its own grid and adjust the size accordingly. It may not be a guaranteed fix, but it's worth experimenting with. Please note that I'm providing this response instead of a comment due to limitations on my reputation level.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to Extract the key value from the parseJson() function

Could someone assist me in retrieving the value of the "id_user" key from the script provided below? JSON.parse({ "data": [ { "id_user": "351023", "name": "", "age": "29", "link": "http://domain. ...

The error message is stating that there is a TypeError because it cannot read the property "bind" of an undefined value when using the ng

When trying to implement the ng-cropper directive, an angular binding for the cropper javascript image cropping library, I'm encountering the error message TypeError: Cannot read property 'bind' of undefined. It seems to be related to the fo ...

Tips for incorporating inline styling into the body element

Can someone help me with adding inline style to the body element using jQuery? I want to set the background color to white (#FFFFFF). Your assistance would be highly appreciated. Thank you! ...

Images cannot be shown until they have been uploaded

My issue involves a menu that loads an external file (form) on the same page, and for the menu, I am utilizing a specific function for menu styling. Custom Menu Function function getXmlHttp() { try { return new ActiveX ...

Having troubles with delayed state changes due to setState being used within useEffect

I have been working on a slider effect using React Hooks and Redux, and here is the code I am using: const Barchart = ({chartData}) => { let newArray = [] let len = chartData.length const [XArray,setXArray]=useState([chartData]) const [ ...

What could be causing my canvas to not display my sprite?

Currently, I am in the process of learning JavaScript and experimenting with creating games to make the learning experience more enjoyable. However, I am facing an issue while using EaselJS and CreateJS to develop these games as a beginner. I need some as ...

Is it possible to utilize the "let" keyword in JavaScript as a way to prevent global-scope variables?

While working on a JavaScript test, I came across an interesting observation related to the let keyword. Take a look at this code snippet: let variable = "I am a variable"; console.log(window.variable); Surprisingly, when I tried to access the variable p ...

Background: Cover causing image to be cut off

I'm having trouble trying to display the top part of a background image under my current navigation bar. I've been unable to identify what mistake I may be making here. Here is my HTML code: <section class="jumbotron"> <div class=" ...

Exploring Angular 9: Harnessing the Power of Fork Join with an Array of

I have a challenge where I need to send multiple API requests to an endpoint by iterating over an array of values To handle this, I decided to use rxjs library and specifically the forkJoin method //array to keep observables propOb: Observable<any>[ ...

Create an array of objects in JavaScript using JSON data

I have fetched a collection of dictionaries from my API: The data can be retrieved in JSON format like this: [{"2020-03-11 14:00:00":10.765736766809729} ,{"2020-03-11 15:00:00":10.788090128755387}, {"2020-03-11 16:00:00":10.70594897472582}, {"2020-03-11 1 ...

The Mui datepicker displays the day and month in reverse order

Do you have trouble with date search filter using the mui datepicker component? It seems that when entering a date in the input and clicking on search, the day gets swapped with the month. For instance, if you input 03/05/2022, it returns Sat Mar 05 2022 ...

Is there a way to access just the concealed text within an element?

Is there a way to create a JavaScript function that can specifically extract hidden text from an element? Are there any existing libraries with this capability, and if so, how efficient are they? In order for an element to be considered visible ac ...

Vue Checkboxes - Maintain selection unless a different checkbox is selected

I have implemented a checkbox system with radio button behavior, but I am facing an issue where I want to keep the checkbox checked until another checkbox is selected (which will then uncheck the first one). I do not want the ability to deselect the checkb ...

React components with Material-UI integration are inquiring about specific keys for the Autocomplete functionality

Issue with React Native: Receiving a warning for encountering children with the same key Any suggestions on how to resolve this by adding unique keys? Here's what I've attempted so far: <Stack spacing={2} sx={{ width: 300 }}> < ...

Establish the editor's starting state

Currently, I am utilizing lexical and aiming to establish initial text for the editor. At the moment, my approach involves hardcoding the initial text, but it seems I cannot simply pass a String as anticipated. Instead, the format required is JSON. Hence ...

The only functional button in the table is the one located on the top row

My MVC Application is encountering an issue with only the first item in the table working perfectly, while the rest are not calling the method. Despite my extensive research, I have been unable to resolve this issue. Below is the code on my view. Can someo ...

The login function in Nativescript Vue successfully returns a true value

Hello, I am currently using a function that is quite similar to this one with some minor tweaks here. However, I have encountered an issue when trying to log in to my REST API. Even if I input the incorrect username or password, it still authenticates me ...

Using AngularJS translation capabilities with UI Router

I am working on an AngularJS application that utilizes the AngularJS Translate library from . The setup includes UI router to maintain the existing URL structure of the website, which has been indexed by Google with various language versions such as www.do ...

Can you explain the functioning of knockout container less syntax? (does it have any drawbacks?)

There are numerous instances and examples of using knockout ContainerLess syntax, although I find it challenging to locate proper documentation from their site. Initially, my question was "is it evil?" but upon realizing my lack of understanding on how it ...

Keeping an eye on the location and retrieving articles once more - Vuejs

ClassController <?php namespace App\Http\Controllers\Classes; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\ClassCategory; use App\Models\Article; use App& ...