Material UI Tabpanel not using columns - reactjs

const useStyles = makeStyles((theme) => ({
root: {
flexGrow: 1,
width: "100%",
backgroundColor: theme.palette.background.paper,
},
title: {
[theme.breakpoints.up("sm")]: {
display: "block",
maxHeight: 125,
},
},
Alert: {
margin: theme.spacing(2),
},
Logo: {
width: 50,
height: 50,
marginRight: theme.spacing(3),
[theme.breakpoints.up("sm")]: {
width: 80,
height: 80,
},
},
}));
export default function ScrollableTabsButtonForce() {
const classes = useStyles();
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<div className={classes.root}>
<AppBar position="static" color="default">
<Tabs
className={classes.title}
value={value}
onChange={handleChange}
variant="scrollable"
scrollButtons="on"
indicatorColor="primary"
textColor="primary"
aria-label="scrollable force tabs example"
>
<Tab
label="Elite Knight"
icon={<img className={classes.Logo} src={Knight} alt="Logo" />}
{...a11yProps(0)}
/>
<Tab
label="Royal Paladin"
icon={<img className={classes.Logo} src={Paladin} alt="Logo" />}
{...a11yProps(1)}
/>
<Tab
label="Master Sorcerer"
icon={<img className={classes.Logo} src={Sorcerer} alt="Logo" />}
{...a11yProps(2)}
/>
<Tab
label="Elder Druid"
icon={<img className={classes.Logo} src={Druid} alt="Logo" />}
{...a11yProps(3)}
/>
</Tabs>
</AppBar>
<Grid container justify="center" alignItems="center">
<Alert className={classes.Alert} severity="info">
For more information on how to make a purchase please click on the
desired script!
</Alert>
</Grid>
<TabPanel value={value} index={0}>
<Cards voc={0} />
</TabPanel>
<TabPanel value={value} index={1}>
<Cards voc={1} />
</TabPanel>
<TabPanel value={value} index={2}>
<Cards voc={2} />
</TabPanel>
<TabPanel value={value} index={3}>
<Cards voc={3} />
</TabPanel>
</div>
);
}
here is the cards component it loops on a table and generate cards for the other component i already declared how many columns for each screen.
no matter what i tried it keeps each card on a row, i tried display: "Flex" still same issue.
tried declaring the columns on seprate divs aswell still same issue.

Related

Search Input with side button on Tailwind CSS

So i try to display and search bar with button on the right side of it but i keep geeting this view even though i have display it as flex and justify center, and even when i change it into row it still show up as image below
here is my code:
return (
<div className="p-2">
<div className="text-left pl-4 pb-4 font-bold text-3xl">
<h2>Detail SKU</h2>
</div>
<div className="p-2 justify-center mt-4 flex">
<form
onSubmit={(e) => {
e.preventDefault();
}}
>
<Autocomplete
style={{ width: "100%" }}
id="grouped-demo"
options={options.sort(
(a, b, index) => -b.firstLetter.localeCompare(a.firstLetter)
)}
groupBy={(option) => option.firstLetter}
getOptionLabel={(option) => option.title}
sx={{ width: 300 }}
renderInput={(params) => {
params.inputProps.onKeyDown = handleKeyDown;
return <TextField {...params} label="Search SKU" />;
}}
renderGroup={(params) => (
<li key={params.key}>
<GroupHeader>{params.group}</GroupHeader>
<GroupItems>{params.children}</GroupItems>
</li>
)}
/>
<Button variant="contained">Search</Button>
</form>
</div>
<Box sx={{ width: "100%", typography: "body1" }}>
<TabContext value={value} index={0} classes={{ root: useStyles.tab }}>
<Box sx={{ borderColor: "divider", p: 0 }}>
<TabList
index={0}
classes={{ root: useStyles.tab }}
onChange={handleChange}
variant="scrollable"
scrollButtons="auto"
aria-label="scrollable auto tabs example"
>
<Tab label="BOM" value="1" />
<Tab label="Routing" value="2" />
<Tab label="Depre" value="3" />
<Tab label="OMC" value="4" />
</TabList>
</Box>
<TabPanel style={{ padding: 10 }} value="1">
<div className="m-0 p-0" style={{ height: 400, width: "100%" }}>
<DataGrid {...data} components={{ Toolbar: GridToolbar }} />
</div>
</TabPanel>
<TabPanel value="2">Routing</TabPanel>
<TabPanel value="3">Depre</TabPanel>
<TabPanel value="4">OMC</TabPanel>
</TabContext>
</Box>
</div>
);
};
any help on it??, i've been figure it out but it seems dont help at all or where did do wrong here actually??
try removing display classname flex
<div className="p-2 justify-center mt-4">

