From: Revanshu Paliwal Date: Thu, 30 Mar 2023 09:46:55 +0000 (+0200) Subject: SONAR-18918 Fixing accessibility issues in global search X-Git-Tag: 10.0.0.68432~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2383bd4877bc4c364c7e0a2912330fd6197978b3;p=sonarqube.git SONAR-18918 Fixing accessibility issues in global search --- diff --git a/server/sonar-web/src/main/js/app/components/global-search/GlobalSearch.tsx b/server/sonar-web/src/main/js/app/components/global-search/GlobalSearch.tsx index 605b251614f..131c63ce23c 100644 --- a/server/sonar-web/src/main/js/app/components/global-search/GlobalSearch.tsx +++ b/server/sonar-web/src/main/js/app/components/global-search/GlobalSearch.tsx @@ -31,6 +31,7 @@ import { import { debounce, uniqBy } from 'lodash'; import * as React from 'react'; import { getSuggestions } from '../../../api/components'; +import FocusOutHandler from '../../../components/controls/FocusOutHandler'; import OutsideClickHandler from '../../../components/controls/OutsideClickHandler'; import Tooltip from '../../../components/controls/Tooltip'; import { Router, withRouter } from '../../../components/hoc/withRouter'; @@ -39,6 +40,7 @@ import { isInput, isShortcut } from '../../../helpers/keyboardEventHelpers'; import { KeyboardKeys } from '../../../helpers/keycodes'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getKeyboardShortcutEnabled } from '../../../helpers/preferences'; +import { scrollToElement } from '../../../helpers/scrolling'; import { getComponentOverviewUrl } from '../../../helpers/urls'; import { ComponentQualifier } from '../../../types/component'; import { Dict } from '../../../types/types'; @@ -277,7 +279,12 @@ export class GlobalSearch extends React.PureComponent { const node = this.nodes[this.state.selected]; if (node && this.node) { - node.scrollIntoView(); + // using scrollIntoView here is creating some weird scroll behaviour when scrolling + scrollToElement(node, { + topOffset: 30, + bottomOffset: 30, + parent: this.node, + }); } } }; @@ -357,25 +364,10 @@ export class GlobalSearch extends React.PureComponent { render() { const { open, query, results, more, loadingMore, selected, loading } = this.state; - if (!open && !query) { - return ( - - - - ); - } - const list = this.getPlainComponentsList(results, more); const search = ( -
+
{ maxHeight="38rem" innerRef={(node: HTMLUListElement | null) => (this.node = node)} size="auto" + aria-owns="global-search-input" > { zLevel={PopupZLevel.Global} > {
); - return open ? ( - {search} - ) : ( - search + return ( +
+ {!open && !query ? ( + + + + ) : ( + + + {search} + + + )} +
); } } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/BranchLikeNavigation.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/BranchLikeNavigation.tsx index b8296bd4355..db755f32bd4 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/BranchLikeNavigation.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/BranchLikeNavigation.tsx @@ -20,6 +20,7 @@ import { ButtonSecondary, Popup, PopupPlacement, PopupZLevel } from 'design-system'; import * as React from 'react'; import EscKeydownHandler from '../../../../../components/controls/EscKeydownHandler'; +import FocusOutHandler from '../../../../../components/controls/FocusOutHandler'; import OutsideClickHandler from '../../../../../components/controls/OutsideClickHandler'; import { AlmKeys, ProjectAlmBindingResponse } from '../../../../../types/alm-settings'; import { BranchLike } from '../../../../../types/branch-like'; @@ -63,50 +64,48 @@ export function BranchLikeNavigation(props: BranchLikeNavigationProps) { ); + const handleOutsideClick = () => { + setIsMenuOpen(false); + }; + return (
- { - setIsMenuOpen(false); - }} + + + + { + setIsMenuOpen(false); + }} + /> + + + + ) + } + placement={PopupPlacement.BottomLeft} + zLevel={PopupZLevel.Global} > - { - setIsMenuOpen(false); + { + setIsMenuOpen(!isMenuOpen); }} + disabled={!isMenuEnabled} + aria-expanded={isMenuOpen} + aria-haspopup="menu" > - { - setIsMenuOpen(false); - }} - /> - ) - } - placement={PopupPlacement.BottomLeft} - zLevel={PopupZLevel.Global} - > - { - setIsMenuOpen(!isMenuOpen); - }} - disabled={!isMenuEnabled} - aria-expanded={isMenuOpen} - aria-haspopup="menu" - > - {currentBranchLikeElement} - - - - + {currentBranchLikeElement} + +