我的下拉菜单按钮在鼠标悬停时打开(CSS),但是无法通过“tab”访问其内容。
在按钮-标签上,下拉菜单在下一个“tab”按下时打开,跳过菜单的所有内容,关闭它并继续到页面上的下一个焦点元素。
我需要能够通过“tab”键遍历菜单。这是我的React组件:
<div className="dropdown"
tabIndex="0"
role="navigation">
<button className="dropBtn" tabIndex="0" role="menu" type="button" aria-expanded="false" aria-controls="navbar">
<i className="hover">Places</i>
</button>
<div tabIndex="0" className="dropdown-content">
<div tabIndex='0' className='filter'>
<input
className='input'
tabIndex="0"
type="text"
placeholder="Search your place"
value={this.props.query}
onChange={e => this.props.handleUpdateQuery(e.target.value)}/>
</div>
{/* <div className="search-places-results"> */}
<ul className='listOfPlaces'
role="menubar">
{this.props.filteredPlaces.map((item)=>{
return <li item={item}
tabIndex="0"
role="menuitem"
items={this.props.places}
key={item.id}
onClick={(e)=>{this.props.onItemClick(e, item.id)}}>
{item.name}</li>
})}
</ul>
{/* </div> */}
</div>
</div>
CSS:
.dropdown-content .filter:hover,
.dropdown-content .filter:focus,
.dropdown-content ul li:hover,
.dropdown-content ul li:focus {
background-color: rgb(41, 160, 240);
}
.dropdown:hover .dropdown-content,
.dropdown:focus .dropdown-content {
display: block;
}
(此图为示例,与IT技术无关)