【发布时间】:2019-06-05 11:19:28
【问题描述】:
我正在尝试制作一个下拉菜单,其中包含从谷歌地图返回的城市名称,以便它使用 z-Index 显示在其下方分区的顶部。这是最小的代码。
class PlacesAutocomplete1 extends React.Component {
....
render() {
const open = Boolean(anchorEl);
const { anchorEl } = this.state;
const searchOptions = {
types: ['(cities)'],
componentRestrictions: { country: 'in' }
}
return (
<div>
<PlacesAutocomplete
value={this.state.address}
onChange={this.handleChange}
onSelect={this.handleSelect}
searchOptions={searchOptions}
shouldFetchSuggestions={this.state.address.length > 3}
>
{({ getInputProps, suggestions, getSuggestionItemProps, loading }) => (
<div style={{ position: 'relative', zIndex: 2 }}>
<TextField
id="outlined-search"
type="search"
label="city"
margin="dense"
onClick={this.handleClick}
variant="outlined"
{...getInputProps()}
/>
<div>
{loading && <div>Loading...</div>}
{suggestions.map(suggestion => {
const className = suggestion.active
? 'suggestion-item--active'
: 'suggestion-item';
// inline style for demonstration purpose
const style = suggestion.active
? { backgroundColor: '#fafafa', cursor: 'pointer', position: 'relative', zIndex: 2 }
: { backgroundColor: '#ffffff', cursor: 'pointer', position: 'relative', zIndex: 2 };
return (
<Paper {...getSuggestionItemProps(suggestion, {
className,
style
})} elevation={1}>
<span>{suggestion.description}</span>
</Paper>
);
})}
</div>
</div>
)}
</PlacesAutocomplete>
<div style={{ position: 'relative', zIndex: 1 }}>
<h2>Suggestions Should be on the top of Me</h2>
</div>
</div>
);
}
}
谁能帮助指导我做错了什么?这里是代码沙盒演示
【问题讨论】:
标签: css reactjs styles z-index