How to make MUI Tab to have multiple routes

I'm trying to make a simple navigation component with Material UI, React Router v6 and TypeScript. I have AppBar component with Tabs inside, it looks like this:
NavBar screenshot
The layout component renders the <Navigation /> component that contains what I mentioned above and the <Outlet /> to render the component according to the current path.
The problem is that I have two components for user: one to view users (its like a table that lists the users) and the second is a screen to create users (routes are "/secure/users" and the other is "/secure/userCreate"). When I click on the "Users" tab, the userView component gets rendered, because as u can see in the code below, I have the tab
<Tab label="Users" value={routes[6]} to="/secure/users" component={Link} />
to match the user view route ("/secure/users"), but that component has a button to create a new user, it redirects you to "/secure/userCreate" , but that way MUI tab gives me an error because there is no Tab that matches that route.
So my question is, how can I make the Users tab stay selected when I'm in the userView component and then also be selected on user creation? Because I think that would need the tab to match both routes at the same time, "/secure/users" and "/secure/userCreate", and I dont know how to do that or if its possible
Here's my code so far:
navigation.component.tsx
const routes = ["/secure/books", "/secure/offers", "/secure/products", "/secure/vacation", "/secure/others", "/secure/reports", "/secure/users"];
function useRouteMatch(patterns: readonly string[]) {
const { pathname } = useLocation();
for (let i = 0; i < patterns.length; i += 1) {
const pattern = patterns[i];
const possibleMatch = matchPath(pattern, pathname);
if (possibleMatch !== null) {
return possibleMatch;
}
}
return null;
}
export const Navigation = (): ReactElement => {
const permission = getPermission();
const routeMatch = useRouteMatch(routes)
const currentTab = routeMatch?.pattern?.path;
return (
<Container style={{ marginTop: 34}}>
<AppBar
position="static"
style= {{ background: '#FFFFFF'}}
elevation={0}
>
<Container maxWidth="xl">
<Tabs
value={currentTab}
aria-label="nav tabs example"
variant="scrollable"
scrollButtons="auto"
sx={{
'& .MuiTab-root': {
fontSize: 18,
fontWeight: 600,
lineHeight: '175%',
letterSpacing: '0.15px',
padding: '5px 0px 5px 0px',
color: 'rgba(0, 54, 101, 0.6)',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'flex-start',
marginRight: 6.25,
minWidth: 0,
},
'& .MuiTabs-indicator': {
backgroundColor: "#01A3FE",
},
'& .Mui-selected': {
color: "#01A3FE !important",
}
}}
>
<Tab label="Books" value={routes[0]} to="/secure/books" component={Link} />
<Tab label="Offers" value={routes[1]} to="/secure/offers" component={Link} />
<Tab label="Products" value={routes[2]} to="/secure/products" component={Link} />
<Tab label="Vacation" value={routes[3]} to="/secure/vacation" component={Link} />
<Tab label="Others" value={routes[4]} to="/secure/others" component={Link} />
<Tab label="Reports" value={routes[5]} to="/secure/reports" component={Link} />
{permission.isAdmin &&
<Tab label="Users" value={routes[6]} to="/secure/users" component={Link} />}
<span className="MuiTabs-indicator css-1aquho2-MuiTabs-indicator" style={{ left: 0, backgroundColor: '#EEEEEE'}}></span>
</Tabs>
</Container>
</AppBar>
</Container>
);
}
layout.component.tsx
export const Layout = (): ReactElement => {
return (
<div>
<Navigation />
<Outlet />
</div>
);
}
Edit: Maybe to clarify a bit, I need the Users Tab to stay selected when I'm in both routes ("/secure/users" and "/secure/userCreate").
You could simply check if the current pathname value is the "/secure/userCreate" path and set the currentTab value to equal that of the "Users" tab's URL path.
Example:
const Navigation = (): ReactElement => {
const { pathname } = useLocation();
const permission = getPermission();
let currentTab = pathname;
if (pathname === "/secure/userCreate") {
currentTab = "/secure/users";
}
return (
<Container style={{ marginTop: 34 }}>
<AppBar position="static" style={{ background: "#FFFFFF" }} elevation={0}>
<Container maxWidth="xl">
<Tabs
value={currentTab}
aria-label="nav tabs example"
variant="scrollable"
scrollButtons="auto"
sx={{ .... }}
>
<Tab
label="Books"
value={routes[0]}
to="/secure/books"
component={Link}
/>
<Tab
label="Offers"
value={routes[1]}
to="/secure/offers"
component={Link}
/>
<Tab
label="Products"
value={routes[2]}
to="/secure/products"
component={Link}
/>
<Tab
label="Vacation"
value={routes[3]}
to="/secure/vacation"
component={Link}
/>
<Tab
label="Others"
value={routes[4]}
to="/secure/others"
component={Link}
/>
<Tab
label="Reports"
value={routes[5]}
to="/secure/reports"
component={Link}
/>
{permission.isAdmin && (
<Tab
label="Users"
value={routes[6]}
to="/secure/users"
component={Link}
/>
)}
<span
className="MuiTabs-indicator css-1aquho2-MuiTabs-indicator"
style={{ left: 0, backgroundColor: "#EEEEEE" }}
></span>
</Tabs>
</Container>
</AppBar>
</Container>
);
};
If you don't want to explicitly check the paths then create an object that maps a pathname value to a tab "key" value, use the tab "key" value in each tab.

