Search Input with side button on Tailwind CSS - reactjs

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">

Related

How to swap MUI icon on IconButton when hovering

I have these tabs that have a close button on them, if the content in them has edits then the close icon turns to a circle, similar to visual code.
{tabs.map((tab, index) => {
const child = (
<StyledTab
label={
<span>
{tab.label + ':' + tab.hasEdit}
<IconButton size="small" component="span" onClick={() => closeClickHandler(tab.value)}>
{tab.hasEdit ? (
<CircleIcon style={{ fontSize: "12px" }} />
) : (
<CloseIcon style={{ fontSize: "18px" }} />
)}
</IconButton>
</span>
}
value={tab.value}
key={index}
/>
);
return (
<DraggableTab
label={
<span>
{tab.label}
<IconButton size="small" component="span" onClick={() => {
closeClickHandler(tab.value);
}}>
{tab.hasEdit ? (
<CircleIcon style={{ fontSize: "12px" }} />
) : (
<CloseIcon style={{ fontSize: "18px" }} />
)}
</IconButton>
</span>
}
value={tab.value}
index={index}
key={index}
child={child}
/>
);
})}
What I'm having trouble with is getting the icon to change from a circle to a close icon while hovering over the button.
Could someone give me a hand on a good way to implement this please?!
You could do this by adding a state for the items. Then add a onMouseEnter and onMouseLeave events on the IconButton. When hovering we can add the index to the array and finally remove when we're leaving. To determine if a icon needs to change we can check if the index in in the hoveringItems.
const [hoveringItems, setHoveringItems] = useState([]);
function handleHover(index, isLeaving) {
setHoveringItems((prevItems) => {
if (isLeaving) return prevItems.filter((item) => item !== index);
return [...prevItems, index];
});
}
return (
<IconButton
size="small"
component="span"
onClick={() => {
closeClickHandler(tab.value);
}}
onMouseEnter={() => handleHover(index, false)}
onMouseLeave={() => handleHover(index, true)}
>
{tab.hasEdit || hoveringItems.includes(index) ? (
<CircleIcon style={{ fontSize: "12px" }} />
) : (
<CloseIcon style={{ fontSize: "18px" }} />
)}
</IconButton>
);

How to solve problem with 2items with the same key?

I usually using uuid from react-uuid but this time I get all time an error even I try to combine it with unique item.id..
<Swiper
{...params}
>
{listMovie?.map((item, index) =>{
const time = new Date(item.release_date)
return(
<React.Fragment key={`${item.id + uuid()}`}>
<SwiperSlide >
<Grid item className="items">
<Card sx={{ maxWidth: "350" }}>
<div className="favorite">
<IconContext.Provider
value={{ color: 'red', size: '30px' }}
>
<div className="fav" onClick={() => FavHanlder(item, index)}>
{likes.includes(item.id) ? <MdFavorite/> : <MdFavoriteBorder/>}
</div>
</IconContext.Provider> </div>
<Link to={`/movie/${item.id}`}>
<CardMedia
component="img"
height="350"
image={`${apiConfig.w500Image(item.poster_path)}`}
// alt={item.Title}
/>
<CardContent>
</CardContent>
</Link>
</Card>
<div className="title">
<Typography variant="body2" color="white" >
{item.original_title}
</Typography>
<Typography variant="body2" color="white" >
({time?.getFullYear()})
</Typography>
<div style={{display: "flex", float: "left", paddingLeft: "10px", paddingRight: "10px"}}>
<ReactStars
count={10}
value={item.vote_average}
size={10}
isHalf={true}
emptyIcon={<i className="far fa-star"></i>}
halfIcon={<i className="fa fa-star-half-alt"></i>}
fullIcon={<i className="fa fa-star"></i>}
activeColor="#ffd700"
/><p style={{fontSize: "5px"}}>/{item.vote_count}votes</p></div>
</div>
</Grid>
</SwiperSlide>
</React.Fragment>
)})}
</Swiper>
I am a little bit confused, because this is an error of beginners.
full msg:
Warning: Encountered two children with the same key, .0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

Avatar not wooking when i use with Mui selectTag

