Skip to content

Commit

Permalink
[Fix] User dropdown tabbing (#1009)
Browse files Browse the repository at this point in the history
- Tab auto opens username dropdown
- Will now instantly tab to dropdown elements when landing on username button/down arrow.
- Also added comments for the tab index value and code.
  • Loading branch information
SukhsimranpreetSekhon committed Oct 28, 2020
1 parent e6fe674 commit 69f2744
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@ant-design/icons";
import PropTypes from "prop-types";
import { useKeycloak } from "@react-keycloak/web";
import { Layout, Dropdown, Menu, Button, Input, Row, Col } from "antd";
import { Layout, Dropdown, Menu, Button, Input, Row } from "antd";
import { FormattedMessage, injectIntl } from "react-intl";
import { useSelector } from "react-redux";
import { useHistory } from "react-router";
Expand Down Expand Up @@ -46,8 +46,15 @@ const TopNavView = ({ isAdmin, loading, displaySearch, displayLogo, intl }) => {
}, []);

// menu options for profile dropdown
/* eslint-disable react/jsx-no-duplicate-props */
const menu = (isDropdown, optionalStartMenuItems) => (
<Menu className={isDropdown ? "dropDownMenu" : "hamburgerMenu"}>
<Menu
// Ant-design issue: recognizes either depending on machine
// "-1" is used for off-screen content that appears on a specific event
tabIndex={-1}
tabindex="-1"
className={isDropdown ? "dropDownMenu" : "hamburgerMenu"}
>
{optionalStartMenuItems}
<Menu.Item className="dropDownItem">
<Link to={`/profile/${id}`}>
Expand Down Expand Up @@ -93,14 +100,17 @@ const TopNavView = ({ isAdmin, loading, displaySearch, displayLogo, intl }) => {
</Menu.Item>
</Menu>
);
/* eslint-enable react/jsx-no-duplicate-props */

const getAvatarDropdown = (userName) => {
if (userName) {
return (
<Dropdown
overlay={() => menu(true)}
placement="bottomCenter"
trigger="click"
trigger={["click"]}
getPopupContainer={(triggerNode) => triggerNode.parentNode}
showAction={["focus"]}
>
<Button type="link" className="nav-dropDownButton ant-dropdown-link">
<CustomAvatar
Expand Down Expand Up @@ -215,10 +225,10 @@ const TopNavView = ({ isAdmin, loading, displaySearch, displayLogo, intl }) => {

{getSearchInput()}

<Col className="rightMenu">
{getAvatarDropdown(name)}
<Row align="middle">
<div>{getAvatarDropdown(name)}</div>
<ChangeLanguage />
</Col>
</Row>
</Row>
</Header>
);
Expand Down

0 comments on commit 69f2744

Please sign in to comment.