Add dynamic value beside label in Material UI React Tabs Component

I am creating tabs using material ui and i want to add value beside label (ex: 05 written beside Recommendation label) which will be dynamic in the tabs component just like shown in below image:
Here is my code snippet of Tabs component:
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<Tabs value={value} onChange={handleChange} aria-label="basic tabs example">
<Tab label="Recommendation" />
<Tab label="Ongoing" />
<Tab label="Completed" />
</Tabs>
</Box>
One option is to create your own component, pass that in as a the Tab label, and then style it as needed. For example:
const TabWithCount = ({ children, count }) => {
return (
<Box sx={{ display: "inline-flex", alignItems: "center" }}>
<Typography component="div">{children}</Typography>
{count ? (
<Typography
component="div"
variant="body2"
sx={{ marginLeft: "0.5rem" }}
>
{count}
</Typography>
) : null}
</Box>
);
};
...
<Tab
label={<TabWithCount count="05">Recommendation</TabWithCount>}
/>
I've created a quick (unstyled) example to illustrate the solution: https://codesandbox.io/s/basictabs-material-demo-forked-i9543?file=/demo.js

vertical divider not working in material ui

I have this component that contains a card and inside this card there are elements and I want to separate them through a vertical line and the problem is that the vertical line does not work.
const useStyles = makeStyles((theme: Theme) =>
createStyles({
orange: {
color: theme.palette.getContrastText(deepOrange[500]),
backgroundColor: deepOrange[500],
}
}),
);
const SpaceForm: FC = (props) => {
const classes = useStyles()
const workspaceData = useWorkspaceModule((state) => state.workspace)
console.log("inside component 1: ", workspaceData);
return (
<>
<Grid
container
spacing={3}
>
<Grid
item
lg={8}
md={6}
xs={12}
>
<Card>
<CardHeader title="Name your Workspace:"/>
<CardContent>
<Avatar style={{width: '3.4rem', height: '3.4rem'}} className={classes.orange}>N</Avatar>
{/*llll*/}
<Divider style={{ backgroundColor:'red'}} orientation="vertical" flexItem />
</CardContent>
</Card>
</Grid>
</Grid>
</>
);
};
export default SpaceForm;
You just wrap Avatar inside a flex Box and it will show Divider after Avatar:
<Box display="flex">
<Avatar
style={{ width: "3.4rem", height: "3.4rem" }}
className={classes.orange}
>
N
</Avatar>
{/*llll*/}
<Divider
style={{ backgroundColor: "red" }}
orientation="vertical"
flexItem
/>
</Box>

How can I solve this vertical tab problem in material UI using react.js?

I am trying to implement a vertical tab using material UI in react.js. For some reason the tabs not appearing. Here is the code :
Javascript:
const [value, setValue] = useState(0);
const handleChange1 = (event, newValue) => {
setValue(newValue);
};
UI:
<div className={classes.root}>
<Tabs
orientation="vertical"
value={value}
onChange={handleChange}
aria-label="Vertical tabs example"
>
<Tab label="Item One" {...a11yProps(0)} />
<Tab label="Item Two" {...a11yProps(1)} />
<Tab label="Item Three" {...a11yProps(2)} />
</Tabs>
<TabPanel value={value} index={0}>
Item One
</TabPanel>
<TabPanel value={value} index={1}>
Item Two
</TabPanel>
<TabPanel value={value} index={2}>
Item Three
</TabPanel>
</div>
CSS:
root: {
flexGrow: 1,
backgroundColor: theme.palette.background.paper,
display: 'flex',
height: 400,
},
tabs: {
borderRight: `1px solid ${theme.palette.divider}`,
width:100
},
The final result:
https://i.stack.imgur.com/mUT7L.png
Firstly delete enter code here part, secondly css display might cause the problem. Try to change display as "block"
here's demo link: https://codesandbox.io/s/material-demo-lj0bu?file=/demo.js

Resources