I use avatar in MUI to display images in tagSelect, but it isn't working.
<FormControl sx={{ width: "27.5rem" }}>
<InputLabel id="demo-multiple-checkbox-label">Tag</InputLabel>
<Select
labelId="demo-multiple-checkbox-label"
id="demo-multiple-checkbox"
multiple={true}
value={valueTag}
onChange={(e) => handleChange(e)}
input={<OutlinedInput label="Tag" />}
renderValue={(selected) => selected.join(", ")}
MenuProps={MenuProps}
>
{listFoodSelectbox.map((item) => (
<MenuItem key={item.id} value={item.name}>
<Stack direction="row" spacing={2}>
{/* <Avatar url="/static/logo7.png" alt="food" /> */}
<Avatar url={item.image} alt="food" />
</Stack>
<Checkbox checked={valueTag.indexOf(item.name) > -1} />
<ListItemText primary={item.name} />
</MenuItem>
))}
</Select>
</FormControl>
<Avatar url={item.image} alt="food" />
to <Avatar src={item.image} alt="food" />
tôi đã nhầm lẫn src thành url
sorry for my stupid

How can I transform this DataPicker into DataRangePicker of Material UI?

I've tried some imports but doesn't have much idea how to implement
<form className={classes.formContainer} noValidate autoComplete="off">
<div className={classes.formContent}>
<div className={classes.fieldsContent}>
<TextField
id="search-name-enrollment"
placeholder="Buscar por nome ou número de matrícula"
className={clsx(classes.field, classes.fieldNameEnroll)}
value={nameEnrollment}
onChange={(event) => handleNameEnrollmentChange(event.target.value)}
InputProps={{
disableUnderline: true,
classes: { input: classes.placeholder },
startAdornment: (
<InputAdornment position="start">
<SearchIcon color="primary" />
</InputAdornment>
)
}}
/>
</div>
<Link
component="button"
type="button"
variant="body2"
color="primary"
underline="none"
className={classes.linkFiltros}
onClick={() => {
setOpenFilters(!openFilters)
}}
>
Mais filtros
{openFilters ? (
<KeyboardArrowUpIcon fontSize="small" />
) : (
<KeyboardArrowDownIcon fontSize="small" />
)}
</Link>
<Collapse
in={openFilters}
classes={{
wrapper: classes.wrapper
}}
className={classes.fieldsContent}
timeout="auto"
unmountOnExit
>
<div className={classes.secundaryFieldContent}>
<div className={classes.secundaryField}>
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<KeyboardDatePicker
disableToolbar
variant="inline"
format="dd/MM/yyyy"
margin="normal"
id="date-picker-inline"
placeholder="Data de matrícula"
value={dateEnrollment}
onChange={handleDateEnrollmentChange}
className={clsx(classes.field, classes.dates)}
invalidDateMessage=""
InputProps={{
disableUnderline: true,
classes: { input: classes.placeholder }
}}
KeyboardButtonProps={{
'aria-label': 'change date'
}}
/>
</MuiPickersUtilsProvider>
</div>
<div
className={clsx(
classes.secundaryField,
classes.secundaryFieldMarginL
)}
>
<Autocomplete
multiple
limitTags={1}
id="checkboxes-tags-demo"
options={options}
disableCloseOnSelect
value={status}
onChange={handleStatusChange}
getOptionLabel={(option) => option.label}
renderOption={(option, { selected }) => (
<React.Fragment>
<Checkbox
icon={icon}
checkedIcon={checkedIcon}
style={{ marginRight: 8 }}
checked={selected}
/>
{option.label}
</React.Fragment>
)}
renderInput={(params) => (
<TextField
{...params}
className={clsx(classes.field, classes.status)}
placeholder="Status de matrícula"
classes={{ root: classes.underline }}
/>
)}
/>
</div>
</div>
</Collapse>
</div>
</form>
I would like to know how to transform into to DataRangePicker, you guys can help me?
I've tried already some imports and similiar ones, but at all not having a full idea how to implement it. This model that I have already developed just is one date, I would like to have a calendar that I can choose a range as well.

Material UI Tabpanel not using columns

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.

Resources