【发布时间】:2021-10-08 13:07:11
【问题描述】:
我想在我现有的 reactjs material ui 项目中添加一个日期范围组件。但问题是它占用了空间,而不是像 Select 组件那样仅仅显示它“在其他组件之上”
这是我想在我的应用程序中添加的示例 sn-p https://codesandbox.io/s/materialui-daterange-picker-2p3f1?file=/src/App.js:274-385
我的实际实现
const Wow = () => (
<DateRangePicker
open={open}
toggle={toggle}
onChange={(range) => setDateRange(range)}
/>
);
const DateRange = () => (
<>
<Grid
container
spacing={1}
>
<Grid
item
lg={10}
md={12}
xl={9}
xs={12}
>
<Button
onClick={() => setOpen(true)}
>
Show
</Button>
<Wow />
</Grid>
<Grid
item
lg={2}
md={12}
xl={9}
xs={12}
>
<Button
variant="contained"
startIcon={<CheckIcon />}
onClick={handleSubmit}
>
Go
</Button>
</Grid>
</Grid>
</>
);
return (
<>
<Helmet>
<title>Selectors | Clever Clicks</title>
</Helmet>
<Box
sx={{
backgroundColor: 'background.default',
minHeight: '100%',
py: 3
}}
>
<Container maxWidth={false}>
<Grid
container
spacing={1}
>
<Grid
item
lg={4}
md={12}
xl={9}
xs={12}
>
<TextField
id="standard-select-currency-native"
select
label="Market"
onChange={handleMarket}
SelectProps={{
native: true,
}}
size="small"
fullWidth
helperText="Please select "
>
{marketplaces.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</TextField>
</Grid>
<Grid
item
lg={4}
md={12}
xl={9}
xs={12}
>
<TextField
id="standard-select-currency-native"
select
label="Products"
onChange={handleProduct}
SelectProps={{
native: true
}}
size="small"
fullWidth
helperText="Please select products"
inputProps={{ style: { fontSize: 15, overflow: 'visible' } }}
>
<option value="All"> --All-- </option>
{products.map((option) => (
<option key={option.id} value={`${option.title},${option.seller_sku},${option.id}`}>
{option.title}
</option>
))}
</TextField>
</Grid>
<Grid
item
lg={4}
md={12}
xl={9}
xs={12}
>
<DateRange />
</Grid>
</Grid>
</Container>
</Box>
</>
);
};
如果您注意到,以下组件是“强制”拉伸的。我想要的是使日期范围日历“浮动”。 有什么帮助吗?
【问题讨论】:
标签: reactjs material-ui